diff --git a/src/database/migrations/Migration20251203114705.ts b/src/database/migrations/Migration20251203114705.ts index 2862657..ac06162 100644 --- a/src/database/migrations/Migration20251203114705.ts +++ b/src/database/migrations/Migration20251203114705.ts @@ -4,18 +4,18 @@ export class Migration20251203114705 extends Migration { override async up(): Promise { const knex = this.getKnex(); - await knex.schema.alterTable("package", (table) => { + await knex.schema.alterTable("package_detail", (table) => { table.decimal("quad_discount", 10, 2).notNullable().defaultTo(0); table.decimal("triple_discount", 10, 2).notNullable().defaultTo(0); table.decimal("double_discount", 10, 2).notNullable().defaultTo(0); - table.decimal("infant_discount", 10, 2).notNullable().defaultTo(0); + table.decimal("infant_discount", 10, 2).nullable(); }); } override async down(): Promise { const knex = this.getKnex(); - await knex.schema.alterTable("package", (table) => { + await knex.schema.alterTable("package_detail", (table) => { table.dropColumn("quad_discount"); table.dropColumn("triple_discount"); table.dropColumn("double_discount"); diff --git a/src/database/migrations/Migration20251210043520.ts b/src/database/migrations/Migration20251210043520.ts new file mode 100644 index 0000000..4daafe9 --- /dev/null +++ b/src/database/migrations/Migration20251210043520.ts @@ -0,0 +1,47 @@ +import { Migration } from "@mikro-orm/migrations"; + +export class Migration20251210043520 extends Migration { + override async up(): Promise { + const knex = this.getKnex(); + + knex.schema.alterTable("package_detail", (table) => { + table.dropColumn("transportation_id"); + }); + + knex.schema.alterTable("package_detail", (table) => { + // Columns + table.string("transportation_id", 30).notNullable(); + // Constraints + table + .foreign( + "transportation_id", + "package_detail_transportation_id_foreign", + ) + .references("transportation_class.id") + .onUpdate("NO ACTION") + .onDelete("CASCADE"); + }); + } + + override async down(): Promise { + const knex = this.getKnex(); + + knex.schema.alterTable("package_detail", (table) => { + table.dropColumn("transportation_id"); + }); + + knex.schema.alterTable("package_detail", (table) => { + // Columns + table.string("transportation_id", 30).notNullable(); + // Constraints + table + .foreign( + "transportation_id", + "package_detail_transportation_id_foreign", + ) + .references("transportation.id") + .onUpdate("NO ACTION") + .onDelete("CASCADE"); + }); + } +}