update order status
This commit is contained in:
@@ -0,0 +1,81 @@
|
||||
import { Migration } from '@mikro-orm/migrations';
|
||||
|
||||
export class Migration20260714170013_changeOrderStatus extends Migration {
|
||||
|
||||
public async up(): Promise<void> {
|
||||
|
||||
// remove old constraint
|
||||
this.addSql(`
|
||||
ALTER TABLE orders
|
||||
DROP CONSTRAINT IF EXISTS orders_status_check;
|
||||
`);
|
||||
|
||||
// migrate data
|
||||
this.addSql(`
|
||||
UPDATE orders
|
||||
SET status='new'
|
||||
WHERE status='pendingPayment';
|
||||
`);
|
||||
|
||||
this.addSql(`
|
||||
UPDATE orders
|
||||
SET status='completed'
|
||||
WHERE status='paid';
|
||||
`);
|
||||
|
||||
// create new constraint
|
||||
this.addSql(`
|
||||
ALTER TABLE orders
|
||||
ADD CONSTRAINT orders_status_check
|
||||
CHECK (
|
||||
status IN (
|
||||
'new',
|
||||
'preparing',
|
||||
'deliveredToWaiter',
|
||||
'deliveredToReceptionist',
|
||||
'shipped',
|
||||
'canceled',
|
||||
'completed'
|
||||
)
|
||||
);
|
||||
`);
|
||||
}
|
||||
|
||||
public async down(): Promise<void> {
|
||||
|
||||
this.addSql(`
|
||||
ALTER TABLE "orders"
|
||||
DROP CONSTRAINT IF EXISTS "orders_status_check";
|
||||
`);
|
||||
|
||||
this.addSql(`
|
||||
UPDATE "orders"
|
||||
SET "status" = 'pendingPayment'
|
||||
WHERE "status" = 'new';
|
||||
`);
|
||||
|
||||
this.addSql(`
|
||||
UPDATE "orders"
|
||||
SET "status" = 'paid'
|
||||
WHERE "status" = 'completed';
|
||||
`);
|
||||
|
||||
this.addSql(`
|
||||
ALTER TABLE "orders"
|
||||
ADD CONSTRAINT "orders_status_check"
|
||||
CHECK (
|
||||
"status" IN (
|
||||
'pendingPayment',
|
||||
'preparing',
|
||||
'deliveredToWaiter',
|
||||
'deliveredToReceptionist',
|
||||
'shipped',
|
||||
'paid',
|
||||
'canceled',
|
||||
'completed'
|
||||
)
|
||||
);
|
||||
`);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user