using FluentMigrator;

namespace FastBlog.Core.Db.Migrations;

[Migration(202410222104, "Add sessions")]
public class AddSessions : Migration
{
    public override void Up()
    {
        Create.Table("Users")
            .WithColumn("Id").AsInt32().PrimaryKey().Unique().Identity()
            .WithColumn("Username").AsString().Unique()
            .WithColumn("PasswordHash").AsString()
            .WithColumn("Deleted").AsBoolean().WithDefaultValue(false);

        Create.Table("Sessions")
            .WithColumn("Id").AsInt32().PrimaryKey().Unique().Identity()
            .WithColumn("Token").AsString().Unique()
            .WithColumn("LastUsed").AsDateTime()
            .WithColumn("CreatedAt").AsDateTime()
            .WithColumn("Active").AsBoolean().WithDefaultValue(true).Indexed("IX_Sessions_Active")
            .WithColumn("UserId").AsInt32().ForeignKey("Users", "Id");
    }

    public override void Down()
    {
        Delete.Table("Users");
        Delete.Table("Sessions");
    }
}