update order status
This commit is contained in:
@@ -961,18 +961,6 @@
|
||||
"default": "0",
|
||||
"mappedType": "decimal"
|
||||
},
|
||||
"credit": {
|
||||
"name": "credit",
|
||||
"type": "numeric(10,0)",
|
||||
"unsigned": false,
|
||||
"autoincrement": false,
|
||||
"primary": false,
|
||||
"nullable": false,
|
||||
"precision": 10,
|
||||
"scale": 0,
|
||||
"default": "0",
|
||||
"mappedType": "decimal"
|
||||
},
|
||||
"domain": {
|
||||
"name": "domain",
|
||||
"type": "varchar(255)",
|
||||
@@ -2917,6 +2905,263 @@
|
||||
},
|
||||
"nativeEnums": {}
|
||||
},
|
||||
{
|
||||
"columns": {
|
||||
"id": {
|
||||
"name": "id",
|
||||
"type": "char(26)",
|
||||
"unsigned": false,
|
||||
"autoincrement": false,
|
||||
"primary": false,
|
||||
"nullable": false,
|
||||
"length": 26,
|
||||
"mappedType": "character"
|
||||
},
|
||||
"created_at": {
|
||||
"name": "created_at",
|
||||
"type": "timestamptz",
|
||||
"unsigned": false,
|
||||
"autoincrement": false,
|
||||
"primary": false,
|
||||
"nullable": false,
|
||||
"length": 6,
|
||||
"default": "now()",
|
||||
"mappedType": "datetime"
|
||||
},
|
||||
"updated_at": {
|
||||
"name": "updated_at",
|
||||
"type": "timestamptz",
|
||||
"unsigned": false,
|
||||
"autoincrement": false,
|
||||
"primary": false,
|
||||
"nullable": false,
|
||||
"length": 6,
|
||||
"default": "now()",
|
||||
"mappedType": "datetime"
|
||||
},
|
||||
"deleted_at": {
|
||||
"name": "deleted_at",
|
||||
"type": "timestamptz",
|
||||
"unsigned": false,
|
||||
"autoincrement": false,
|
||||
"primary": false,
|
||||
"nullable": true,
|
||||
"length": 6,
|
||||
"mappedType": "datetime"
|
||||
},
|
||||
"admin_id": {
|
||||
"name": "admin_id",
|
||||
"type": "char(26)",
|
||||
"unsigned": false,
|
||||
"autoincrement": false,
|
||||
"primary": false,
|
||||
"nullable": false,
|
||||
"length": 26,
|
||||
"mappedType": "character"
|
||||
},
|
||||
"restaurant_id": {
|
||||
"name": "restaurant_id",
|
||||
"type": "char(26)",
|
||||
"unsigned": false,
|
||||
"autoincrement": false,
|
||||
"primary": false,
|
||||
"nullable": false,
|
||||
"length": 26,
|
||||
"mappedType": "character"
|
||||
},
|
||||
"opened_at": {
|
||||
"name": "opened_at",
|
||||
"type": "timestamptz",
|
||||
"unsigned": false,
|
||||
"autoincrement": false,
|
||||
"primary": false,
|
||||
"nullable": false,
|
||||
"length": 6,
|
||||
"mappedType": "datetime"
|
||||
},
|
||||
"closed_at": {
|
||||
"name": "closed_at",
|
||||
"type": "timestamptz",
|
||||
"unsigned": false,
|
||||
"autoincrement": false,
|
||||
"primary": false,
|
||||
"nullable": true,
|
||||
"length": 6,
|
||||
"mappedType": "datetime"
|
||||
},
|
||||
"opening_amount": {
|
||||
"name": "opening_amount",
|
||||
"type": "numeric(10,0)",
|
||||
"unsigned": false,
|
||||
"autoincrement": false,
|
||||
"primary": false,
|
||||
"nullable": false,
|
||||
"precision": 10,
|
||||
"scale": 0,
|
||||
"default": "0",
|
||||
"mappedType": "decimal"
|
||||
},
|
||||
"expected_amount": {
|
||||
"name": "expected_amount",
|
||||
"type": "numeric(10,0)",
|
||||
"unsigned": false,
|
||||
"autoincrement": false,
|
||||
"primary": false,
|
||||
"nullable": true,
|
||||
"precision": 10,
|
||||
"scale": 0,
|
||||
"mappedType": "decimal"
|
||||
},
|
||||
"counted_amount": {
|
||||
"name": "counted_amount",
|
||||
"type": "numeric(10,0)",
|
||||
"unsigned": false,
|
||||
"autoincrement": false,
|
||||
"primary": false,
|
||||
"nullable": true,
|
||||
"precision": 10,
|
||||
"scale": 0,
|
||||
"mappedType": "decimal"
|
||||
},
|
||||
"difference_amount": {
|
||||
"name": "difference_amount",
|
||||
"type": "numeric(10,0)",
|
||||
"unsigned": false,
|
||||
"autoincrement": false,
|
||||
"primary": false,
|
||||
"nullable": true,
|
||||
"precision": 10,
|
||||
"scale": 0,
|
||||
"mappedType": "decimal"
|
||||
},
|
||||
"orders": {
|
||||
"name": "orders",
|
||||
"type": "int",
|
||||
"unsigned": false,
|
||||
"autoincrement": false,
|
||||
"primary": false,
|
||||
"nullable": false,
|
||||
"default": "0",
|
||||
"mappedType": "integer"
|
||||
},
|
||||
"status": {
|
||||
"name": "status",
|
||||
"type": "text",
|
||||
"unsigned": false,
|
||||
"autoincrement": false,
|
||||
"primary": false,
|
||||
"nullable": false,
|
||||
"default": "'open'",
|
||||
"enumItems": [
|
||||
"open",
|
||||
"closed"
|
||||
],
|
||||
"mappedType": "enum"
|
||||
},
|
||||
"notes": {
|
||||
"name": "notes",
|
||||
"type": "text",
|
||||
"unsigned": false,
|
||||
"autoincrement": false,
|
||||
"primary": false,
|
||||
"nullable": true,
|
||||
"mappedType": "text"
|
||||
}
|
||||
},
|
||||
"name": "cash_shifts",
|
||||
"schema": "public",
|
||||
"indexes": [
|
||||
{
|
||||
"keyName": "cash_shifts_created_at_index",
|
||||
"columnNames": [
|
||||
"created_at"
|
||||
],
|
||||
"composite": false,
|
||||
"constraint": false,
|
||||
"primary": false,
|
||||
"unique": false
|
||||
},
|
||||
{
|
||||
"keyName": "cash_shifts_deleted_at_index",
|
||||
"columnNames": [
|
||||
"deleted_at"
|
||||
],
|
||||
"composite": false,
|
||||
"constraint": false,
|
||||
"primary": false,
|
||||
"unique": false
|
||||
},
|
||||
{
|
||||
"keyName": "cash_shifts_admin_id_index",
|
||||
"columnNames": [
|
||||
"admin_id"
|
||||
],
|
||||
"composite": false,
|
||||
"constraint": false,
|
||||
"primary": false,
|
||||
"unique": false
|
||||
},
|
||||
{
|
||||
"keyName": "cash_shifts_restaurant_id_status_index",
|
||||
"columnNames": [
|
||||
"restaurant_id",
|
||||
"status"
|
||||
],
|
||||
"composite": true,
|
||||
"constraint": false,
|
||||
"primary": false,
|
||||
"unique": false
|
||||
},
|
||||
{
|
||||
"keyName": "cash_shifts_restaurant_id_index",
|
||||
"columnNames": [
|
||||
"restaurant_id"
|
||||
],
|
||||
"composite": false,
|
||||
"constraint": false,
|
||||
"primary": false,
|
||||
"unique": false
|
||||
},
|
||||
{
|
||||
"keyName": "cash_shifts_pkey",
|
||||
"columnNames": [
|
||||
"id"
|
||||
],
|
||||
"composite": false,
|
||||
"constraint": true,
|
||||
"primary": true,
|
||||
"unique": true
|
||||
}
|
||||
],
|
||||
"checks": [],
|
||||
"foreignKeys": {
|
||||
"cash_shifts_admin_id_foreign": {
|
||||
"constraintName": "cash_shifts_admin_id_foreign",
|
||||
"columnNames": [
|
||||
"admin_id"
|
||||
],
|
||||
"localTableName": "public.cash_shifts",
|
||||
"referencedColumnNames": [
|
||||
"id"
|
||||
],
|
||||
"referencedTableName": "public.admins",
|
||||
"updateRule": "cascade"
|
||||
},
|
||||
"cash_shifts_restaurant_id_foreign": {
|
||||
"constraintName": "cash_shifts_restaurant_id_foreign",
|
||||
"columnNames": [
|
||||
"restaurant_id"
|
||||
],
|
||||
"localTableName": "public.cash_shifts",
|
||||
"referencedColumnNames": [
|
||||
"id"
|
||||
],
|
||||
"referencedTableName": "public.restaurants",
|
||||
"updateRule": "cascade"
|
||||
}
|
||||
},
|
||||
"nativeEnums": {}
|
||||
},
|
||||
{
|
||||
"columns": {
|
||||
"id": {
|
||||
@@ -2981,16 +3226,6 @@
|
||||
"length": 255,
|
||||
"mappedType": "string"
|
||||
},
|
||||
"groups": {
|
||||
"name": "groups",
|
||||
"type": "jsonb",
|
||||
"unsigned": false,
|
||||
"autoincrement": false,
|
||||
"primary": false,
|
||||
"nullable": false,
|
||||
"default": "'[]'",
|
||||
"mappedType": "json"
|
||||
},
|
||||
"sent_type": {
|
||||
"name": "sent_type",
|
||||
"type": "text",
|
||||
@@ -3140,6 +3375,159 @@
|
||||
},
|
||||
"nativeEnums": {}
|
||||
},
|
||||
{
|
||||
"columns": {
|
||||
"id": {
|
||||
"name": "id",
|
||||
"type": "char(26)",
|
||||
"unsigned": false,
|
||||
"autoincrement": false,
|
||||
"primary": false,
|
||||
"nullable": false,
|
||||
"length": 26,
|
||||
"mappedType": "character"
|
||||
},
|
||||
"created_at": {
|
||||
"name": "created_at",
|
||||
"type": "timestamptz",
|
||||
"unsigned": false,
|
||||
"autoincrement": false,
|
||||
"primary": false,
|
||||
"nullable": false,
|
||||
"length": 6,
|
||||
"default": "now()",
|
||||
"mappedType": "datetime"
|
||||
},
|
||||
"updated_at": {
|
||||
"name": "updated_at",
|
||||
"type": "timestamptz",
|
||||
"unsigned": false,
|
||||
"autoincrement": false,
|
||||
"primary": false,
|
||||
"nullable": false,
|
||||
"length": 6,
|
||||
"default": "now()",
|
||||
"mappedType": "datetime"
|
||||
},
|
||||
"deleted_at": {
|
||||
"name": "deleted_at",
|
||||
"type": "timestamptz",
|
||||
"unsigned": false,
|
||||
"autoincrement": false,
|
||||
"primary": false,
|
||||
"nullable": true,
|
||||
"length": 6,
|
||||
"mappedType": "datetime"
|
||||
},
|
||||
"restaurant_id": {
|
||||
"name": "restaurant_id",
|
||||
"type": "char(26)",
|
||||
"unsigned": false,
|
||||
"autoincrement": false,
|
||||
"primary": false,
|
||||
"nullable": false,
|
||||
"length": 26,
|
||||
"mappedType": "character"
|
||||
},
|
||||
"amount": {
|
||||
"name": "amount",
|
||||
"type": "numeric(10,0)",
|
||||
"unsigned": false,
|
||||
"autoincrement": false,
|
||||
"primary": false,
|
||||
"nullable": false,
|
||||
"precision": 10,
|
||||
"scale": 0,
|
||||
"mappedType": "decimal"
|
||||
},
|
||||
"invoice_id": {
|
||||
"name": "invoice_id",
|
||||
"type": "varchar(255)",
|
||||
"unsigned": false,
|
||||
"autoincrement": false,
|
||||
"primary": false,
|
||||
"nullable": false,
|
||||
"length": 255,
|
||||
"mappedType": "string"
|
||||
},
|
||||
"status": {
|
||||
"name": "status",
|
||||
"type": "text",
|
||||
"unsigned": false,
|
||||
"autoincrement": false,
|
||||
"primary": false,
|
||||
"nullable": false,
|
||||
"default": "'pending'",
|
||||
"enumItems": [
|
||||
"pending",
|
||||
"paid",
|
||||
"cancelled",
|
||||
"failed"
|
||||
],
|
||||
"mappedType": "enum"
|
||||
}
|
||||
},
|
||||
"name": "restaurant_credit_requests",
|
||||
"schema": "public",
|
||||
"indexes": [
|
||||
{
|
||||
"keyName": "restaurant_credit_requests_created_at_index",
|
||||
"columnNames": [
|
||||
"created_at"
|
||||
],
|
||||
"composite": false,
|
||||
"constraint": false,
|
||||
"primary": false,
|
||||
"unique": false
|
||||
},
|
||||
{
|
||||
"keyName": "restaurant_credit_requests_deleted_at_index",
|
||||
"columnNames": [
|
||||
"deleted_at"
|
||||
],
|
||||
"composite": false,
|
||||
"constraint": false,
|
||||
"primary": false,
|
||||
"unique": false
|
||||
},
|
||||
{
|
||||
"keyName": "restaurant_credit_requests_restaurant_id_index",
|
||||
"columnNames": [
|
||||
"restaurant_id"
|
||||
],
|
||||
"composite": false,
|
||||
"constraint": false,
|
||||
"primary": false,
|
||||
"unique": false
|
||||
},
|
||||
{
|
||||
"keyName": "restaurant_credit_requests_pkey",
|
||||
"columnNames": [
|
||||
"id"
|
||||
],
|
||||
"composite": false,
|
||||
"constraint": true,
|
||||
"primary": true,
|
||||
"unique": true
|
||||
}
|
||||
],
|
||||
"checks": [],
|
||||
"foreignKeys": {
|
||||
"restaurant_credit_requests_restaurant_id_foreign": {
|
||||
"constraintName": "restaurant_credit_requests_restaurant_id_foreign",
|
||||
"columnNames": [
|
||||
"restaurant_id"
|
||||
],
|
||||
"localTableName": "public.restaurant_credit_requests",
|
||||
"referencedColumnNames": [
|
||||
"id"
|
||||
],
|
||||
"referencedTableName": "public.restaurants",
|
||||
"updateRule": "cascade"
|
||||
}
|
||||
},
|
||||
"nativeEnums": {}
|
||||
},
|
||||
{
|
||||
"columns": {
|
||||
"id": {
|
||||
@@ -4734,6 +5122,16 @@
|
||||
"length": 26,
|
||||
"mappedType": "character"
|
||||
},
|
||||
"cash_shift_id": {
|
||||
"name": "cash_shift_id",
|
||||
"type": "char(26)",
|
||||
"unsigned": false,
|
||||
"autoincrement": false,
|
||||
"primary": false,
|
||||
"nullable": true,
|
||||
"length": 26,
|
||||
"mappedType": "character"
|
||||
},
|
||||
"delivery_method_id": {
|
||||
"name": "delivery_method_id",
|
||||
"type": "char(26)",
|
||||
@@ -4940,8 +5338,7 @@
|
||||
"primary": false,
|
||||
"nullable": false,
|
||||
"enumItems": [
|
||||
"pendingPayment",
|
||||
"paid",
|
||||
"new",
|
||||
"preparing",
|
||||
"deliveredToWaiter",
|
||||
"deliveredToReceptionist",
|
||||
@@ -4984,6 +5381,16 @@
|
||||
"primary": false,
|
||||
"unique": false
|
||||
},
|
||||
{
|
||||
"keyName": "orders_cash_shift_id_index",
|
||||
"columnNames": [
|
||||
"cash_shift_id"
|
||||
],
|
||||
"composite": false,
|
||||
"constraint": false,
|
||||
"primary": false,
|
||||
"unique": false
|
||||
},
|
||||
{
|
||||
"keyName": "orders_restaurant_id_order_number_index",
|
||||
"columnNames": [
|
||||
@@ -5054,6 +5461,19 @@
|
||||
"referencedTableName": "public.restaurants",
|
||||
"updateRule": "cascade"
|
||||
},
|
||||
"orders_cash_shift_id_foreign": {
|
||||
"constraintName": "orders_cash_shift_id_foreign",
|
||||
"columnNames": [
|
||||
"cash_shift_id"
|
||||
],
|
||||
"localTableName": "public.orders",
|
||||
"referencedColumnNames": [
|
||||
"id"
|
||||
],
|
||||
"referencedTableName": "public.cash_shifts",
|
||||
"deleteRule": "set null",
|
||||
"updateRule": "cascade"
|
||||
},
|
||||
"orders_delivery_method_id_foreign": {
|
||||
"constraintName": "orders_delivery_method_id_foreign",
|
||||
"columnNames": [
|
||||
@@ -6432,6 +6852,73 @@
|
||||
},
|
||||
"nativeEnums": {}
|
||||
},
|
||||
{
|
||||
"columns": {
|
||||
"campaign_id": {
|
||||
"name": "campaign_id",
|
||||
"type": "char(26)",
|
||||
"unsigned": false,
|
||||
"autoincrement": false,
|
||||
"primary": false,
|
||||
"nullable": false,
|
||||
"length": 26,
|
||||
"mappedType": "character"
|
||||
},
|
||||
"user_group_id": {
|
||||
"name": "user_group_id",
|
||||
"type": "char(26)",
|
||||
"unsigned": false,
|
||||
"autoincrement": false,
|
||||
"primary": false,
|
||||
"nullable": false,
|
||||
"length": 26,
|
||||
"mappedType": "character"
|
||||
}
|
||||
},
|
||||
"name": "campaign_user_groups",
|
||||
"schema": "public",
|
||||
"indexes": [
|
||||
{
|
||||
"keyName": "campaign_user_groups_pkey",
|
||||
"columnNames": [
|
||||
"campaign_id",
|
||||
"user_group_id"
|
||||
],
|
||||
"composite": true,
|
||||
"constraint": true,
|
||||
"primary": true,
|
||||
"unique": true
|
||||
}
|
||||
],
|
||||
"checks": [],
|
||||
"foreignKeys": {
|
||||
"campaign_user_groups_campaign_id_foreign": {
|
||||
"constraintName": "campaign_user_groups_campaign_id_foreign",
|
||||
"columnNames": [
|
||||
"campaign_id"
|
||||
],
|
||||
"localTableName": "public.campaign_user_groups",
|
||||
"referencedColumnNames": [
|
||||
"id"
|
||||
],
|
||||
"referencedTableName": "public.campaigns",
|
||||
"updateRule": "cascade"
|
||||
},
|
||||
"campaign_user_groups_user_group_id_foreign": {
|
||||
"constraintName": "campaign_user_groups_user_group_id_foreign",
|
||||
"columnNames": [
|
||||
"user_group_id"
|
||||
],
|
||||
"localTableName": "public.campaign_user_groups",
|
||||
"referencedColumnNames": [
|
||||
"id"
|
||||
],
|
||||
"referencedTableName": "public.user_groups",
|
||||
"updateRule": "cascade"
|
||||
}
|
||||
},
|
||||
"nativeEnums": {}
|
||||
},
|
||||
{
|
||||
"columns": {
|
||||
"id": {
|
||||
|
||||
@@ -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