import { MigrationInterface, QueryRunner, Table } from "typeorm";

export class CreateAdminUsers1748000000000 implements MigrationInterface {
  name = "CreateAdminUsers1748000000000";

  public async up(queryRunner: QueryRunner): Promise<void> {
    await queryRunner.createTable(
      new Table({
        name: "admin_users",
        columns: [
          { name: "id", type: "varchar", length: "36", isPrimary: true },
          { name: "email", type: "varchar", length: "255", isUnique: true },
          { name: "name", type: "varchar", length: "255" },
          { name: "password_hash", type: "varchar", length: "255" },
          { name: "active", type: "tinyint", width: 1, default: 1 },
          { name: "created_at", type: "timestamp", default: "CURRENT_TIMESTAMP" },
          {
            name: "updated_at",
            type: "timestamp",
            default: "CURRENT_TIMESTAMP",
            onUpdate: "CURRENT_TIMESTAMP",
          },
        ],
      }),
      true,
    );
  }

  public async down(queryRunner: QueryRunner): Promise<void> {
    await queryRunner.dropTable("admin_users");
  }
}
