cash shift
This commit is contained in:
@@ -0,0 +1,61 @@
|
||||
import { Migration } from '@mikro-orm/migrations';
|
||||
|
||||
export class Migration20260714120000_addCashShifts extends Migration {
|
||||
|
||||
override async up(): Promise<void> {
|
||||
this.addSql(`
|
||||
create table "cash_shifts" (
|
||||
"id" char(26) not null,
|
||||
"created_at" timestamptz not null default now(),
|
||||
"updated_at" timestamptz not null default now(),
|
||||
"deleted_at" timestamptz null,
|
||||
"admin_id" char(26) not null,
|
||||
"restaurant_id" char(26) not null,
|
||||
"opened_at" timestamptz not null,
|
||||
"closed_at" timestamptz null,
|
||||
"opening_amount" numeric(10,0) not null default 0,
|
||||
"expected_amount" numeric(10,0) null,
|
||||
"counted_amount" numeric(10,0) null,
|
||||
"difference_amount" numeric(10,0) null,
|
||||
"orders" int not null default 0,
|
||||
"status" text check ("status" in ('open', 'closed')) not null default 'open',
|
||||
"notes" text null,
|
||||
constraint "cash_shifts_pkey" primary key ("id")
|
||||
);
|
||||
`);
|
||||
this.addSql(`create index "cash_shifts_created_at_index" on "cash_shifts" ("created_at");`);
|
||||
this.addSql(`create index "cash_shifts_deleted_at_index" on "cash_shifts" ("deleted_at");`);
|
||||
this.addSql(`create index "cash_shifts_admin_id_index" on "cash_shifts" ("admin_id");`);
|
||||
this.addSql(`create index "cash_shifts_restaurant_id_index" on "cash_shifts" ("restaurant_id");`);
|
||||
this.addSql(`create index "cash_shifts_restaurant_id_status_index" on "cash_shifts" ("restaurant_id", "status");`);
|
||||
this.addSql(`
|
||||
alter table "cash_shifts"
|
||||
add constraint "cash_shifts_admin_id_foreign"
|
||||
foreign key ("admin_id") references "admins" ("id") on update cascade;
|
||||
`);
|
||||
this.addSql(`
|
||||
alter table "cash_shifts"
|
||||
add constraint "cash_shifts_restaurant_id_foreign"
|
||||
foreign key ("restaurant_id") references "restaurants" ("id") on update cascade;
|
||||
`);
|
||||
|
||||
this.addSql(`alter table "orders" add column "cash_shift_id" char(26) null;`);
|
||||
this.addSql(`create index "orders_cash_shift_id_index" on "orders" ("cash_shift_id");`);
|
||||
this.addSql(`
|
||||
alter table "orders"
|
||||
add constraint "orders_cash_shift_id_foreign"
|
||||
foreign key ("cash_shift_id") references "cash_shifts" ("id") on update cascade on delete set null;
|
||||
`);
|
||||
}
|
||||
|
||||
override async down(): Promise<void> {
|
||||
this.addSql(`alter table "orders" drop constraint if exists "orders_cash_shift_id_foreign";`);
|
||||
this.addSql(`drop index if exists "orders_cash_shift_id_index";`);
|
||||
this.addSql(`alter table "orders" drop column if exists "cash_shift_id";`);
|
||||
|
||||
this.addSql(`alter table "cash_shifts" drop constraint if exists "cash_shifts_restaurant_id_foreign";`);
|
||||
this.addSql(`alter table "cash_shifts" drop constraint if exists "cash_shifts_admin_id_foreign";`);
|
||||
this.addSql(`drop table if exists "cash_shifts" cascade;`);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user