feat(pricing): pricing models are made soft deletable (#6732)

what:

- pricing models are made soft deletable
- adds missing timestamp attributes
- removes unwanted relationships + cascade cleanup
This commit is contained in:
Riqwan Thamir
2024-03-20 16:03:17 +00:00
committed by GitHub
parent 70859397c0
commit 20243e22ee
36 changed files with 1006 additions and 1729 deletions
@@ -1,7 +1,5 @@
{
"namespaces": [
"public"
],
"namespaces": ["public"],
"name": "public",
"tables": [
{
@@ -21,7 +19,7 @@
"unsigned": false,
"autoincrement": false,
"primary": false,
"nullable": true,
"nullable": false,
"mappedType": "text"
},
"amount": {
@@ -30,7 +28,7 @@
"unsigned": false,
"autoincrement": false,
"primary": false,
"nullable": true,
"nullable": false,
"mappedType": "decimal"
},
"min_quantity": {
@@ -88,28 +86,24 @@
"schema": "public",
"indexes": [
{
"columnNames": [
"currency_code"
],
"composite": false,
"keyName": "IDX_money_amount_currency_code",
"columnNames": ["currency_code"],
"composite": false,
"primary": false,
"unique": false
"unique": false,
"expression": "CREATE INDEX IF NOT EXISTS \"IDX_money_amount_currency_code\" ON \"money_amount\" (currency_code) WHERE deleted_at IS NULL"
},
{
"columnNames": [
"deleted_at"
],
"composite": false,
"keyName": "IDX_money_amount_deleted_at",
"columnNames": ["deleted_at"],
"composite": false,
"primary": false,
"unique": false
"unique": false,
"expression": "CREATE INDEX IF NOT EXISTS \"IDX_money_amount_deleted_at\" ON \"money_amount\" (deleted_at) WHERE deleted_at IS NOT NULL"
},
{
"keyName": "money_amount_pkey",
"columnNames": [
"id"
],
"columnNames": ["id"],
"composite": false,
"primary": true,
"unique": true
@@ -155,10 +149,7 @@
"primary": false,
"nullable": false,
"default": "'draft'",
"enumItems": [
"active",
"draft"
],
"enumItems": ["active", "draft"],
"mappedType": "enum"
},
"type": {
@@ -169,10 +160,7 @@
"primary": false,
"nullable": false,
"default": "'sale'",
"enumItems": [
"sale",
"override"
],
"enumItems": ["sale", "override"],
"mappedType": "enum"
},
"starts_at": {
@@ -242,19 +230,16 @@
"schema": "public",
"indexes": [
{
"columnNames": [
"deleted_at"
],
"composite": false,
"keyName": "IDX_price_list_deleted_at",
"columnNames": ["deleted_at"],
"composite": false,
"primary": false,
"unique": false
"unique": false,
"expression": "CREATE INDEX IF NOT EXISTS \"IDX_price_list_deleted_at\" ON \"price_list\" (deleted_at) WHERE deleted_at IS NOT NULL"
},
{
"keyName": "price_list_pkey",
"columnNames": [
"id"
],
"columnNames": ["id"],
"composite": false,
"primary": true,
"unique": true
@@ -273,16 +258,54 @@
"primary": false,
"nullable": false,
"mappedType": "text"
},
"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"
}
},
"name": "price_set",
"schema": "public",
"indexes": [
{
"keyName": "IDX_price_set_deleted_at",
"columnNames": ["deleted_at"],
"composite": false,
"primary": false,
"unique": false,
"expression": "CREATE INDEX IF NOT EXISTS \"IDX_price_set_deleted_at\" ON \"price_set\" (deleted_at) WHERE deleted_at IS NOT NULL"
},
{
"keyName": "price_set_pkey",
"columnNames": [
"id"
],
"columnNames": ["id"],
"composite": false,
"primary": true,
"unique": true
@@ -308,7 +331,7 @@
"unsigned": false,
"autoincrement": false,
"primary": false,
"nullable": false,
"nullable": true,
"mappedType": "text"
},
"price_set_id": {
@@ -385,55 +408,47 @@
"schema": "public",
"indexes": [
{
"columnNames": [
"price_set_id"
],
"composite": false,
"keyName": "IDX_price_set_money_amount_price_set_id",
"primary": false,
"unique": false
},
{
"columnNames": [
"money_amount_id"
],
"composite": false,
"keyName": "IDX_price_set_money_amount_money_amount_id",
"primary": false,
"unique": false
},
{
"columnNames": [
"money_amount_id"
],
"columnNames": ["money_amount_id"],
"composite": false,
"keyName": "price_set_money_amount_money_amount_id_unique",
"primary": false,
"unique": true
},
{
"columnNames": [
"price_list_id"
],
"keyName": "IDX_price_set_money_amount_price_set_id",
"columnNames": ["price_set_id"],
"composite": false,
"keyName": "IDX_price_rule_price_list_id",
"primary": false,
"unique": false
"unique": false,
"expression": "CREATE INDEX IF NOT EXISTS \"IDX_price_set_money_amount_price_set_id\" ON \"price_set_money_amount\" (price_set_id) WHERE deleted_at IS NULL"
},
{
"columnNames": [
"deleted_at"
],
"keyName": "IDX_price_set_money_amount_money_amount_id",
"columnNames": ["money_amount_id"],
"composite": false,
"keyName": "IDX_price_set_money_amount_deleted_at",
"primary": false,
"unique": false
"unique": false,
"expression": "CREATE INDEX IF NOT EXISTS \"IDX_price_set_money_amount_money_amount_id\" ON \"price_set_money_amount\" (money_amount_id) WHERE deleted_at IS NULL"
},
{
"keyName": "IDX_price_set_money_amount_price_list_id",
"columnNames": ["price_list_id"],
"composite": false,
"primary": false,
"unique": false,
"expression": "CREATE INDEX IF NOT EXISTS \"IDX_price_set_money_amount_price_list_id\" ON \"price_set_money_amount\" (price_list_id) WHERE deleted_at IS NULL"
},
{
"keyName": "IDX_price_set_money_amount_deleted_at",
"columnNames": ["deleted_at"],
"composite": false,
"primary": false,
"unique": false,
"expression": "CREATE INDEX IF NOT EXISTS \"IDX_price_set_money_amount_deleted_at\" ON \"price_set_money_amount\" (deleted_at) WHERE deleted_at IS NOT NULL"
},
{
"keyName": "price_set_money_amount_pkey",
"columnNames": [
"id"
],
"columnNames": ["id"],
"composite": false,
"primary": true,
"unique": true
@@ -443,41 +458,30 @@
"foreignKeys": {
"price_set_money_amount_price_set_id_foreign": {
"constraintName": "price_set_money_amount_price_set_id_foreign",
"columnNames": [
"price_set_id"
],
"columnNames": ["price_set_id"],
"localTableName": "public.price_set_money_amount",
"referencedColumnNames": [
"id"
],
"referencedColumnNames": ["id"],
"referencedTableName": "public.price_set",
"deleteRule": "cascade",
"updateRule": "cascade"
},
"price_set_money_amount_money_amount_id_foreign": {
"constraintName": "price_set_money_amount_money_amount_id_foreign",
"columnNames": [
"money_amount_id"
],
"columnNames": ["money_amount_id"],
"localTableName": "public.price_set_money_amount",
"referencedColumnNames": [
"id"
],
"referencedColumnNames": ["id"],
"referencedTableName": "public.money_amount",
"deleteRule": "cascade",
"updateRule": "cascade"
},
"price_set_money_amount_price_list_id_foreign": {
"constraintName": "price_set_money_amount_price_list_id_foreign",
"columnNames": [
"price_list_id"
],
"columnNames": ["price_list_id"],
"localTableName": "public.price_set_money_amount",
"referencedColumnNames": [
"id"
],
"referencedColumnNames": ["id"],
"referencedTableName": "public.price_list",
"deleteRule": "cascade"
"deleteRule": "cascade",
"updateRule": "cascade"
}
}
},
@@ -541,25 +545,40 @@
"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"
}
},
"name": "rule_type",
"schema": "public",
"indexes": [
{
"columnNames": [
"rule_attribute"
],
"composite": false,
"keyName": "IDX_rule_type_rule_attribute",
"columnNames": ["rule_attribute"],
"composite": false,
"primary": false,
"unique": false
"unique": false,
"expression": "CREATE INDEX IF NOT EXISTS \"IDX_rule_type_rule_attribute\" ON \"rule_type\" (rule_attribute) WHERE deleted_at IS NULL"
},
{
"keyName": "IDX_rule_type_deleted_at",
"columnNames": ["deleted_at"],
"composite": false,
"primary": false,
"unique": false,
"expression": "CREATE INDEX IF NOT EXISTS \"IDX_rule_type_deleted_at\" ON \"rule_type\" (deleted_at) WHERE deleted_at IS NOT NULL"
},
{
"keyName": "rule_type_pkey",
"columnNames": [
"id"
],
"columnNames": ["id"],
"composite": false,
"primary": true,
"unique": true
@@ -596,34 +615,70 @@
"primary": false,
"nullable": false,
"mappedType": "text"
},
"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"
}
},
"name": "price_set_rule_type",
"schema": "public",
"indexes": [
{
"columnNames": [
"price_set_id"
],
"composite": false,
"keyName": "IDX_price_set_rule_type_price_set_id",
"columnNames": ["price_set_id"],
"composite": false,
"primary": false,
"unique": false
"unique": false,
"expression": "CREATE INDEX IF NOT EXISTS \"IDX_price_set_rule_type_price_set_id\" ON \"price_set_rule_type\" (price_set_id) WHERE deleted_at IS NULL"
},
{
"columnNames": [
"rule_type_id"
],
"composite": false,
"keyName": "IDX_price_set_rule_type_rule_type_id",
"columnNames": ["rule_type_id"],
"composite": false,
"primary": false,
"unique": false
"unique": false,
"expression": "CREATE INDEX IF NOT EXISTS \"IDX_price_set_rule_type_rule_type_id\" ON \"price_set_rule_type\" (rule_type_id) WHERE deleted_at IS NULL"
},
{
"keyName": "IDX_price_set_rule_type_deleted_at",
"columnNames": ["deleted_at"],
"composite": false,
"primary": false,
"unique": false,
"expression": "CREATE INDEX IF NOT EXISTS \"IDX_price_set_rule_type_deleted_at\" ON \"price_set_rule_type\" (deleted_at) WHERE deleted_at IS NOT NULL"
},
{
"keyName": "price_set_rule_type_pkey",
"columnNames": [
"id"
],
"columnNames": ["id"],
"composite": false,
"primary": true,
"unique": true
@@ -633,127 +688,21 @@
"foreignKeys": {
"price_set_rule_type_price_set_id_foreign": {
"constraintName": "price_set_rule_type_price_set_id_foreign",
"columnNames": [
"price_set_id"
],
"columnNames": ["price_set_id"],
"localTableName": "public.price_set_rule_type",
"referencedColumnNames": [
"id"
],
"referencedColumnNames": ["id"],
"referencedTableName": "public.price_set",
"deleteRule": "cascade",
"updateRule": "cascade"
},
"price_set_rule_type_rule_type_id_foreign": {
"constraintName": "price_set_rule_type_rule_type_id_foreign",
"columnNames": [
"rule_type_id"
],
"columnNames": ["rule_type_id"],
"localTableName": "public.price_set_rule_type",
"referencedColumnNames": [
"id"
],
"referencedColumnNames": ["id"],
"referencedTableName": "public.rule_type",
"updateRule": "cascade"
}
}
},
{
"columns": {
"id": {
"name": "id",
"type": "text",
"unsigned": false,
"autoincrement": false,
"primary": false,
"nullable": false,
"mappedType": "text"
},
"price_set_money_amount_id": {
"name": "price_set_money_amount_id",
"type": "text",
"unsigned": false,
"autoincrement": false,
"primary": false,
"nullable": false,
"mappedType": "text"
},
"rule_type_id": {
"name": "rule_type_id",
"type": "text",
"unsigned": false,
"autoincrement": false,
"primary": false,
"nullable": false,
"mappedType": "text"
},
"value": {
"name": "value",
"type": "text",
"unsigned": false,
"autoincrement": false,
"primary": false,
"nullable": false,
"mappedType": "text"
}
},
"name": "price_set_money_amount_rules",
"schema": "public",
"indexes": [
{
"columnNames": [
"price_set_money_amount_id"
],
"composite": false,
"keyName": "IDX_price_set_money_amount_rules_price_set_money_amount_id",
"primary": false,
"unique": false
},
{
"columnNames": [
"rule_type_id"
],
"composite": false,
"keyName": "IDX_price_set_money_amount_rules_rule_type_id",
"primary": false,
"unique": false
},
{
"keyName": "price_set_money_amount_rules_pkey",
"columnNames": [
"id"
],
"composite": false,
"primary": true,
"unique": true
}
],
"checks": [],
"foreignKeys": {
"price_set_money_amount_rules_price_set_money_amount_id_foreign": {
"constraintName": "price_set_money_amount_rules_price_set_money_amount_id_foreign",
"columnNames": [
"price_set_money_amount_id"
],
"localTableName": "public.price_set_money_amount_rules",
"referencedColumnNames": [
"id"
],
"referencedTableName": "public.price_set_money_amount",
"deleteRule": "cascade",
"updateRule": "cascade"
},
"price_set_money_amount_rules_rule_type_id_foreign": {
"constraintName": "price_set_money_amount_rules_rule_type_id_foreign",
"columnNames": [
"rule_type_id"
],
"localTableName": "public.price_set_money_amount_rules",
"referencedColumnNames": [
"id"
],
"referencedTableName": "public.rule_type",
"updateRule": "cascade"
}
}
},
@@ -851,46 +800,40 @@
"schema": "public",
"indexes": [
{
"columnNames": [
"price_set_id"
],
"composite": false,
"keyName": "IDX_price_rule_price_set_id",
"columnNames": ["price_set_id"],
"composite": false,
"primary": false,
"unique": false
"unique": false,
"expression": "CREATE INDEX IF NOT EXISTS \"IDX_price_rule_price_set_id\" ON \"price_rule\" (price_set_id) WHERE deleted_at IS NULL"
},
{
"columnNames": [
"rule_type_id"
],
"composite": false,
"keyName": "IDX_price_rule_rule_type_id",
"columnNames": ["rule_type_id"],
"composite": false,
"primary": false,
"unique": false
"unique": false,
"expression": "CREATE INDEX IF NOT EXISTS \"IDX_price_rule_rule_type_id\" ON \"price_rule\" (rule_type_id) WHERE deleted_at IS NULL"
},
{
"columnNames": [
"price_set_money_amount_id"
],
"keyName": "IDX_price_rule_price_set_money_amount_id_unique",
"columnNames": ["price_set_money_amount_id"],
"composite": false,
"keyName": "IDX_price_rule_price_set_money_amount_id",
"primary": false,
"unique": false
"unique": false,
"expression": "CREATE UNIQUE INDEX IF NOT EXISTS \"IDX_price_rule_price_set_money_amount_id_unique\" ON \"price_rule\" (price_set_money_amount_id) WHERE deleted_at IS NULL"
},
{
"columnNames": [
"deleted_at"
],
"composite": false,
"keyName": "IDX_price_rule_deleted_at",
"columnNames": ["deleted_at"],
"composite": false,
"primary": false,
"unique": false
"unique": false,
"expression": "CREATE INDEX IF NOT EXISTS \"IDX_price_rule_deleted_at\" ON \"price_rule\" (deleted_at) WHERE deleted_at IS NOT NULL"
},
{
"keyName": "price_rule_pkey",
"columnNames": [
"id"
],
"columnNames": ["id"],
"composite": false,
"primary": true,
"unique": true
@@ -900,38 +843,26 @@
"foreignKeys": {
"price_rule_price_set_id_foreign": {
"constraintName": "price_rule_price_set_id_foreign",
"columnNames": [
"price_set_id"
],
"columnNames": ["price_set_id"],
"localTableName": "public.price_rule",
"referencedColumnNames": [
"id"
],
"referencedColumnNames": ["id"],
"referencedTableName": "public.price_set",
"deleteRule": "cascade",
"updateRule": "cascade"
},
"price_rule_rule_type_id_foreign": {
"constraintName": "price_rule_rule_type_id_foreign",
"columnNames": [
"rule_type_id"
],
"columnNames": ["rule_type_id"],
"localTableName": "public.price_rule",
"referencedColumnNames": [
"id"
],
"referencedColumnNames": ["id"],
"referencedTableName": "public.rule_type",
"updateRule": "cascade"
},
"price_rule_price_set_money_amount_id_foreign": {
"constraintName": "price_rule_price_set_money_amount_id_foreign",
"columnNames": [
"price_set_money_amount_id"
],
"columnNames": ["price_set_money_amount_id"],
"localTableName": "public.price_rule",
"referencedColumnNames": [
"id"
],
"referencedColumnNames": ["id"],
"referencedTableName": "public.price_set_money_amount",
"deleteRule": "cascade",
"updateRule": "cascade"
@@ -958,6 +889,38 @@
"nullable": false,
"mappedType": "text"
},
"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"
},
"rule_type_id": {
"name": "rule_type_id",
"type": "text",
@@ -972,38 +935,32 @@
"schema": "public",
"indexes": [
{
"columnNames": [
"price_list_id"
],
"keyName": "IDX_price_list_rule_rule_type_id_unique",
"columnNames": ["rule_type_id"],
"composite": false,
"primary": false,
"unique": false,
"expression": "CREATE UNIQUE INDEX IF NOT EXISTS \"IDX_price_list_rule_rule_type_id_unique\" ON \"price_list_rule\" (rule_type_id) WHERE deleted_at IS NULL"
},
{
"keyName": "IDX_price_list_rule_price_list_id",
"primary": false,
"unique": false
},
{
"columnNames": [
"rule_type_id"
],
"columnNames": ["price_list_id"],
"composite": false,
"keyName": "IDX_price_list_rule_rule_type_id",
"primary": false,
"unique": false
"unique": false,
"expression": "CREATE INDEX IF NOT EXISTS \"IDX_price_list_rule_price_list_id\" ON \"price_list_rule\" (price_list_id) WHERE deleted_at IS NULL"
},
{
"keyName": "IDX_price_list_rule_rule_type_id_price_list_id_unique",
"columnNames": [
"price_list_id",
"rule_type_id"
],
"composite": true,
"keyName": "IDX_price_list_rule_deleted_at",
"columnNames": ["deleted_at"],
"composite": false,
"primary": false,
"unique": true
"unique": false,
"expression": "CREATE INDEX IF NOT EXISTS \"IDX_price_list_rule_deleted_at\" ON \"price_list_rule\" (deleted_at) WHERE deleted_at IS NOT NULL"
},
{
"keyName": "price_list_rule_pkey",
"columnNames": [
"id"
],
"columnNames": ["id"],
"composite": false,
"primary": true,
"unique": true
@@ -1013,25 +970,18 @@
"foreignKeys": {
"price_list_rule_price_list_id_foreign": {
"constraintName": "price_list_rule_price_list_id_foreign",
"columnNames": [
"price_list_id"
],
"columnNames": ["price_list_id"],
"localTableName": "public.price_list_rule",
"referencedColumnNames": [
"id"
],
"referencedColumnNames": ["id"],
"referencedTableName": "public.price_list",
"deleteRule": "cascade",
"updateRule": "cascade"
},
"price_list_rule_rule_type_id_foreign": {
"constraintName": "price_list_rule_rule_type_id_foreign",
"columnNames": [
"rule_type_id"
],
"columnNames": ["rule_type_id"],
"localTableName": "public.price_list_rule",
"referencedColumnNames": [
"id"
],
"referencedColumnNames": ["id"],
"referencedTableName": "public.rule_type",
"updateRule": "cascade"
}
@@ -1065,25 +1015,62 @@
"primary": false,
"nullable": false,
"mappedType": "text"
},
"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"
}
},
"name": "price_list_rule_value",
"schema": "public",
"indexes": [
{
"columnNames": [
"price_list_rule_id"
],
"keyName": "IDX_price_list_rule_value_price_list_rule_id",
"columnNames": ["price_list_rule_id"],
"composite": false,
"keyName": "IDX_price_list_rule_price_list_rule_value_id",
"primary": false,
"unique": false
"unique": false,
"expression": "CREATE INDEX IF NOT EXISTS \"IDX_price_list_rule_value_price_list_rule_id\" ON \"price_list_rule_value\" (price_list_rule_id) WHERE deleted_at IS NULL"
},
{
"keyName": "IDX_price_list_rule_value_deleted_at",
"columnNames": ["deleted_at"],
"composite": false,
"primary": false,
"unique": false,
"expression": "CREATE INDEX IF NOT EXISTS \"IDX_price_list_rule_value_deleted_at\" ON \"price_list_rule_value\" (deleted_at) WHERE deleted_at IS NOT NULL"
},
{
"keyName": "price_list_rule_value_pkey",
"columnNames": [
"id"
],
"columnNames": ["id"],
"composite": false,
"primary": true,
"unique": true
@@ -1093,13 +1080,9 @@
"foreignKeys": {
"price_list_rule_value_price_list_rule_id_foreign": {
"constraintName": "price_list_rule_value_price_list_rule_id_foreign",
"columnNames": [
"price_list_rule_id"
],
"columnNames": ["price_list_rule_id"],
"localTableName": "public.price_list_rule_value",
"referencedColumnNames": [
"id"
],
"referencedColumnNames": ["id"],
"referencedTableName": "public.price_list_rule",
"deleteRule": "cascade",
"updateRule": "cascade"
@@ -3,65 +3,31 @@ import { Migration } from "@mikro-orm/migrations"
export class Migration20230929122253 extends Migration {
async up(): Promise<void> {
this.addSql(
'create table if not exists "money_amount" ("id" text not null, "currency_code" text null, "amount" numeric null, "min_quantity" numeric null, "max_quantity" numeric null, constraint "money_amount_pkey" primary key ("id"));'
)
this.addSql(
'create index if not exists "IDX_money_amount_currency_code" on "money_amount" ("currency_code");'
'create table if not exists "money_amount" ("id" text not null, "currency_code" text not null, "amount" numeric not null, "min_quantity" numeric null, "max_quantity" numeric null, "created_at" timestamptz not null default now(), "updated_at" timestamptz not null default now(), "deleted_at" timestamptz null, constraint "money_amount_pkey" primary key ("id"));'
)
this.addSql(
'create table "price_set" ("id" text not null, constraint "price_set_pkey" primary key ("id"));'
'create table "price_set" ("id" text not null, "created_at" timestamptz not null default now(), "updated_at" timestamptz not null default now(), "deleted_at" timestamptz null, constraint "price_set_pkey" primary key ("id"));'
)
this.addSql(
'create table "price_set_money_amount" ("id" text not null, "title" text not null, "price_set_id" text not null, "money_amount_id" text not null, "rules_count" integer not null default 0, constraint "price_set_money_amount_pkey" primary key ("id"));'
)
this.addSql(
'create index "IDX_price_set_money_amount_price_set_id" on "price_set_money_amount" ("price_set_id");'
)
this.addSql(
'create index "IDX_price_set_money_amount_money_amount_id" on "price_set_money_amount" ("money_amount_id");'
'create table "price_set_money_amount" ("id" text not null, "title" text, "price_set_id" text not null, "money_amount_id" text not null, "rules_count" integer not null default 0, "created_at" timestamptz not null default now(), "updated_at" timestamptz not null default now(), "deleted_at" timestamptz null, constraint "price_set_money_amount_pkey" primary key ("id"));'
)
this.addSql(
'create table "rule_type" ("id" text not null, "name" text not null, "rule_attribute" text not null, "default_priority" integer not null default 0, "created_at" timestamptz not null default now(), "updated_at" timestamptz not null default now(), constraint "rule_type_pkey" primary key ("id"));'
'alter table "price_set_money_amount" add constraint "price_set_money_amount_money_amount_id_unique" unique ("money_amount_id");'
)
this.addSql(
'create index "IDX_rule_type_rule_attribute" on "rule_type" ("rule_attribute");'
'create table "rule_type" ("id" text not null, "name" text not null, "rule_attribute" text not null, "default_priority" integer not null default 0, "created_at" timestamptz not null default now(), "updated_at" timestamptz not null default now(), "deleted_at" timestamptz null, constraint "rule_type_pkey" primary key ("id"));'
)
this.addSql(
'create table "price_set_rule_type" ("id" text not null, "price_set_id" text not null, "rule_type_id" text not null, constraint "price_set_rule_type_pkey" primary key ("id"));'
)
this.addSql(
'create index "IDX_price_set_rule_type_price_set_id" on "price_set_rule_type" ("price_set_id");'
)
this.addSql(
'create index "IDX_price_set_rule_type_rule_type_id" on "price_set_rule_type" ("rule_type_id");'
'create table "price_set_rule_type" ("id" text not null, "price_set_id" text not null, "rule_type_id" text not null, "created_at" timestamptz not null default now(), "updated_at" timestamptz not null default now(), "deleted_at" timestamptz null, constraint "price_set_rule_type_pkey" primary key ("id"));'
)
this.addSql(
'create table "price_set_money_amount_rules" ("id" text not null, "price_set_money_amount_id" text not null, "rule_type_id" text not null, "value" text not null, constraint "price_set_money_amount_rules_pkey" primary key ("id"));'
)
this.addSql(
'create index "IDX_price_set_money_amount_rules_price_set_money_amount_id" on "price_set_money_amount_rules" ("price_set_money_amount_id");'
)
this.addSql(
'create index "IDX_price_set_money_amount_rules_rule_type_id" on "price_set_money_amount_rules" ("rule_type_id");'
)
this.addSql(
'create table "price_rule" ("id" text not null, "price_set_id" text not null, "rule_type_id" text not null, "is_dynamic" boolean not null default false, "value" text not null, "priority" integer not null default 0, "price_set_money_amount_id" text not null, "price_list_id" text not null, constraint "price_rule_pkey" primary key ("id"));'
)
this.addSql(
'create index "IDX_price_rule_price_set_id" on "price_rule" ("price_set_id");'
)
this.addSql(
'create index "IDX_price_rule_rule_type_id" on "price_rule" ("rule_type_id");'
)
this.addSql(
'create index "IDX_price_rule_price_set_money_amount_id" on "price_rule" ("price_set_money_amount_id");'
'create table "price_rule" ("id" text not null, "price_set_id" text not null, "rule_type_id" text not null, "value" text not null, "priority" integer not null default 0, "price_set_money_amount_id" text not null, "price_list_id" text not null, "created_at" timestamptz not null default now(), "updated_at" timestamptz not null default now(), "deleted_at" timestamptz null, constraint "price_rule_pkey" primary key ("id"));'
)
this.addSql(
@@ -78,13 +44,6 @@ export class Migration20230929122253 extends Migration {
'alter table "price_set_rule_type" add constraint "price_set_rule_type_rule_type_id_foreign" foreign key ("rule_type_id") references "rule_type" ("id") on update cascade;'
)
this.addSql(
'alter table "price_set_money_amount_rules" add constraint "price_set_money_amount_rules_price_set_money_amount_id_foreign" foreign key ("price_set_money_amount_id") references "price_set_money_amount" ("id") on update cascade on delete cascade;'
)
this.addSql(
'alter table "price_set_money_amount_rules" add constraint "price_set_money_amount_rules_rule_type_id_foreign" foreign key ("rule_type_id") references "rule_type" ("id") on update cascade;'
)
this.addSql(
'alter table "price_rule" add constraint "price_rule_price_set_id_foreign" foreign key ("price_set_id") references "price_set" ("id") on update cascade on delete cascade;'
)
@@ -100,14 +59,7 @@ export class Migration20230929122253 extends Migration {
)
this.addSql(
'create table "price_list_rule" ("id" text not null, "rule_type_id" text not null, "price_list_id" text not null, constraint "price_list_rule_pkey" primary key ("id"));'
)
this.addSql(
'create index "IDX_price_list_rule_rule_type_id" on "price_list_rule" ("rule_type_id");'
)
this.addSql(
'create index "IDX_price_list_rule_price_list_id" on "price_list_rule" ("price_list_id");'
'create table "price_list_rule" ("id" text not null, "rule_type_id" text not null, "price_list_id" text not null, "created_at" timestamptz not null default now(), "updated_at" timestamptz not null default now(), "deleted_at" timestamptz null, constraint "price_list_rule_pkey" primary key ("id"));'
)
this.addSql(
@@ -120,13 +72,139 @@ export class Migration20230929122253 extends Migration {
this.addSql(
'alter table "price_set_money_amount" add column "price_list_id" text null;'
)
this.addSql(
'alter table "price_set_money_amount" add constraint "price_set_money_amount_price_list_id_foreign" foreign key ("price_list_id") references "price_list" ("id") on update cascade on delete set null;'
)
this.addSql(
'create index "IDX_price_rule_price_list_id" on "price_set_money_amount" ("price_list_id");'
)
this.addSql('alter table "price_rule" drop column "price_list_id";')
this.addSql(
'create table "price_list_rule_value" ("id" text not null, "value" text not null, "price_list_rule_id" text not null, "created_at" timestamptz not null default now(), "updated_at" timestamptz not null default now(), "deleted_at" timestamptz null, constraint "price_list_rule_value_pkey" primary key ("id"));'
)
this.addSql(
'alter table "price_list_rule_value" add constraint "price_list_rule_value_price_list_rule_id_foreign" foreign key ("price_list_rule_id") references "price_list_rule" ("id") on update cascade on delete cascade;'
)
this.addSql(
`ALTER TABLE price_list
ADD COLUMN IF NOT EXISTS rules_count integer not null default 0`
)
this.addSql(
'alter table "price_list" add column if not exists "title" text, add column if not exists "name" text, add column if not exists "description" text not null, add column if not exists "type" text check ("type" in (\'sale\', \'override\')) not null default \'sale\', add column if not exists "created_at" timestamptz not null default now(), add column if not exists "updated_at" timestamptz not null default now(), add column if not exists "deleted_at" timestamptz null;'
)
this.addSql(`
UPDATE "price_list"
SET title = name
`)
this.addSql(`alter table "price_list" alter column "title" set not null `)
this.addSql(
'CREATE INDEX IF NOT EXISTS "IDX_money_amount_currency_code" ON "money_amount" (currency_code) WHERE deleted_at IS NULL;'
)
this.addSql(
'CREATE INDEX IF NOT EXISTS "IDX_money_amount_deleted_at" ON "money_amount" (deleted_at) WHERE deleted_at IS NOT NULL;'
)
this.addSql(
'CREATE INDEX IF NOT EXISTS "IDX_price_list_deleted_at" ON "price_list" (deleted_at) WHERE deleted_at IS NOT NULL;'
)
this.addSql(
'CREATE INDEX IF NOT EXISTS "IDX_price_set_deleted_at" ON "price_set" (deleted_at) WHERE deleted_at IS NOT NULL;'
)
this.addSql(
'CREATE INDEX IF NOT EXISTS "IDX_price_set_money_amount_price_set_id" ON "price_set_money_amount" (price_set_id) WHERE deleted_at IS NULL;'
)
this.addSql(
'CREATE INDEX IF NOT EXISTS "IDX_price_set_money_amount_money_amount_id" ON "price_set_money_amount" (money_amount_id) WHERE deleted_at IS NULL;'
)
this.addSql(
'CREATE INDEX IF NOT EXISTS "IDX_price_set_money_amount_price_list_id" ON "price_set_money_amount" (price_list_id) WHERE deleted_at IS NULL;'
)
this.addSql(
'CREATE INDEX IF NOT EXISTS "IDX_price_set_money_amount_deleted_at" ON "price_set_money_amount" (deleted_at) WHERE deleted_at IS NOT NULL;'
)
this.addSql(
'CREATE INDEX IF NOT EXISTS "IDX_rule_type_rule_attribute" ON "rule_type" (rule_attribute) WHERE deleted_at IS NOT NULL;'
)
this.addSql(
'CREATE INDEX IF NOT EXISTS "IDX_rule_type_deleted_at" ON "rule_type" (deleted_at) WHERE deleted_at IS NOT NULL;'
)
this.addSql(
'CREATE INDEX IF NOT EXISTS "IDX_price_set_rule_type_price_set_id" ON "price_set_rule_type" (price_set_id) WHERE deleted_at IS NOT NULL;'
)
this.addSql(
'CREATE INDEX IF NOT EXISTS "IDX_price_set_rule_type_rule_type_id" ON "price_set_rule_type" (rule_type_id) WHERE deleted_at IS NOT NULL;'
)
this.addSql(
'CREATE INDEX IF NOT EXISTS "IDX_price_set_rule_type_deleted_at" ON "price_set_rule_type" (deleted_at) WHERE deleted_at IS NOT NULL;'
)
this.addSql(
'CREATE INDEX IF NOT EXISTS "IDX_price_rule_price_set_id" ON "price_rule" (price_set_id) WHERE deleted_at IS NOT NULL;'
)
this.addSql(
'CREATE INDEX IF NOT EXISTS "IDX_price_rule_rule_type_id" ON "price_rule" (rule_type_id) WHERE deleted_at IS NOT NULL;'
)
this.addSql(
'CREATE UNIQUE INDEX IF NOT EXISTS "IDX_price_rule_price_set_money_amount_id_unique" ON "price_rule" (price_set_money_amount_id) WHERE deleted_at IS NOT NULL;'
)
this.addSql(
'CREATE INDEX IF NOT EXISTS "IDX_price_rule_deleted_at" ON "price_rule" (deleted_at) WHERE deleted_at IS NOT NULL;'
)
this.addSql(
'CREATE UNIQUE INDEX IF NOT EXISTS "IDX_price_list_rule_rule_type_id_unique" ON "price_list_rule" (rule_type_id) WHERE deleted_at IS NOT NULL;'
)
this.addSql(
'CREATE INDEX IF NOT EXISTS "IDX_price_list_rule_price_list_id" ON "price_list_rule" (price_list_id) WHERE deleted_at IS NOT NULL;'
)
this.addSql(
'CREATE INDEX IF NOT EXISTS "IDX_price_list_rule_deleted_at" ON "price_list_rule" (deleted_at) WHERE deleted_at IS NOT NULL;'
)
this.addSql(
'CREATE INDEX IF NOT EXISTS "IDX_price_list_rule_value_price_list_rule_id" ON "price_list_rule_value" (price_list_rule_id) WHERE deleted_at IS NULL;'
)
this.addSql(
'CREATE INDEX IF NOT EXISTS "IDX_price_list_rule_value_deleted_at" ON "price_list_rule_value" (deleted_at) WHERE deleted_at IS NOT NULL;'
)
this.addSql(
'alter table if exists "price_list" drop column if exists "name";'
)
this.addSql(
'alter table if exists "price_set_money_amount" add constraint "price_set_money_amount_price_list_id_foreign" foreign key ("price_list_id") references "price_list" ("id") on update cascade on delete cascade;'
)
this.addSql(
'alter table if exists "price_rule" drop constraint if exists "price_rule_rule_type_id_foreign";'
)
this.addSql(
'alter table if exists "price_rule" add constraint "price_rule_rule_type_id_foreign" foreign key ("rule_type_id") references "rule_type" ("id") on update cascade on delete cascade;'
)
this.addSql(
'alter table if exists "price_rule" drop constraint if exists "price_rule_rule_type_id_foreign";'
)
this.addSql(
'alter table if exists "price_list_rule" drop constraint if exists "price_list_rule_price_list_id_foreign";'
)
this.addSql(
'alter table if exists "price_rule" add constraint "price_rule_rule_type_id_foreign" foreign key ("rule_type_id") references "rule_type" ("id") on update cascade;'
)
this.addSql(
'alter table if exists "price_list_rule" add constraint "price_list_rule_price_list_id_foreign" foreign key ("price_list_id") references "price_list" ("id") on update cascade on delete cascade;'
)
this.addSql(
'alter table if exists "price_set_rule_type" drop constraint if exists "price_set_rule_type_rule_type_id_foreign";'
)
this.addSql(
'alter table if exists "price_set_rule_type" add constraint "price_set_rule_type_rule_type_id_foreign" foreign key ("rule_type_id") references "rule_type" ("id") on update cascade on delete cascade;'
)
}
}
@@ -1,120 +0,0 @@
import { Migration } from "@mikro-orm/migrations"
export class Migration20231101232834 extends Migration {
async up(): Promise<void> {
this.addSql(
'create table "price_list_rule_value" ("id" text not null, "value" text not null, "price_list_rule_id" text not null, constraint "price_list_rule_value_pkey" primary key ("id"));'
)
this.addSql(
'create index "IDX_price_list_rule_price_list_rule_value_id" on "price_list_rule_value" ("price_list_rule_id");'
)
this.addSql(
'alter table "price_list_rule_value" add constraint "price_list_rule_value_price_list_rule_id_foreign" foreign key ("price_list_rule_id") references "price_list_rule" ("id") on update cascade on delete cascade;'
)
this.addSql(
`ALTER TABLE price_list
ADD COLUMN IF NOT EXISTS rules_count integer not null default 0`
)
this.addSql(
'alter table "price_set_money_amount" drop constraint "price_set_money_amount_price_list_id_foreign";'
)
this.addSql(
'alter table "price_set_money_amount" add constraint "price_set_money_amount_price_list_id_foreign" foreign key ("price_list_id") references "price_list" ("id") on update cascade on delete cascade;'
)
this.addSql(
'alter table "price_list" add column if not exists "title" text, add column if not exists "name" text, add column if not exists "description" text not null, add column if not exists "type" text check ("type" in (\'sale\', \'override\')) not null default \'sale\', add column if not exists "created_at" timestamptz not null default now(), add column if not exists "updated_at" timestamptz not null default now(), add column if not exists "deleted_at" timestamptz null;'
)
this.addSql(`
UPDATE "price_list"
SET title = name
`)
this.addSql(`alter table "price_list" alter column "title" set not null `)
this.addSql(
'create index if not exists "IDX_price_list_deleted_at" on "price_list" ("deleted_at");'
)
this.addSql(
'alter table "price_list_rule" drop constraint if exists "IDX_price_list_rule_rule_type_id_price_list_id_unique"'
)
this.addSql(
'alter table "price_list_rule" add constraint "IDX_price_list_rule_rule_type_id_price_list_id_unique" unique ("price_list_id", "rule_type_id");'
)
this.addSql(
'alter table "money_amount" add column if not exists "created_at" timestamptz not null default now(), add column if not exists "updated_at" timestamptz not null default now(), add column if not exists "deleted_at" timestamptz null;'
)
this.addSql(
'create index if not exists "IDX_money_amount_deleted_at" on "money_amount" ("deleted_at");'
)
this.addSql(
'alter table "price_set_money_amount" add constraint "price_set_money_amount_money_amount_id_unique" unique ("money_amount_id");'
)
}
async down(): Promise<void> {
this.addSql('drop table if exists "price_list_rule_value" cascade;')
this.addSql(`ALTER TABLE price_list DROP COLUMN IF EXISTS rules_count`)
this.addSql('alter table "price_list" drop column if exists "title";')
this.addSql('alter table "price_list" drop column if exists "description";')
this.addSql('alter table "price_list" drop column if exists "type";')
this.addSql(
'alter table "price_set_money_amount" drop constraint "price_set_money_amount_price_list_id_foreign";'
)
this.addSql(
'alter table "price_set_money_amount" add constraint "price_set_money_amount_price_list_id_foreign" foreign key ("price_list_id") references "price_list" ("id") on update cascade on delete set null;'
)
this.addSql('drop index if exists "IDX_price_list_deleted_at";')
this.addSql('alter table "price_list" drop column if exists "title";')
this.addSql('alter table "price_list" drop column if exists "description";')
this.addSql('alter table "price_list" drop column if exists "type";')
this.addSql('alter table "price_list" drop column if exists "created_at";')
this.addSql('alter table "price_list" drop column if exists "updated_at";')
this.addSql('alter table "price_list" drop column if exists "deleted_at";')
this.addSql(
'alter table "price_list_rule" drop constraint if exists "IDX_price_list_rule_rule_type_id_price_list_id_unique";'
)
this.addSql('drop index if exists "IDX_money_amount_deleted_at";')
this.addSql(
'alter table "money_amount" drop column if exists "created_at";'
)
this.addSql(
'alter table "money_amount" drop column if exists "updated_at";'
)
this.addSql(
'alter table "money_amount" drop column if exists "deleted_at";'
)
this.addSql(
'alter table "price_set_money_amount" drop constraint if exists "price_set_money_amount_money_amount_id_unique";'
)
}
}
@@ -1,55 +0,0 @@
import { Migration } from "@mikro-orm/migrations"
export class Migration20240103140327 extends Migration {
async up(): Promise<void> {
this.addSql(
'alter table "price_set_money_amount" drop constraint "price_set_money_amount_price_list_id_foreign";'
)
this.addSql(
'alter table "price_set_money_amount" add column "created_at" timestamptz not null default now(), add column "updated_at" timestamptz not null default now(), add column "deleted_at" timestamptz null;'
)
this.addSql(
'alter table "price_set_money_amount" add constraint "price_set_money_amount_price_list_id_foreign" foreign key ("price_list_id") references "price_list" ("id") on delete cascade;'
)
this.addSql(
'create index "IDX_price_set_money_amount_deleted_at" on "price_set_money_amount" ("deleted_at");'
)
this.addSql(
'alter table "price_rule" add column "created_at" timestamptz not null default now(), add column "updated_at" timestamptz not null default now(), add column "deleted_at" timestamptz null;'
)
this.addSql('alter table "price_rule" drop column "is_dynamic";')
this.addSql(
'create index "IDX_price_rule_deleted_at" on "price_rule" ("deleted_at");'
)
}
async down(): Promise<void> {
this.addSql(
'alter table "price_set_money_amount" drop constraint "price_set_money_amount_price_list_id_foreign";'
)
this.addSql('drop index "IDX_price_set_money_amount_deleted_at";')
this.addSql(
'alter table "price_set_money_amount" drop column "created_at";'
)
this.addSql(
'alter table "price_set_money_amount" drop column "updated_at";'
)
this.addSql(
'alter table "price_set_money_amount" drop column "deleted_at";'
)
this.addSql(
'alter table "price_set_money_amount" add constraint "price_set_money_amount_price_list_id_foreign" foreign key ("price_list_id") references "price_list" ("id") on update cascade on delete cascade;'
)
this.addSql(
'alter table "price_rule" add column "is_dynamic" boolean not null default false;'
)
this.addSql('drop index "IDX_price_rule_deleted_at";')
this.addSql('alter table "price_rule" drop column "created_at";')
this.addSql('alter table "price_rule" drop column "updated_at";')
this.addSql('alter table "price_rule" drop column "deleted_at";')
}
}
-1
View File
@@ -5,6 +5,5 @@ export { default as PriceListRuleValue } from "./price-list-rule-value"
export { default as PriceRule } from "./price-rule"
export { default as PriceSet } from "./price-set"
export { default as PriceSetMoneyAmount } from "./price-set-money-amount"
export { default as PriceSetMoneyAmountRules } from "./price-set-money-amount-rules"
export { default as PriceSetRuleType } from "./price-set-rule-type"
export { default as RuleType } from "./rule-type"
+36 -36
View File
@@ -1,60 +1,53 @@
import { DALUtils, generateEntityId } from "@medusajs/utils"
import { DAL } from "@medusajs/types"
import {
DALUtils,
createPsqlIndexStatementHelper,
generateEntityId,
} from "@medusajs/utils"
import {
BeforeCreate,
Collection,
Entity,
Filter,
Index,
ManyToMany,
OnInit,
OneToOne,
OptionalProps,
PrimaryKey,
Property,
} from "@mikro-orm/core"
import { PriceSetMoneyAmount } from "./index"
import PriceSet from "./price-set"
@Entity()
type OptionalFields = DAL.SoftDeletableEntityDateColumns
const tableName = "money_amount"
const MoneyAmountDeletedAtIndex = createPsqlIndexStatementHelper({
tableName: tableName,
columns: "deleted_at",
where: "deleted_at IS NOT NULL",
})
const MoneyAmountCurrencyCodeIndex = createPsqlIndexStatementHelper({
tableName: tableName,
columns: "currency_code",
where: "deleted_at IS NULL",
})
@Entity({ tableName })
@Filter(DALUtils.mikroOrmSoftDeletableFilterOptions)
class MoneyAmount {
[OptionalProps]?:
| "created_at"
| "updated_at"
| "deleted_at"
| "price_set_money_amount"
| "amount"
[OptionalProps]?: OptionalFields
@PrimaryKey({ columnType: "text" })
id!: string
@Property({
columnType: "text",
nullable: true,
index: "IDX_money_amount_currency_code",
})
currency_code: string | null
@ManyToMany({
entity: () => PriceSet,
mappedBy: (ps) => ps.money_amounts,
})
price_sets = new Collection<PriceSet>(this)
@OneToOne({
entity: () => PriceSetMoneyAmount,
mappedBy: (psma) => psma.money_amount,
cascade: ["soft-remove"] as any,
})
price_set_money_amount: PriceSetMoneyAmount
@MoneyAmountCurrencyCodeIndex.MikroORMIndex()
@Property({ columnType: "text" })
currency_code: string
@Property({
columnType: "numeric",
nullable: true,
serializer: Number,
})
amount: number | null
amount: number
@Property({ columnType: "numeric", nullable: true })
min_quantity: number | null
@@ -62,6 +55,13 @@ class MoneyAmount {
@Property({ columnType: "numeric", nullable: true })
max_quantity: number | null
@OneToOne({
entity: () => PriceSetMoneyAmount,
mappedBy: (psma) => psma.money_amount,
onDelete: "cascade",
})
price_set_money_amount: PriceSetMoneyAmount
@Property({
onCreate: () => new Date(),
columnType: "timestamptz",
@@ -77,9 +77,9 @@ class MoneyAmount {
})
updated_at: Date
@Index({ name: "IDX_money_amount_deleted_at" })
@MoneyAmountDeletedAtIndex.MikroORMIndex()
@Property({ columnType: "timestamptz", nullable: true })
deleted_at: Date | null
deleted_at: Date | null = null
@BeforeCreate()
onCreate() {
@@ -1,30 +1,73 @@
import { DAL } from "@medusajs/types"
import {
DALUtils,
createPsqlIndexStatementHelper,
generateEntityId,
} from "@medusajs/utils"
import {
BeforeCreate,
Entity,
Filter,
ManyToOne,
OnInit,
OptionalProps,
PrimaryKey,
Property,
} from "@mikro-orm/core"
import PriceListRule from "./price-list-rule"
import { generateEntityId } from "@medusajs/utils"
@Entity()
type OptionalFields = DAL.SoftDeletableEntityDateColumns
const tableName = "price_list_rule_value"
const PriceListRuleValueDeletedAtIndex = createPsqlIndexStatementHelper({
tableName: tableName,
columns: "deleted_at",
where: "deleted_at IS NOT NULL",
})
const PriceListPriceListRuleIdIndex = createPsqlIndexStatementHelper({
tableName: tableName,
columns: "price_list_rule_id",
where: "deleted_at IS NULL",
})
@Entity({ tableName })
@Filter(DALUtils.mikroOrmSoftDeletableFilterOptions)
export default class PriceListRuleValue {
[OptionalProps]?: OptionalFields
@PrimaryKey({ columnType: "text" })
id!: string
@PriceListPriceListRuleIdIndex.MikroORMIndex()
@ManyToOne(() => PriceListRule, {
onDelete: "cascade",
fieldName: "price_list_rule_id",
index: "IDX_price_list_rule_price_list_rule_value_id",
})
price_list_rule: PriceListRule
@Property({ columnType: "text" })
value: string
@Property({
onCreate: () => new Date(),
columnType: "timestamptz",
defaultRaw: "now()",
})
created_at: Date
@Property({
onCreate: () => new Date(),
onUpdate: () => new Date(),
columnType: "timestamptz",
defaultRaw: "now()",
})
updated_at: Date
@PriceListRuleValueDeletedAtIndex.MikroORMIndex()
@Property({ columnType: "timestamptz", nullable: true })
deleted_at: Date | null = null
@BeforeCreate()
onCreate() {
this.id = generateEntityId(this.id, "plrv")
+56 -20
View File
@@ -1,56 +1,92 @@
import { DAL } from "@medusajs/types"
import {
DALUtils,
createPsqlIndexStatementHelper,
generateEntityId,
} from "@medusajs/utils"
import {
BeforeCreate,
Cascade,
Collection,
Entity,
Filter,
ManyToOne,
OneToMany,
OnInit,
OneToMany,
OptionalProps,
PrimaryKey,
Unique,
Property,
} from "@mikro-orm/core"
import { generateEntityId } from "@medusajs/utils"
import PriceList from "./price-list"
import PriceListRuleValue from "./price-list-rule-value"
import RuleType from "./rule-type"
type OptionalFields = "id"
type OptionalRelations = "rule_type" | "price_list"
type OptionalFields = DAL.SoftDeletableEntityDateColumns
@Entity()
@Unique({
name: "IDX_price_list_rule_rule_type_id_price_list_id_unique",
properties: ["price_list", "rule_type"],
const tableName = "price_list_rule"
const PriceListRuleDeletedAtIndex = createPsqlIndexStatementHelper({
tableName: tableName,
columns: "deleted_at",
where: "deleted_at IS NOT NULL",
})
const PriceListRuleRuleTypeIdIndex = createPsqlIndexStatementHelper({
tableName: tableName,
columns: "rule_type_id",
where: "deleted_at IS NULL",
unique: true,
})
const PriceListRulePriceListIdIndex = createPsqlIndexStatementHelper({
tableName: tableName,
columns: "price_list_id",
where: "deleted_at IS NULL",
})
@Entity({ tableName })
@Filter(DALUtils.mikroOrmSoftDeletableFilterOptions)
export default class PriceListRule {
[OptionalProps]: OptionalFields | OptionalRelations
[OptionalProps]: OptionalFields
@PrimaryKey({ columnType: "text" })
id!: string
@ManyToOne({
entity: () => RuleType,
fieldName: "rule_type_id",
name: "price_rule_rule_type_id_unique",
index: "IDX_price_list_rule_rule_type_id",
})
@PriceListRuleRuleTypeIdIndex.MikroORMIndex()
@ManyToOne({ entity: () => RuleType, fieldName: "rule_type_id" })
rule_type: RuleType
@OneToMany(() => PriceListRuleValue, (plrv) => plrv.price_list_rule, {
cascade: [Cascade.REMOVE],
cascade: ["soft-remove" as Cascade],
})
price_list_rule_values = new Collection<PriceListRuleValue>(this)
@PriceListRulePriceListIdIndex.MikroORMIndex()
@ManyToOne({
entity: () => PriceList,
fieldName: "price_list_id",
name: "price_rule_price_list_id",
index: "IDX_price_list_rule_price_list_id",
onDelete: "cascade",
})
price_list: PriceList
@Property({
onCreate: () => new Date(),
columnType: "timestamptz",
defaultRaw: "now()",
})
created_at: Date
@Property({
onCreate: () => new Date(),
onUpdate: () => new Date(),
columnType: "timestamptz",
defaultRaw: "now()",
})
updated_at: Date
@PriceListRuleDeletedAtIndex.MikroORMIndex()
@Property({ columnType: "timestamptz", nullable: true })
deleted_at: Date | null = null
@BeforeCreate()
beforeCreate() {
this.id = generateEntityId(this.id, "plrule")
+23 -23
View File
@@ -1,7 +1,10 @@
import { DAL } from "@medusajs/types"
import {
generateEntityId,
DALUtils,
PriceListStatus,
PriceListType,
createPsqlIndexStatementHelper,
generateEntityId,
} from "@medusajs/utils"
import {
BeforeCreate,
@@ -9,10 +12,10 @@ import {
Collection,
Entity,
Enum,
Index,
Filter,
ManyToMany,
OneToMany,
OnInit,
OneToMany,
OptionalProps,
PrimaryKey,
Property,
@@ -22,23 +25,21 @@ import PriceSetMoneyAmount from "./price-set-money-amount"
import RuleType from "./rule-type"
type OptionalFields =
| "status"
| "type"
| "rules_count"
| "starts_at"
| "ends_at"
| "created_at"
| "updated_at"
| "deleted_at"
| DAL.SoftDeletableEntityDateColumns
type OptionalRelations =
| "price_set_money_amounts"
| "rule_types"
| "price_list_rules"
const tableName = "price_list"
const PriceListDeletedAtIndex = createPsqlIndexStatementHelper({
tableName: tableName,
columns: "deleted_at",
where: "deleted_at IS NOT NULL",
})
@Entity()
@Entity({ tableName })
@Filter(DALUtils.mikroOrmSoftDeletableFilterOptions)
export default class PriceList {
[OptionalProps]: OptionalFields | OptionalRelations
[OptionalProps]: OptionalFields
@PrimaryKey({ columnType: "text" })
id!: string
@@ -59,33 +60,32 @@ export default class PriceList {
columnType: "timestamptz",
nullable: true,
})
starts_at: Date | null
starts_at: Date | null = null
@Property({
columnType: "timestamptz",
nullable: true,
})
ends_at: Date | null
ends_at: Date | null = null
@OneToMany(() => PriceSetMoneyAmount, (psma) => psma.price_list, {
cascade: [Cascade.REMOVE],
cascade: ["soft-remove" as Cascade],
})
price_set_money_amounts = new Collection<PriceSetMoneyAmount>(this)
@OneToMany(() => PriceListRule, (pr) => pr.price_list, {
cascade: [Cascade.REMOVE],
cascade: ["soft-remove" as Cascade],
})
price_list_rules = new Collection<PriceListRule>(this)
@ManyToMany({
entity: () => RuleType,
pivotEntity: () => PriceListRule,
cascade: [Cascade.REMOVE],
})
rule_types = new Collection<RuleType>(this)
@Property({ columnType: "integer", default: 0 })
rules_count?: number
rules_count: number = 0
@Property({
onCreate: () => new Date(),
@@ -102,9 +102,9 @@ export default class PriceList {
})
updated_at: Date
@Index({ name: "IDX_price_list_deleted_at" })
@PriceListDeletedAtIndex.MikroORMIndex()
@Property({ columnType: "timestamptz", nullable: true })
deleted_at: Date | null
deleted_at: Date | null = null
@BeforeCreate()
onCreate() {
+42 -27
View File
@@ -1,66 +1,81 @@
import { DAL } from "@medusajs/types"
import {
DALUtils,
createPsqlIndexStatementHelper,
generateEntityId,
} from "@medusajs/utils"
import {
BeforeCreate,
Entity,
Filter,
Index,
ManyToOne,
OnInit,
OptionalProps,
PrimaryKey,
Property,
} from "@mikro-orm/core"
import { DALUtils, generateEntityId } from "@medusajs/utils"
import PriceSet from "./price-set"
import PriceSetMoneyAmount from "./price-set-money-amount"
import RuleType from "./rule-type"
type OptionalFields =
| "id"
| "is_dynamic"
| "priority"
| "created_at"
| "updated_at"
| "deleted_at"
type OptionalRelations = "price_set" | "rule_type" | "price_set_money_amount"
type OptionalFields = DAL.SoftDeletableEntityDateColumns
@Entity()
const tableName = "price_rule"
const PriceRuleDeletedAtIndex = createPsqlIndexStatementHelper({
tableName: tableName,
columns: "deleted_at",
where: "deleted_at IS NOT NULL",
})
const PriceRulePriceSetIdIndex = createPsqlIndexStatementHelper({
tableName: tableName,
columns: "price_set_id",
where: "deleted_at IS NULL",
})
const PriceRuleRuleTypeIdIndex = createPsqlIndexStatementHelper({
tableName: tableName,
columns: "rule_type_id",
where: "deleted_at IS NULL",
})
const PriceRulePriceSetMoneyAmountIdIndex = createPsqlIndexStatementHelper({
tableName: tableName,
columns: "price_set_money_amount_id",
where: "deleted_at IS NULL",
unique: true,
})
@Entity({ tableName })
@Filter(DALUtils.mikroOrmSoftDeletableFilterOptions)
export default class PriceRule {
[OptionalProps]: OptionalFields | OptionalRelations
[OptionalProps]?: OptionalFields
@PrimaryKey({ columnType: "text" })
id!: string
@PriceRulePriceSetIdIndex.MikroORMIndex()
@ManyToOne({
entity: () => PriceSet,
fieldName: "price_set_id",
name: "price_rule_price_set_id_unique",
onDelete: "cascade",
index: "IDX_price_rule_price_set_id",
})
price_set: PriceSet
@ManyToOne({
entity: () => RuleType,
fieldName: "rule_type_id",
name: "price_rule_rule_type_id_unique",
index: "IDX_price_rule_rule_type_id",
})
@PriceRuleRuleTypeIdIndex.MikroORMIndex()
@ManyToOne({ entity: () => RuleType })
rule_type: RuleType
@Property({ columnType: "text" })
value: string
@Property({ columnType: "integer", default: 0 })
priority: number
priority: number = 0
@PriceRulePriceSetMoneyAmountIdIndex.MikroORMIndex()
@ManyToOne({
onDelete: "cascade",
entity: () => PriceSetMoneyAmount,
fieldName: "price_set_money_amount_id",
name: "price_set_money_amount_id_unique",
index: "IDX_price_rule_price_set_money_amount_id",
})
price_set_money_amount: PriceSetMoneyAmount
@@ -79,9 +94,9 @@ export default class PriceRule {
})
updated_at: Date
@Index({ name: "IDX_price_rule_deleted_at" })
@PriceRuleDeletedAtIndex.MikroORMIndex()
@Property({ columnType: "timestamptz", nullable: true })
deleted_at: Date | null
deleted_at: Date | null = null
@BeforeCreate()
beforeCreate() {
@@ -1,35 +1,82 @@
import { generateEntityId } from "@medusajs/utils"
import { DAL } from "@medusajs/types"
import {
DALUtils,
createPsqlIndexStatementHelper,
generateEntityId,
} from "@medusajs/utils"
import {
BeforeCreate,
Entity,
Filter,
ManyToOne,
OnInit,
OptionalProps,
PrimaryKey,
Property,
} from "@mikro-orm/core"
import PriceSetMoneyAmount from "./price-set-money-amount"
import RuleType from "./rule-type"
@Entity()
type OptionalFields = DAL.SoftDeletableEntityDateColumns
const tableName = "price_set_money_amount_rules"
const PriceSetMoneyAmountRulesDeletedAtIndex = createPsqlIndexStatementHelper({
tableName: tableName,
columns: "deleted_at",
where: "deleted_at IS NOT NULL",
})
const PriceSetMoneyAmountRulesPriceSetMoneyAmountIdIndex =
createPsqlIndexStatementHelper({
tableName: tableName,
columns: "price_set_money_amount_id",
where: "deleted_at IS NULL",
})
const PriceSetMoneyAmountRulesRuleTypeIdIndex = createPsqlIndexStatementHelper({
tableName: tableName,
columns: "rule_type_id",
where: "deleted_at IS NULL",
})
@Entity({ tableName })
@Filter(DALUtils.mikroOrmSoftDeletableFilterOptions)
export default class PriceSetMoneyAmountRules {
[OptionalProps]?: OptionalFields
@PrimaryKey({ columnType: "text" })
id!: string
@ManyToOne(() => PriceSetMoneyAmount, {
onDelete: "cascade",
index: "IDX_price_set_money_amount_rules_price_set_money_amount_id",
})
@PriceSetMoneyAmountRulesPriceSetMoneyAmountIdIndex.MikroORMIndex()
@ManyToOne(() => PriceSetMoneyAmount, { onDelete: "cascade" })
price_set_money_amount: PriceSetMoneyAmount
@ManyToOne(() => RuleType, {
index: "IDX_price_set_money_amount_rules_rule_type_id",
})
@PriceSetMoneyAmountRulesRuleTypeIdIndex.MikroORMIndex()
@ManyToOne(() => RuleType, { onDelete: "cascade" })
rule_type: RuleType
@Property({ columnType: "text" })
value: string
@Property({
onCreate: () => new Date(),
columnType: "timestamptz",
defaultRaw: "now()",
})
created_at: Date
@Property({
onCreate: () => new Date(),
onUpdate: () => new Date(),
columnType: "timestamptz",
defaultRaw: "now()",
})
updated_at: Date
@PriceSetMoneyAmountRulesDeletedAtIndex.MikroORMIndex()
@Property({ columnType: "timestamptz", nullable: true })
deleted_at: Date | null = null
@BeforeCreate()
onCreate() {
this.id = generateEntityId(this.id, "psmar")
@@ -1,3 +1,9 @@
import { DAL } from "@medusajs/types"
import {
DALUtils,
createPsqlIndexStatementHelper,
generateEntityId,
} from "@medusajs/utils"
import {
BeforeCreate,
Cascade,
@@ -5,67 +11,76 @@ import {
Entity,
Filter,
ManyToOne,
OnInit,
OneToMany,
OneToOne,
OnInit,
OptionalProps,
PrimaryKey,
PrimaryKeyType,
Property,
} from "@mikro-orm/core"
import { DALUtils, generateEntityId } from "@medusajs/utils"
import MoneyAmount from "./money-amount"
import PriceList from "./price-list"
import PriceRule from "./price-rule"
import PriceSet from "./price-set"
import PriceSetMoneyAmountRules from "./price-set-money-amount-rules"
@Entity()
type OptionalFields = DAL.SoftDeletableEntityDateColumns
const tableName = "price_set_money_amount"
const PriceSetMoneyAmountDeletedAtIndex = createPsqlIndexStatementHelper({
tableName: tableName,
columns: "deleted_at",
where: "deleted_at IS NOT NULL",
})
const PriceSetMoneyAmountPriceSetIdIndex = createPsqlIndexStatementHelper({
tableName: tableName,
columns: "price_set_id",
where: "deleted_at IS NULL",
})
const PriceSetMoneyAmountMoneyAmountIdIndex = createPsqlIndexStatementHelper({
tableName: tableName,
columns: "money_amount_id",
where: "deleted_at IS NULL",
})
const PriceSetMoneyAmountPriceListIdIndex = createPsqlIndexStatementHelper({
tableName: tableName,
columns: "price_list_id",
where: "deleted_at IS NULL",
})
@Entity({ tableName })
@Filter(DALUtils.mikroOrmSoftDeletableFilterOptions)
export default class PriceSetMoneyAmount {
[OptionalProps]?: "created_at" | "updated_at" | "deleted_at"
[OptionalProps]?: OptionalFields
@PrimaryKey({ columnType: "text" })
id!: string
@Property({ columnType: "text" })
title!: string
@Property({ columnType: "text", nullable: true })
title: string | null = null
@ManyToOne(() => PriceSet, {
onDelete: "cascade",
index: "IDX_price_set_money_amount_price_set_id",
})
@PriceSetMoneyAmountPriceSetIdIndex.MikroORMIndex()
@ManyToOne(() => PriceSet, { onDelete: "cascade" })
price_set: PriceSet
@OneToOne(() => MoneyAmount, {
onDelete: "cascade",
index: "IDX_price_set_money_amount_money_amount_id",
})
@PriceSetMoneyAmountMoneyAmountIdIndex.MikroORMIndex()
@OneToOne(() => MoneyAmount, { onDelete: "cascade" })
money_amount: MoneyAmount
@Property({ columnType: "integer", default: 0 })
rules_count: number
rules_count: number = 0
@OneToMany({
entity: () => PriceRule,
mappedBy: (pr) => pr.price_set_money_amount,
cascade: ["soft-remove"] as any,
cascade: ["soft-remove" as Cascade],
})
price_rules = new Collection<PriceRule>(this)
@OneToMany({
entity: () => PriceSetMoneyAmountRules,
mappedBy: (psmar) => psmar.price_set_money_amount,
})
price_set_money_amount_rules = new Collection<PriceSetMoneyAmountRules>(this)
@ManyToOne(() => PriceList, {
index: "IDX_price_rule_price_list_id",
onDelete: "cascade",
cascade: [Cascade.REMOVE, "soft-remove"] as any,
nullable: true,
})
@PriceSetMoneyAmountPriceListIdIndex.MikroORMIndex()
@ManyToOne(() => PriceList, { onDelete: "cascade", nullable: true })
price_list: PriceList | null
@Property({
@@ -83,12 +98,9 @@ export default class PriceSetMoneyAmount {
})
updated_at: Date
@Property({
columnType: "timestamptz",
nullable: true,
index: "IDX_price_set_money_amount_deleted_at",
})
deleted_at: Date | null
@PriceSetMoneyAmountDeletedAtIndex.MikroORMIndex()
@Property({ columnType: "timestamptz", nullable: true })
deleted_at: Date | null = null
@BeforeCreate()
onCreate() {
@@ -99,11 +111,4 @@ export default class PriceSetMoneyAmount {
onInit() {
this.id = generateEntityId(this.id, "psma")
}
[PrimaryKeyType]?: [string, string]
constructor(money_amount: MoneyAmount, price_set: PriceSet) {
this.money_amount = money_amount
this.price_set = price_set
}
}
@@ -1,31 +1,72 @@
import {
DALUtils,
createPsqlIndexStatementHelper,
generateEntityId,
} from "@medusajs/utils"
import {
BeforeCreate,
Entity,
Filter,
ManyToOne,
OnInit,
PrimaryKey,
Property,
} from "@mikro-orm/core"
import PriceSet from "./price-set"
import RuleType from "./rule-type"
import { generateEntityId } from "@medusajs/utils"
@Entity()
const tableName = "price_set_rule_type"
const PriceSetRuleTypeDeletedAtIndex = createPsqlIndexStatementHelper({
tableName: tableName,
columns: "deleted_at",
where: "deleted_at IS NOT NULL",
})
const PriceSetRuleTypePriceSetIdIndex = createPsqlIndexStatementHelper({
tableName: tableName,
columns: "price_set_id",
where: "deleted_at IS NULL",
})
const PriceSetRuleTypeRuleTypeIdIndex = createPsqlIndexStatementHelper({
tableName: tableName,
columns: "rule_type_id",
where: "deleted_at IS NULL",
})
@Entity({ tableName })
@Filter(DALUtils.mikroOrmSoftDeletableFilterOptions)
export default class PriceSetRuleType {
@PrimaryKey({ columnType: "text" })
id!: string
@ManyToOne(() => PriceSet, {
onDelete: "cascade",
index: "IDX_price_set_rule_type_price_set_id",
})
@PriceSetRuleTypePriceSetIdIndex.MikroORMIndex()
@ManyToOne(() => PriceSet, { onDelete: "cascade" })
price_set: PriceSet
@ManyToOne(() => RuleType, {
index: "IDX_price_set_rule_type_rule_type_id",
})
@PriceSetRuleTypeRuleTypeIdIndex.MikroORMIndex()
@ManyToOne(() => RuleType, { onDelete: "cascade" })
rule_type: RuleType
@Property({
onCreate: () => new Date(),
columnType: "timestamptz",
defaultRaw: "now()",
})
created_at: Date
@Property({
onCreate: () => new Date(),
onUpdate: () => new Date(),
columnType: "timestamptz",
defaultRaw: "now()",
})
updated_at: Date
@PriceSetRuleTypeDeletedAtIndex.MikroORMIndex()
@Property({ columnType: "timestamptz", nullable: true })
deleted_at: Date | null = null
@BeforeCreate()
onCreate() {
this.id = generateEntityId(this.id, "psrt")
+39 -17
View File
@@ -1,52 +1,74 @@
import { generateEntityId } from "@medusajs/utils"
import {
DALUtils,
createPsqlIndexStatementHelper,
generateEntityId,
} from "@medusajs/utils"
import {
BeforeCreate,
Cascade,
Collection,
Entity,
Filter,
ManyToMany,
OneToMany,
OnInit,
OptionalProps,
OneToMany,
PrimaryKey,
Property,
} from "@mikro-orm/core"
import MoneyAmount from "./money-amount"
import PriceRule from "./price-rule"
import PriceSetMoneyAmount from "./price-set-money-amount"
import PriceSetRuleType from "./price-set-rule-type"
import RuleType from "./rule-type"
@Entity()
export default class PriceSet {
[OptionalProps]?: "price_set_money_amounts" | "rule_types" | "money_amounts"
const tableName = "price_set"
const PriceSetDeletedAtIndex = createPsqlIndexStatementHelper({
tableName: tableName,
columns: "deleted_at",
where: "deleted_at IS NOT NULL",
})
@Entity({ tableName })
@Filter(DALUtils.mikroOrmSoftDeletableFilterOptions)
export default class PriceSet {
@PrimaryKey({ columnType: "text" })
id!: string
@OneToMany(() => PriceSetMoneyAmount, (psma) => psma.price_set, {
cascade: [Cascade.REMOVE],
cascade: ["soft-remove" as Cascade],
})
price_set_money_amounts = new Collection<PriceSetMoneyAmount>(this)
@OneToMany(() => PriceRule, (pr) => pr.price_set, {
cascade: [Cascade.REMOVE],
cascade: ["soft-remove" as Cascade],
})
price_rules = new Collection<PriceRule>(this)
@ManyToMany({
entity: () => MoneyAmount,
pivotEntity: () => PriceSetMoneyAmount,
})
money_amounts = new Collection<MoneyAmount>(this)
@ManyToMany({
entity: () => RuleType,
pivotEntity: () => PriceSetRuleType,
cascade: [Cascade.REMOVE],
cascade: ["soft-remove" as Cascade],
})
rule_types = new Collection<RuleType>(this)
@Property({
onCreate: () => new Date(),
columnType: "timestamptz",
defaultRaw: "now()",
})
created_at: Date
@Property({
onCreate: () => new Date(),
onUpdate: () => new Date(),
columnType: "timestamptz",
defaultRaw: "now()",
})
updated_at: Date
@PriceSetDeletedAtIndex.MikroORMIndex()
@Property({ columnType: "timestamptz", nullable: true })
deleted_at: Date | null = null
@BeforeCreate()
onCreate() {
this.id = generateEntityId(this.id, "pset")
+27 -3
View File
@@ -1,8 +1,13 @@
import { generateEntityId } from "@medusajs/utils"
import {
DALUtils,
createPsqlIndexStatementHelper,
generateEntityId,
} from "@medusajs/utils"
import {
BeforeCreate,
Collection,
Entity,
Filter,
ManyToMany,
OnInit,
OptionalProps,
@@ -13,7 +18,21 @@ import PriceSet from "./price-set"
type OptionalFields = "default_priority"
@Entity()
const tableName = "rule_type"
const RuleTypeDeletedAtIndex = createPsqlIndexStatementHelper({
tableName: tableName,
columns: "deleted_at",
where: "deleted_at IS NOT NULL",
})
const RuleTypeRuleAttributeIndex = createPsqlIndexStatementHelper({
tableName: tableName,
columns: "rule_attribute",
where: "deleted_at IS NULL",
})
@Entity({ tableName })
@Filter(DALUtils.mikroOrmSoftDeletableFilterOptions)
class RuleType {
[OptionalProps]?: OptionalFields
@@ -23,7 +42,8 @@ class RuleType {
@Property({ columnType: "text" })
name: string
@Property({ columnType: "text", index: "IDX_rule_type_rule_attribute" })
@RuleTypeRuleAttributeIndex.MikroORMIndex()
@Property({ columnType: "text" })
rule_attribute: string
@Property({ columnType: "integer", default: 0 })
@@ -47,6 +67,10 @@ class RuleType {
})
updated_at: Date
@RuleTypeDeletedAtIndex.MikroORMIndex()
@Property({ columnType: "timestamptz", nullable: true })
deleted_at: Date | null = null
@BeforeCreate()
onCreate() {
this.id = generateEntityId(this.id, "rul-typ")
+10 -79
View File
@@ -35,7 +35,6 @@ import {
PriceRule,
PriceSet,
PriceSetMoneyAmount,
PriceSetMoneyAmountRules,
PriceSetRuleType,
RuleType,
} from "@models"
@@ -56,7 +55,6 @@ type InjectedDependencies = {
pricingRepository: PricingRepositoryService
moneyAmountService: ModulesSdkTypes.InternalModuleService<any>
priceSetService: ModulesSdkTypes.InternalModuleService<any>
priceSetMoneyAmountRulesService: ModulesSdkTypes.InternalModuleService<any>
ruleTypeService: RuleTypeService<any>
priceRuleService: PriceRuleService<any>
priceSetRuleTypeService: ModulesSdkTypes.InternalModuleService<any>
@@ -73,7 +71,6 @@ const generateMethodForModels = [
PriceListRuleValue,
PriceRule,
PriceSetMoneyAmount,
PriceSetMoneyAmountRules,
PriceSetRuleType,
RuleType,
]
@@ -82,7 +79,6 @@ export default class PricingModuleService<
TPriceSet extends PriceSet = PriceSet,
TMoneyAmount extends MoneyAmount = MoneyAmount,
TRuleType extends RuleType = RuleType,
TPriceSetMoneyAmountRules extends PriceSetMoneyAmountRules = PriceSetMoneyAmountRules,
TPriceRule extends PriceRule = PriceRule,
TPriceSetRuleType extends PriceSetRuleType = PriceSetRuleType,
TPriceSetMoneyAmount extends PriceSetMoneyAmount = PriceSetMoneyAmount,
@@ -100,10 +96,11 @@ export default class PricingModuleService<
update: PricingTypes.UpdateMoneyAmountDTO
}
PriceSetMoneyAmount: { dto: PricingTypes.PriceSetMoneyAmountDTO }
PriceSetMoneyAmountRules: {
dto: PricingTypes.PriceSetMoneyAmountRulesDTO
PriceRule: {
dto: PricingTypes.PriceRuleDTO
create: PricingTypes.CreatePriceRuleDTO
update: PricingTypes.UpdatePriceRuleDTO
}
PriceRule: { dto: PricingTypes.PriceRuleDTO }
RuleType: {
dto: PricingTypes.RuleTypeDTO
create: PricingTypes.CreateRuleTypeDTO
@@ -120,7 +117,6 @@ export default class PricingModuleService<
protected readonly moneyAmountService_: ModulesSdkTypes.InternalModuleService<TMoneyAmount>
protected readonly ruleTypeService_: RuleTypeService<TRuleType>
protected readonly priceSetService_: ModulesSdkTypes.InternalModuleService<TPriceSet>
protected readonly priceSetMoneyAmountRulesService_: ModulesSdkTypes.InternalModuleService<TPriceSetMoneyAmountRules>
protected readonly priceRuleService_: PriceRuleService<TPriceRule>
protected readonly priceSetRuleTypeService_: ModulesSdkTypes.InternalModuleService<TPriceSetRuleType>
protected readonly priceSetMoneyAmountService_: ModulesSdkTypes.InternalModuleService<TPriceSetMoneyAmount>
@@ -135,7 +131,6 @@ export default class PricingModuleService<
moneyAmountService,
ruleTypeService,
priceSetService,
priceSetMoneyAmountRulesService,
priceRuleService,
priceSetRuleTypeService,
priceSetMoneyAmountService,
@@ -153,7 +148,6 @@ export default class PricingModuleService<
this.moneyAmountService_ = moneyAmountService
this.ruleTypeService_ = ruleTypeService
this.priceSetService_ = priceSetService
this.priceSetMoneyAmountRulesService_ = priceSetMoneyAmountRulesService
this.ruleTypeService_ = ruleTypeService
this.priceRuleService_ = priceRuleService
this.priceSetRuleTypeService_ = priceSetRuleTypeService
@@ -259,7 +253,11 @@ export default class PricingModuleService<
const dbPriceSets = await this.list(
{ id: priceSets.filter((p) => !!p).map((p) => p!.id) },
{
relations: ["rule_types", "money_amounts", "price_rules"],
relations: [
"rule_types",
"price_set_money_amounts.money_amount",
"price_rules",
],
},
sharedContext
)
@@ -538,7 +536,7 @@ export default class PricingModuleService<
return (await this.list(
{ id: input.map((d) => d.priceSetId) },
{ relations: ["money_amounts"] },
{ relations: ["price_set_money_amounts"] },
sharedContext
)) as unknown as PricingTypes.PriceSetDTO[] | PricingTypes.PriceSetDTO
}
@@ -713,73 +711,6 @@ export default class PricingModuleService<
)
}
@InjectTransactionManager("baseRepository_")
async createPriceSetMoneyAmountRules(
data: PricingTypes.CreatePriceSetMoneyAmountRulesDTO[],
@MedusaContext() sharedContext: Context = {}
): Promise<PricingTypes.PriceSetMoneyAmountRulesDTO[]> {
const records = await this.priceSetMoneyAmountRulesService_.create(
data,
sharedContext
)
return await this.baseRepository_.serialize<
PricingTypes.PriceSetMoneyAmountRulesDTO[]
>(records, {
populate: true,
})
}
@InjectTransactionManager("baseRepository_")
async updatePriceSetMoneyAmountRules(
data: PricingTypes.UpdatePriceSetMoneyAmountRulesDTO[],
@MedusaContext() sharedContext: Context = {}
): Promise<PricingTypes.PriceSetMoneyAmountRulesDTO[]> {
const records = await this.priceSetMoneyAmountRulesService_.update(
data,
sharedContext
)
return await this.baseRepository_.serialize<
PricingTypes.PriceSetMoneyAmountRulesDTO[]
>(records, {
populate: true,
})
}
@InjectTransactionManager("baseRepository_")
async createPriceRules(
data: PricingTypes.CreatePriceRuleDTO[],
@MedusaContext() sharedContext: Context = {}
): Promise<PricingTypes.PriceRuleDTO[]> {
const priceRules = await this.priceRuleService_.create(
data as ServiceTypes.CreatePriceRuleDTO[],
sharedContext
)
return await this.baseRepository_.serialize<PricingTypes.PriceRuleDTO[]>(
priceRules,
{
populate: true,
}
)
}
@InjectTransactionManager("baseRepository_")
async updatePriceRules(
data: PricingTypes.UpdatePriceRuleDTO[],
@MedusaContext() sharedContext: Context = {}
): Promise<PricingTypes.PriceRuleDTO[]> {
const priceRules = await this.priceRuleService_.update(data, sharedContext)
return await this.baseRepository_.serialize<PricingTypes.PriceRuleDTO[]>(
priceRules,
{
populate: true,
}
)
}
@InjectManager("baseRepository_")
async createPriceLists(
data: PricingTypes.CreatePriceListDTO[],
@@ -1,10 +1,9 @@
export * from "./money-amount"
export * from "./price-list-rule-value"
export * from "./price-list-rule"
export * from "./price-list"
export * from "./price-list-rule"
export * from "./price-list-rule-value"
export * from "./price-rule"
export * from "./price-set-money-amount-rules"
export * from "./price-set"
export * from "./price-set-money-amount"
export * from "./price-set-rule-type"
export * from "./price-set"
export * from "./rule-type"
@@ -1,12 +0,0 @@
export interface CreatePriceSetMoneyAmountRulesDTO {
price_set_money_amount: string
rule_type: string
value: string
}
export interface UpdatePriceSetMoneyAmountRulesDTO {
id: string
price_set_money_amount?: string
rule_type?: string
value?: string
}
+3 -4
View File
@@ -1,11 +1,10 @@
export * from "./money-amount"
export * from "./price-list-rule-value"
export * from "./price-list-rule"
export * from "./price-list"
export * from "./price-list-rule"
export * from "./price-list-rule-value"
export * from "./price-rule"
export * from "./price-set-money-amount-rules"
export * from "./price-set"
export * from "./price-set-money-amount"
export * from "./price-set-rule-type"
export * from "./price-set"
export * from "./pricing"
export * from "./rule-type"
@@ -1,33 +0,0 @@
import {
BaseFilterable,
PriceSetMoneyAmountDTO,
RuleTypeDTO,
} from "@medusajs/types"
export interface CreatePriceSetMoneyAmountRulesDTO {
price_set_money_amount: string
rule_type: string
value: string
}
export interface UpdatePriceSetMoneyAmountRulesDTO {
id: string
price_set_money_amount?: string
rule_type?: string
value?: string
}
export interface PriceSetMoneyAmountRulesDTO {
id: string
price_set_money_amount: PriceSetMoneyAmountDTO
rule_type: RuleTypeDTO
value: string
}
export interface FilterablePriceSetMoneyAmountRulesProps
extends BaseFilterable<FilterablePriceSetMoneyAmountRulesProps> {
id?: string[]
rule_type_id?: string[]
price_set_money_amount_id?: string[]
value?: string[]
}