diff --git a/src/database/migrations/Migration20251210041847.ts b/src/database/migrations/Migration20251210041847.ts new file mode 100644 index 0000000..a475f1f --- /dev/null +++ b/src/database/migrations/Migration20251210041847.ts @@ -0,0 +1,53 @@ +import { Migration } from "@mikro-orm/migrations"; + +export class Migration20251210041847 extends Migration { + override async up(): Promise { + const knex = this.getKnex(); + + await knex.schema.dropTable("transportation_image"); + + await knex.schema.createTable("transportation_image", (table) => { + // Columns + table.string("id", 30).notNullable(); + table.string("transportation_id", 30).notNullable(); + table.string("src", 100).notNullable(); + table.timestamp("created_at", { useTz: true }).notNullable(); + table.timestamp("updated_at", { useTz: true }).notNullable(); + // Constraints + table.primary(["id"], { constraintName: "transportation_image_pkey" }); + table + .foreign( + "transportation_id", + "transportation_image_transportation_id_foreign", + ) + .references("transportation_class.id") + .onUpdate("NO ACTION") + .onDelete("CASCADE"); + }); + } + + override async down(): Promise { + const knex = this.getKnex(); + + await knex.schema.dropTable("transportation_image"); + + await knex.schema.createTable("transportation_image", (table) => { + // Columns + table.string("id", 30).notNullable(); + table.string("transportation_id", 30).notNullable(); + table.string("src", 100).notNullable(); + table.timestamp("created_at", { useTz: true }).notNullable(); + table.timestamp("updated_at", { useTz: true }).notNullable(); + // Constraints + table.primary(["id"], { constraintName: "transportation_image_pkey" }); + table + .foreign( + "transportation_id", + "transportation_image_transportation_id_foreign", + ) + .references("transportation.id") + .onUpdate("NO ACTION") + .onDelete("CASCADE"); + }); + } +}