Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
thetutlage committed Dec 9, 2024
1 parent abdd4c9 commit 9cd4e4c
Show file tree
Hide file tree
Showing 9 changed files with 569 additions and 444 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ moduleIntegrationTestRunner<ICustomerModuleService>({

expect(Object.keys(linkable)).toEqual([
"customerAddress",
"customerGroupCustomer",
"customerGroup",
"customer",
"customerGroup",
"customerGroupCustomer",
])

Object.keys(linkable).forEach((key) => {
Expand Down Expand Up @@ -704,7 +704,7 @@ moduleIntegrationTestRunner<ICustomerModuleService>({
expect(res.length).toBe(0)
})

it("should cascade relationship when deleting customer", async () => {
it.only("should cascade relationship when deleting customer", async () => {
// Creating a customer and a group
const customer = await service.createCustomers({
first_name: "John",
Expand Down
190 changes: 129 additions & 61 deletions packages/modules/customer/src/migrations/.snapshot-medusa-customer.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
{
"namespaces": ["public"],
"namespaces": [
"public"
],
"name": "public",
"tables": [
{
Expand Down Expand Up @@ -77,6 +79,15 @@
"nullable": true,
"mappedType": "json"
},
"created_by": {
"name": "created_by",
"type": "text",
"unsigned": false,
"autoincrement": false,
"primary": false,
"nullable": true,
"mappedType": "text"
},
"created_at": {
"name": "created_at",
"type": "timestamptz",
Expand Down Expand Up @@ -108,20 +119,19 @@
"nullable": true,
"length": 6,
"mappedType": "datetime"
},
"created_by": {
"name": "created_by",
"type": "text",
"unsigned": false,
"autoincrement": false,
"primary": false,
"nullable": true,
"mappedType": "text"
}
},
"name": "customer",
"schema": "public",
"indexes": [
{
"keyName": "IDX_customer_deleted_at",
"columnNames": [],
"composite": false,
"primary": false,
"unique": false,
"expression": "CREATE INDEX IF NOT EXISTS \"IDX_customer_deleted_at\" ON \"customer\" (deleted_at) WHERE deleted_at IS NULL"
},
{
"keyName": "IDX_customer_email_has_account_unique",
"columnNames": [],
Expand All @@ -132,7 +142,9 @@
},
{
"keyName": "customer_pkey",
"columnNames": ["id"],
"columnNames": [
"id"
],
"composite": false,
"primary": true,
"unique": true
Expand Down Expand Up @@ -181,15 +193,6 @@
"default": "false",
"mappedType": "boolean"
},
"customer_id": {
"name": "customer_id",
"type": "text",
"unsigned": false,
"autoincrement": false,
"primary": false,
"nullable": false,
"mappedType": "text"
},
"company": {
"name": "company",
"type": "text",
Expand Down Expand Up @@ -289,6 +292,15 @@
"nullable": true,
"mappedType": "json"
},
"customer_id": {
"name": "customer_id",
"type": "text",
"unsigned": false,
"autoincrement": false,
"primary": false,
"nullable": false,
"mappedType": "text"
},
"created_at": {
"name": "created_at",
"type": "timestamptz",
Expand All @@ -310,37 +322,58 @@
"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": "customer_address",
"schema": "public",
"indexes": [
{
"columnNames": ["customer_id"],
"composite": false,
"keyName": "IDX_customer_address_customer_id",
"columnNames": [],
"composite": false,
"primary": false,
"unique": false,
"expression": "CREATE INDEX IF NOT EXISTS \"IDX_customer_address_customer_id\" ON \"customer_address\" (customer_id) WHERE deleted_at IS NULL"
},
{
"keyName": "IDX_customer_address_deleted_at",
"columnNames": [],
"composite": false,
"primary": false,
"unique": false
"unique": false,
"expression": "CREATE INDEX IF NOT EXISTS \"IDX_customer_address_deleted_at\" ON \"customer_address\" (deleted_at) WHERE deleted_at IS NULL"
},
{
"keyName": "IDX_customer_address_unique_customer_billing",
"columnNames": [],
"composite": false,
"primary": false,
"unique": false,
"expression": "CREATE UNIQUE INDEX IF NOT EXISTS \"IDX_customer_address_unique_customer_billing\" ON \"customer_address\" (customer_id) WHERE \"is_default_billing\" = true"
"expression": "CREATE UNIQUE INDEX IF NOT EXISTS \"IDX_customer_address_unique_customer_billing\" ON \"customer_address\" (customer_id) WHERE \"is_default_billing\" = true AND deleted_at IS NULL"
},
{
"keyName": "IDX_customer_address_unique_customer_shipping",
"columnNames": [],
"composite": false,
"primary": false,
"unique": false,
"expression": "CREATE UNIQUE INDEX IF NOT EXISTS \"IDX_customer_address_unique_customer_shipping\" ON \"customer_address\" (customer_id) WHERE \"is_default_shipping\" = true"
"expression": "CREATE UNIQUE INDEX IF NOT EXISTS \"IDX_customer_address_unique_customer_shipping\" ON \"customer_address\" (customer_id) WHERE \"is_default_shipping\" = true AND deleted_at IS NULL"
},
{
"keyName": "customer_address_pkey",
"columnNames": ["id"],
"columnNames": [
"id"
],
"composite": false,
"primary": true,
"unique": true
Expand All @@ -350,9 +383,13 @@
"foreignKeys": {
"customer_address_customer_id_foreign": {
"constraintName": "customer_address_customer_id_foreign",
"columnNames": ["customer_id"],
"columnNames": [
"customer_id"
],
"localTableName": "public.customer_address",
"referencedColumnNames": ["id"],
"referencedColumnNames": [
"id"
],
"referencedTableName": "public.customer",
"deleteRule": "cascade",
"updateRule": "cascade"
Expand Down Expand Up @@ -433,17 +470,27 @@
"name": "customer_group",
"schema": "public",
"indexes": [
{
"keyName": "IDX_customer_group_deleted_at",
"columnNames": [],
"composite": false,
"primary": false,
"unique": false,
"expression": "CREATE INDEX IF NOT EXISTS \"IDX_customer_group_deleted_at\" ON \"customer_group\" (deleted_at) WHERE deleted_at IS NULL"
},
{
"keyName": "IDX_customer_group_name_unique",
"columnNames": ["name"],
"columnNames": [],
"composite": false,
"primary": false,
"unique": false,
"expression": "CREATE UNIQUE INDEX IF NOT EXISTS \"IDX_customer_group_name_unique\" ON \"customer_group\" (name) WHERE deleted_at IS NULL"
},
{
"keyName": "customer_group_pkey",
"columnNames": ["id"],
"columnNames": [
"id"
],
"composite": false,
"primary": true,
"unique": true
Expand All @@ -463,6 +510,15 @@
"nullable": false,
"mappedType": "text"
},
"metadata": {
"name": "metadata",
"type": "jsonb",
"unsigned": false,
"autoincrement": false,
"primary": false,
"nullable": true,
"mappedType": "json"
},
"customer_id": {
"name": "customer_id",
"type": "text",
Expand All @@ -481,15 +537,6 @@
"nullable": false,
"mappedType": "text"
},
"metadata": {
"name": "metadata",
"type": "jsonb",
"unsigned": false,
"autoincrement": false,
"primary": false,
"nullable": true,
"mappedType": "json"
},
"created_at": {
"name": "created_at",
"type": "timestamptz",
Expand All @@ -512,58 +559,79 @@
"default": "now()",
"mappedType": "datetime"
},
"created_by": {
"name": "created_by",
"type": "text",
"deleted_at": {
"name": "deleted_at",
"type": "timestamptz",
"unsigned": false,
"autoincrement": false,
"primary": false,
"nullable": true,
"mappedType": "text"
"length": 6,
"mappedType": "datetime"
}
},
"name": "customer_group_customer",
"schema": "public",
"indexes": [
{
"columnNames": ["customer_group_id"],
"keyName": "IDX_customer_group_customer_customer_id",
"columnNames": [],
"composite": false,
"keyName": "IDX_customer_group_customer_group_id",
"primary": false,
"unique": false
"unique": false,
"expression": "CREATE INDEX IF NOT EXISTS \"IDX_customer_group_customer_customer_id\" ON \"customer_group_customer\" (customer_id) WHERE deleted_at IS NULL"
},
{
"columnNames": ["customer_id"],
"keyName": "IDX_customer_group_customer_customer_group_id",
"columnNames": [],
"composite": false,
"primary": false,
"unique": false,
"expression": "CREATE INDEX IF NOT EXISTS \"IDX_customer_group_customer_customer_group_id\" ON \"customer_group_customer\" (customer_group_id) WHERE deleted_at IS NULL"
},
{
"keyName": "IDX_customer_group_customer_deleted_at",
"columnNames": [],
"composite": false,
"keyName": "IDX_customer_group_customer_customer_id",
"primary": false,
"unique": false
"unique": false,
"expression": "CREATE INDEX IF NOT EXISTS \"IDX_customer_group_customer_deleted_at\" ON \"customer_group_customer\" (deleted_at) WHERE deleted_at IS NULL"
},
{
"keyName": "customer_group_customer_pkey",
"columnNames": ["id"],
"columnNames": [
"id"
],
"composite": false,
"primary": true,
"unique": true
}
],
"checks": [],
"foreignKeys": {
"customer_group_customer_customer_group_id_foreign": {
"constraintName": "customer_group_customer_customer_group_id_foreign",
"columnNames": ["customer_group_id"],
"localTableName": "public.customer_group_customer",
"referencedColumnNames": ["id"],
"referencedTableName": "public.customer_group",
"deleteRule": "cascade"
},
"customer_group_customer_customer_id_foreign": {
"constraintName": "customer_group_customer_customer_id_foreign",
"columnNames": ["customer_id"],
"columnNames": [
"customer_id"
],
"localTableName": "public.customer_group_customer",
"referencedColumnNames": ["id"],
"referencedColumnNames": [
"id"
],
"referencedTableName": "public.customer",
"deleteRule": "cascade"
"updateRule": "cascade"
},
"customer_group_customer_customer_group_id_foreign": {
"constraintName": "customer_group_customer_customer_group_id_foreign",
"columnNames": [
"customer_group_id"
],
"localTableName": "public.customer_group_customer",
"referencedColumnNames": [
"id"
],
"referencedTableName": "public.customer_group",
"updateRule": "cascade"
}
}
}
Expand Down
Loading

0 comments on commit 9cd4e4c

Please sign in to comment.