From 2198c9ef0433e1834c1f4a92965b214e3bfabc6e Mon Sep 17 00:00:00 2001 From: ItsMalma Date: Wed, 10 Dec 2025 11:20:17 +0700 Subject: [PATCH] fix transportation image --- .../migrations/Migration20251210041847.ts | 53 +++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 src/database/migrations/Migration20251210041847.ts 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"); + }); + } +}