import { type Opt, defineEntity, p } from '@mikro-orm/core';

export class PrismaMigrations {
  id!: string;
  checksum!: string;
  finishedAt?: Date;
  migrationName!: string;
  logs?: string;
  rolledBackAt?: Date;
  startedAt!: Date & Opt;
  appliedStepsCount: number & Opt = 0;
}

export const PrismaMigrationsSchema = defineEntity({
  class: PrismaMigrations,
  tableName: '_prisma_migrations',
  properties: {
    id: p.string().primary().length(36),
    checksum: p.string().length(64),
    finishedAt: p.datetime().length(3).nullable(),
    migrationName: p.string(),
    logs: p.text().length(65535).nullable(),
    rolledBackAt: p.datetime().length(3).nullable(),
    startedAt: p.datetime().length(3).defaultRaw(`current_timestamp(3)`),
    appliedStepsCount: p.integer().unsigned(),
  },
});
