feat(promotion,dashboard,types,utils,medusa): Add statuses to promotions (#10950)

what:

- adds a status column to promotion table
- introduce active promotion query
- scope revert, register and compute actions to active promotions
- admin to create and update promotion with statuses

RESOLVES CMRC-845
RESOLVES CMRC-846
RESOLVES CMRC-847
RESOLVES CMRC-848
RESOLVES CMRC-849
RESOLVES CMRC-850
This commit is contained in:
Riqwan Thamir
2025-01-16 19:17:22 +00:00
committed by GitHub
parent effee5c8bb
commit 5eab9e7399
35 changed files with 1208 additions and 1743 deletions
@@ -345,6 +345,21 @@
],
"mappedType": "enum"
},
"status": {
"name": "status",
"type": "text",
"unsigned": false,
"autoincrement": false,
"primary": false,
"nullable": false,
"default": "'draft'",
"enumItems": [
"draft",
"active",
"inactive"
],
"mappedType": "enum"
},
"campaign_id": {
"name": "campaign_id",
"type": "text",
@@ -414,6 +429,14 @@
"unique": false,
"expression": "CREATE INDEX IF NOT EXISTS \"IDX_promotion_type\" ON \"promotion\" (type) WHERE deleted_at IS NULL"
},
{
"keyName": "IDX_promotion_status",
"columnNames": [],
"composite": false,
"primary": false,
"unique": false,
"expression": "CREATE INDEX IF NOT EXISTS \"IDX_promotion_status\" ON \"promotion\" (status) WHERE deleted_at IS NULL"
},
{
"keyName": "IDX_promotion_campaign_id",
"columnNames": [],
@@ -0,0 +1,23 @@
import { Migration } from "@mikro-orm/migrations"
export class Migration20250113094144 extends Migration {
async up(): Promise<void> {
this.addSql(
"alter table if exists \"promotion\" add column if not exists \"status\" text check (\"status\" in ('draft', 'active', 'inactive')) not null default 'draft';"
)
this.addSql(
'CREATE INDEX IF NOT EXISTS "IDX_promotion_status" ON "promotion" (status) WHERE deleted_at IS NULL;'
)
// Data Migration
this.addSql(`UPDATE promotion SET status = 'active';`)
}
async down(): Promise<void> {
this.addSql('drop index if exists "IDX_promotion_status";')
this.addSql(
'alter table if exists "promotion" drop column if exists "status";'
)
}
}