@open-mercato/core 0.4.2-canary-15e78de280 → 0.4.2-canary-f075c3eb92

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (87) hide show
  1. package/dist/modules/api_keys/setup.js +11 -0
  2. package/dist/modules/api_keys/setup.js.map +7 -0
  3. package/dist/modules/attachments/components/AttachmentLibrary.js +1 -1
  4. package/dist/modules/attachments/components/AttachmentLibrary.js.map +2 -2
  5. package/dist/modules/attachments/lib/assignmentDetails.js +31 -17
  6. package/dist/modules/attachments/lib/assignmentDetails.js.map +2 -2
  7. package/dist/modules/attachments/lib/partitions.js +3 -3
  8. package/dist/modules/attachments/lib/partitions.js.map +2 -2
  9. package/dist/modules/attachments/setup.js +11 -0
  10. package/dist/modules/attachments/setup.js.map +7 -0
  11. package/dist/modules/audit_logs/setup.js +12 -0
  12. package/dist/modules/audit_logs/setup.js.map +7 -0
  13. package/dist/modules/auth/lib/setup-app.js +29 -159
  14. package/dist/modules/auth/lib/setup-app.js.map +2 -2
  15. package/dist/modules/auth/setup.js +11 -0
  16. package/dist/modules/auth/setup.js.map +7 -0
  17. package/dist/modules/business_rules/setup.js +11 -0
  18. package/dist/modules/business_rules/setup.js.map +7 -0
  19. package/dist/modules/catalog/setup.js +22 -0
  20. package/dist/modules/catalog/setup.js.map +7 -0
  21. package/dist/modules/configs/lib/upgrade-actions.js +65 -15
  22. package/dist/modules/configs/lib/upgrade-actions.js.map +2 -2
  23. package/dist/modules/configs/setup.js +16 -0
  24. package/dist/modules/configs/setup.js.map +7 -0
  25. package/dist/modules/currencies/setup.js +16 -0
  26. package/dist/modules/currencies/setup.js.map +7 -0
  27. package/dist/modules/customers/setup.js +36 -0
  28. package/dist/modules/customers/setup.js.map +7 -0
  29. package/dist/modules/dashboards/setup.js +12 -0
  30. package/dist/modules/dashboards/setup.js.map +7 -0
  31. package/dist/modules/dictionaries/setup.js +12 -0
  32. package/dist/modules/dictionaries/setup.js.map +7 -0
  33. package/dist/modules/directory/setup.js +12 -0
  34. package/dist/modules/directory/setup.js.map +7 -0
  35. package/dist/modules/entities/setup.js +11 -0
  36. package/dist/modules/entities/setup.js.map +7 -0
  37. package/dist/modules/feature_toggles/setup.js +11 -0
  38. package/dist/modules/feature_toggles/setup.js.map +7 -0
  39. package/dist/modules/perspectives/setup.js +12 -0
  40. package/dist/modules/perspectives/setup.js.map +7 -0
  41. package/dist/modules/planner/setup.js +21 -0
  42. package/dist/modules/planner/setup.js.map +7 -0
  43. package/dist/modules/query_index/setup.js +11 -0
  44. package/dist/modules/query_index/setup.js.map +7 -0
  45. package/dist/modules/resources/setup.js +21 -0
  46. package/dist/modules/resources/setup.js.map +7 -0
  47. package/dist/modules/sales/setup.js +99 -0
  48. package/dist/modules/sales/setup.js.map +7 -0
  49. package/dist/modules/staff/setup.js +27 -0
  50. package/dist/modules/staff/setup.js.map +7 -0
  51. package/dist/modules/workflows/lib/seeds.js +3 -15
  52. package/dist/modules/workflows/lib/seeds.js.map +2 -2
  53. package/dist/modules/workflows/migrations/Migration20251207131955.js +76 -72
  54. package/dist/modules/workflows/migrations/Migration20251207131955.js.map +2 -2
  55. package/dist/modules/workflows/setup.js +16 -0
  56. package/dist/modules/workflows/setup.js.map +7 -0
  57. package/package.json +2 -2
  58. package/src/__tests__/module-decoupling.test.ts +356 -0
  59. package/src/modules/api_keys/setup.ts +9 -0
  60. package/src/modules/attachments/components/AttachmentLibrary.tsx +2 -2
  61. package/src/modules/attachments/lib/assignmentDetails.ts +32 -16
  62. package/src/modules/attachments/lib/partitions.ts +3 -3
  63. package/src/modules/attachments/setup.ts +9 -0
  64. package/src/modules/audit_logs/setup.ts +10 -0
  65. package/src/modules/auth/__tests__/cli-setup-acl.test.ts +30 -0
  66. package/src/modules/auth/lib/setup-app.ts +40 -177
  67. package/src/modules/auth/setup.ts +9 -0
  68. package/src/modules/business_rules/setup.ts +9 -0
  69. package/src/modules/catalog/setup.ts +22 -0
  70. package/src/modules/configs/lib/upgrade-actions.ts +78 -17
  71. package/src/modules/configs/setup.ts +14 -0
  72. package/src/modules/currencies/setup.ts +15 -0
  73. package/src/modules/customers/setup.ts +36 -0
  74. package/src/modules/dashboards/setup.ts +10 -0
  75. package/src/modules/dictionaries/setup.ts +10 -0
  76. package/src/modules/directory/setup.ts +10 -0
  77. package/src/modules/entities/setup.ts +9 -0
  78. package/src/modules/feature_toggles/setup.ts +9 -0
  79. package/src/modules/perspectives/setup.ts +10 -0
  80. package/src/modules/planner/setup.ts +21 -0
  81. package/src/modules/query_index/setup.ts +9 -0
  82. package/src/modules/resources/setup.ts +21 -0
  83. package/src/modules/sales/setup.ts +108 -0
  84. package/src/modules/staff/setup.ts +27 -0
  85. package/src/modules/workflows/lib/seeds.ts +4 -16
  86. package/src/modules/workflows/migrations/Migration20251207131955.ts +77 -143
  87. package/src/modules/workflows/setup.ts +15 -0
@@ -0,0 +1,108 @@
1
+ import type { EntityManager } from '@mikro-orm/postgresql'
2
+ import type { ModuleSetupConfig } from '@open-mercato/shared/modules/setup'
3
+ import { SalesSettings, SalesDocumentSequence, SalesTaxRate } from './data/entities'
4
+ import { DEFAULT_ORDER_NUMBER_FORMAT, DEFAULT_QUOTE_NUMBER_FORMAT } from './lib/documentNumberTokens'
5
+ import { seedSalesStatusDictionaries, seedSalesAdjustmentKinds } from './lib/dictionaries'
6
+ import { ensureExampleShippingMethods, ensureExamplePaymentMethods } from './seed/examples-data'
7
+ import { seedSalesExamples } from './seed/examples'
8
+
9
+ type SeedScope = { tenantId: string; organizationId: string }
10
+
11
+ const DEFAULT_TAX_RATES = [
12
+ { code: 'vat-23', name: '23% VAT', rate: '23' },
13
+ { code: 'vat-0', name: '0% VAT', rate: '0' },
14
+ ] as const
15
+
16
+ async function seedSalesTaxRates(em: EntityManager, scope: SeedScope): Promise<void> {
17
+ await em.transactional(async (tem) => {
18
+ const existing = await tem.find(SalesTaxRate, {
19
+ tenantId: scope.tenantId,
20
+ organizationId: scope.organizationId,
21
+ deletedAt: null,
22
+ })
23
+ const existingCodes = new Set(existing.map((rate) => rate.code))
24
+ const hasDefault = existing.some((rate) => rate.isDefault)
25
+ const now = new Date()
26
+ let isFirst = !hasDefault
27
+
28
+ for (const seed of DEFAULT_TAX_RATES) {
29
+ if (existingCodes.has(seed.code)) continue
30
+ tem.persist(
31
+ tem.create(SalesTaxRate, {
32
+ tenantId: scope.tenantId,
33
+ organizationId: scope.organizationId,
34
+ code: seed.code,
35
+ name: seed.name,
36
+ rate: seed.rate,
37
+ priority: 0,
38
+ isCompound: false,
39
+ isDefault: isFirst,
40
+ createdAt: now,
41
+ updatedAt: now,
42
+ })
43
+ )
44
+ isFirst = false
45
+ }
46
+ })
47
+ }
48
+
49
+ export const setup: ModuleSetupConfig = {
50
+ defaultRoleFeatures: {
51
+ admin: ['sales.*'],
52
+ employee: ['sales.*'],
53
+ },
54
+
55
+ async onTenantCreated({ em, tenantId, organizationId }) {
56
+ const exists = await em.findOne(SalesSettings, { tenantId, organizationId })
57
+ if (!exists) {
58
+ em.persist(
59
+ em.create(SalesSettings, {
60
+ tenantId,
61
+ organizationId,
62
+ orderNumberFormat: DEFAULT_ORDER_NUMBER_FORMAT,
63
+ quoteNumberFormat: DEFAULT_QUOTE_NUMBER_FORMAT,
64
+ createdAt: new Date(),
65
+ updatedAt: new Date(),
66
+ })
67
+ )
68
+ }
69
+
70
+ for (const kind of ['order', 'quote'] as const) {
71
+ const seq = await em.findOne(SalesDocumentSequence, {
72
+ tenantId,
73
+ organizationId,
74
+ documentKind: kind,
75
+ })
76
+ if (!seq) {
77
+ em.persist(
78
+ em.create(SalesDocumentSequence, {
79
+ tenantId,
80
+ organizationId,
81
+ documentKind: kind,
82
+ currentValue: 0,
83
+ createdAt: new Date(),
84
+ updatedAt: new Date(),
85
+ })
86
+ )
87
+ }
88
+ }
89
+
90
+ await em.flush()
91
+ },
92
+
93
+ async seedDefaults({ em, tenantId, organizationId }) {
94
+ const scope = { tenantId, organizationId }
95
+ await seedSalesTaxRates(em, scope)
96
+ await seedSalesStatusDictionaries(em, scope)
97
+ await seedSalesAdjustmentKinds(em, scope)
98
+ await ensureExampleShippingMethods(em, scope)
99
+ await ensureExamplePaymentMethods(em, scope)
100
+ },
101
+
102
+ async seedExamples({ em, container, tenantId, organizationId }) {
103
+ const scope = { tenantId, organizationId }
104
+ await seedSalesExamples(em, container, scope)
105
+ },
106
+ }
107
+
108
+ export default setup
@@ -0,0 +1,27 @@
1
+ import type { ModuleSetupConfig } from '@open-mercato/shared/modules/setup'
2
+ import { seedStaffAddressTypes, seedStaffTeamExamples } from './lib/seeds'
3
+
4
+ export const setup: ModuleSetupConfig = {
5
+ seedDefaults: async (ctx) => {
6
+ const scope = { tenantId: ctx.tenantId, organizationId: ctx.organizationId }
7
+ await seedStaffAddressTypes(ctx.em, scope)
8
+ },
9
+
10
+ seedExamples: async (ctx) => {
11
+ const scope = { tenantId: ctx.tenantId, organizationId: ctx.organizationId }
12
+ await seedStaffTeamExamples(ctx.em, scope)
13
+ },
14
+
15
+ defaultRoleFeatures: {
16
+ admin: ['staff.*', 'staff.leave_requests.manage'],
17
+ employee: [
18
+ 'staff.leave_requests.send',
19
+ 'staff.my_availability.view',
20
+ 'staff.my_availability.manage',
21
+ 'staff.my_leave_requests.view',
22
+ 'staff.my_leave_requests.send',
23
+ ],
24
+ },
25
+ }
26
+
27
+ export default setup
@@ -1,12 +1,11 @@
1
1
  import type { EntityManager } from '@mikro-orm/postgresql'
2
2
  import * as fs from 'fs'
3
3
  import * as path from 'path'
4
+ import { fileURLToPath } from 'node:url'
4
5
  import { WorkflowDefinition, type WorkflowDefinitionData } from '../data/entities'
5
6
  import { BusinessRule, type RuleType } from '@open-mercato/core/modules/business_rules/data/entities'
6
- import checkoutDemoDefinition from '../examples/checkout-demo-definition.json'
7
- import guardRulesExample from '../examples/guard-rules-example.json'
8
- import salesPipelineDefinition from '../examples/sales-pipeline-definition.json'
9
- import simpleApprovalDefinition from '../examples/simple-approval-definition.json'
7
+
8
+ const __esmDirname = path.dirname(fileURLToPath(import.meta.url))
10
9
 
11
10
  export type WorkflowSeedScope = { tenantId: string; organizationId: string }
12
11
 
@@ -46,20 +45,9 @@ type GuardRuleSeed = {
46
45
  labelsJson?: Record<string, string>
47
46
  }
48
47
 
49
- const embeddedSeeds: Record<string, unknown> = {
50
- 'checkout-demo-definition.json': checkoutDemoDefinition,
51
- 'guard-rules-example.json': guardRulesExample,
52
- 'sales-pipeline-definition.json': salesPipelineDefinition,
53
- 'simple-approval-definition.json': simpleApprovalDefinition,
54
- }
55
-
56
48
  function readExampleJson<T>(fileName: string): T {
57
- const embedded = embeddedSeeds[fileName]
58
- if (embedded) {
59
- return embedded as T
60
- }
61
49
  const candidates = [
62
- path.join(__dirname, '..', 'examples', fileName),
50
+ path.join(__esmDirname, '..', 'examples', fileName),
63
51
  path.join(process.cwd(), 'packages', 'core', 'src', 'modules', 'workflows', 'examples', fileName),
64
52
  path.join(process.cwd(), 'src', 'modules', 'workflows', 'examples', fileName),
65
53
  ]
@@ -2,150 +2,84 @@ import { Migration } from '@mikro-orm/migrations';
2
2
 
3
3
  export class Migration20251207131955 extends Migration {
4
4
 
5
- override async up(): Promise<void> {
6
- this.addSql(`alter table "rule_execution_logs" drop constraint "rule_execution_logs_rule_id_foreign";`);
7
-
8
- this.addSql(`alter table "rule_set_members" drop constraint "rule_set_members_rule_id_foreign";`);
9
-
10
- this.addSql(`alter table "catalog_product_variant_prices" drop constraint "catalog_product_variant_prices_price_kind_id_foreign";`);
11
-
12
- this.addSql(`alter table "catalog_product_category_assignments" drop constraint "catalog_product_category_assignments_category_id_foreign";`);
13
-
14
- this.addSql(`alter table "catalog_product_variant_prices" drop constraint "catalog_product_variant_prices_offer_id_foreign";`);
15
-
16
- this.addSql(`alter table "catalog_products" drop constraint "catalog_products_option_schema_id_foreign";`);
17
-
18
- this.addSql(`alter table "catalog_product_tag_assignments" drop constraint "catalog_product_tag_assignments_tag_id_foreign";`);
19
-
20
- this.addSql(`alter table "catalog_product_variant_option_values" drop constraint "catalog_product_variant_option_values_variant_id_foreign";`);
21
-
22
- this.addSql(`alter table "catalog_product_variant_prices" drop constraint "catalog_product_variant_prices_variant_id_foreign";`);
23
-
24
- this.addSql(`alter table "catalog_product_variant_relations" drop constraint "catalog_product_variant_relations_child_variant_id_foreign";`);
25
-
26
- this.addSql(`alter table "catalog_product_variant_relations" drop constraint "catalog_product_variant_relations_parent_variant_id_foreign";`);
27
-
28
- this.addSql(`alter table "catalog_product_category_assignments" drop constraint "catalog_product_category_assignments_product_id_foreign";`);
29
-
30
- this.addSql(`alter table "catalog_product_offers" drop constraint "catalog_product_offers_product_id_foreign";`);
31
-
32
- this.addSql(`alter table "catalog_product_options" drop constraint "catalog_product_options_product_id_foreign";`);
33
-
34
- this.addSql(`alter table "catalog_product_relations" drop constraint "catalog_product_relations_child_product_id_foreign";`);
35
-
36
- this.addSql(`alter table "catalog_product_relations" drop constraint "catalog_product_relations_parent_product_id_foreign";`);
37
-
38
- this.addSql(`alter table "catalog_product_tag_assignments" drop constraint "catalog_product_tag_assignments_product_id_foreign";`);
39
-
40
- this.addSql(`alter table "catalog_product_variant_prices" drop constraint "catalog_product_variant_prices_product_id_foreign";`);
41
-
42
- this.addSql(`alter table "catalog_product_variants" drop constraint "catalog_product_variants_product_id_foreign";`);
43
-
44
- this.addSql(`alter table "customer_activities" drop constraint "customer_activities_deal_id_foreign";`);
45
-
46
- this.addSql(`alter table "customer_comments" drop constraint "customer_comments_deal_id_foreign";`);
47
-
48
- this.addSql(`alter table "customer_deal_companies" drop constraint "customer_deal_companies_deal_id_foreign";`);
49
-
50
- this.addSql(`alter table "customer_deal_people" drop constraint "customer_deal_people_deal_id_foreign";`);
51
-
52
- this.addSql(`alter table "customer_activities" drop constraint "customer_activities_entity_id_foreign";`);
53
-
54
- this.addSql(`alter table "customer_addresses" drop constraint "customer_addresses_entity_id_foreign";`);
55
-
56
- this.addSql(`alter table "customer_comments" drop constraint "customer_comments_entity_id_foreign";`);
57
-
58
- this.addSql(`alter table "customer_companies" drop constraint "customer_companies_entity_id_foreign";`);
59
-
60
- this.addSql(`alter table "customer_deal_companies" drop constraint "customer_deal_companies_company_entity_id_foreign";`);
61
-
62
- this.addSql(`alter table "customer_deal_people" drop constraint "customer_deal_people_person_entity_id_foreign";`);
63
-
64
- this.addSql(`alter table "customer_people" drop constraint "customer_people_company_entity_id_foreign";`);
65
-
66
- this.addSql(`alter table "customer_people" drop constraint "customer_people_entity_id_foreign";`);
67
-
68
- this.addSql(`alter table "customer_tag_assignments" drop constraint "customer_tag_assignments_entity_id_foreign";`);
69
-
70
- this.addSql(`alter table "customer_todo_links" drop constraint "customer_todo_links_entity_id_foreign";`);
71
-
72
- this.addSql(`alter table "customer_tag_assignments" drop constraint "customer_tag_assignments_tag_id_foreign";`);
73
-
74
- this.addSql(`alter table "dictionary_entries" drop constraint "dictionary_entries_dictionary_id_foreign";`);
75
-
76
- this.addSql(`alter table "role_acls" drop constraint "role_acls_role_id_foreign";`);
77
-
78
- this.addSql(`alter table "role_sidebar_preferences" drop constraint "role_sidebar_preferences_role_id_foreign";`);
79
-
80
- this.addSql(`alter table "user_roles" drop constraint "user_roles_role_id_foreign";`);
81
-
82
- this.addSql(`alter table "rule_set_members" drop constraint "rule_set_members_rule_set_id_foreign";`);
83
-
84
- this.addSql(`alter table "sales_orders" drop constraint "sales_orders_channel_ref_id_foreign";`);
85
-
86
- this.addSql(`alter table "sales_credit_memo_lines" drop constraint "sales_credit_memo_lines_credit_memo_id_foreign";`);
87
-
88
- this.addSql(`alter table "sales_orders" drop constraint "sales_orders_delivery_window_ref_id_foreign";`);
89
-
90
- this.addSql(`alter table "sales_credit_memos" drop constraint "sales_credit_memos_invoice_id_foreign";`);
91
-
92
- this.addSql(`alter table "sales_invoice_lines" drop constraint "sales_invoice_lines_invoice_id_foreign";`);
93
-
94
- this.addSql(`alter table "sales_payment_allocations" drop constraint "sales_payment_allocations_invoice_id_foreign";`);
95
-
96
- this.addSql(`alter table "sales_credit_memo_lines" drop constraint "sales_credit_memo_lines_order_line_id_foreign";`);
97
-
98
- this.addSql(`alter table "sales_invoice_lines" drop constraint "sales_invoice_lines_order_line_id_foreign";`);
99
-
100
- this.addSql(`alter table "sales_order_adjustments" drop constraint "sales_order_adjustments_order_line_id_foreign";`);
101
-
102
- this.addSql(`alter table "sales_shipment_items" drop constraint "sales_shipment_items_order_line_id_foreign";`);
103
-
104
- this.addSql(`alter table "sales_credit_memos" drop constraint "sales_credit_memos_order_id_foreign";`);
105
-
106
- this.addSql(`alter table "sales_invoices" drop constraint "sales_invoices_order_id_foreign";`);
107
-
108
- this.addSql(`alter table "sales_notes" drop constraint "sales_notes_order_id_foreign";`);
109
-
110
- this.addSql(`alter table "sales_order_adjustments" drop constraint "sales_order_adjustments_order_id_foreign";`);
111
-
112
- this.addSql(`alter table "sales_order_lines" drop constraint "sales_order_lines_order_id_foreign";`);
113
-
114
- this.addSql(`alter table "sales_payment_allocations" drop constraint "sales_payment_allocations_order_id_foreign";`);
115
-
116
- this.addSql(`alter table "sales_payments" drop constraint "sales_payments_order_id_foreign";`);
117
-
118
- this.addSql(`alter table "sales_shipments" drop constraint "sales_shipments_order_id_foreign";`);
119
-
120
- this.addSql(`alter table "sales_orders" drop constraint "sales_orders_payment_method_ref_id_foreign";`);
121
-
122
- this.addSql(`alter table "sales_payments" drop constraint "sales_payments_payment_method_id_foreign";`);
123
-
124
- this.addSql(`alter table "sales_payment_allocations" drop constraint "sales_payment_allocations_payment_id_foreign";`);
125
-
126
- this.addSql(`alter table "sales_quote_adjustments" drop constraint "sales_quote_adjustments_quote_line_id_foreign";`);
127
-
128
- this.addSql(`alter table "sales_notes" drop constraint "sales_notes_quote_id_foreign";`);
129
-
130
- this.addSql(`alter table "sales_quote_adjustments" drop constraint "sales_quote_adjustments_quote_id_foreign";`);
131
-
132
- this.addSql(`alter table "sales_quote_lines" drop constraint "sales_quote_lines_quote_id_foreign";`);
133
-
134
- this.addSql(`alter table "sales_shipment_items" drop constraint "sales_shipment_items_shipment_id_foreign";`);
135
-
136
- this.addSql(`alter table "sales_orders" drop constraint "sales_orders_shipping_method_ref_id_foreign";`);
137
-
138
- this.addSql(`alter table "organizations" drop constraint "organizations_tenant_id_foreign";`);
139
-
140
- this.addSql(`alter table "password_resets" drop constraint "password_resets_user_id_foreign";`);
141
-
142
- this.addSql(`alter table "sessions" drop constraint "sessions_user_id_foreign";`);
143
-
144
- this.addSql(`alter table "user_acls" drop constraint "user_acls_user_id_foreign";`);
145
-
146
- this.addSql(`alter table "user_roles" drop constraint "user_roles_user_id_foreign";`);
5
+ /** Drop a foreign key constraint only when the owning table exists (safe for disabled modules). */
6
+ private dropConstraintIfTableExists(table: string, constraint: string): void {
7
+ this.addSql(`DO $$ BEGIN IF EXISTS (SELECT 1 FROM information_schema.tables WHERE table_name = '${table}') THEN ALTER TABLE "${table}" DROP CONSTRAINT IF EXISTS "${constraint}"; END IF; END $$;`)
8
+ }
147
9
 
148
- this.addSql(`alter table "user_sidebar_preferences" drop constraint "user_sidebar_preferences_user_id_foreign";`);
10
+ override async up(): Promise<void> {
11
+ this.dropConstraintIfTableExists('rule_execution_logs', 'rule_execution_logs_rule_id_foreign');
12
+ this.dropConstraintIfTableExists('rule_set_members', 'rule_set_members_rule_id_foreign');
13
+ this.dropConstraintIfTableExists('catalog_product_variant_prices', 'catalog_product_variant_prices_price_kind_id_foreign');
14
+ this.dropConstraintIfTableExists('catalog_product_category_assignments', 'catalog_product_category_assignments_category_id_foreign');
15
+ this.dropConstraintIfTableExists('catalog_product_variant_prices', 'catalog_product_variant_prices_offer_id_foreign');
16
+ this.dropConstraintIfTableExists('catalog_products', 'catalog_products_option_schema_id_foreign');
17
+ this.dropConstraintIfTableExists('catalog_product_tag_assignments', 'catalog_product_tag_assignments_tag_id_foreign');
18
+ this.dropConstraintIfTableExists('catalog_product_variant_option_values', 'catalog_product_variant_option_values_variant_id_foreign');
19
+ this.dropConstraintIfTableExists('catalog_product_variant_prices', 'catalog_product_variant_prices_variant_id_foreign');
20
+ this.dropConstraintIfTableExists('catalog_product_variant_relations', 'catalog_product_variant_relations_child_variant_id_foreign');
21
+ this.dropConstraintIfTableExists('catalog_product_variant_relations', 'catalog_product_variant_relations_parent_variant_id_foreign');
22
+ this.dropConstraintIfTableExists('catalog_product_category_assignments', 'catalog_product_category_assignments_product_id_foreign');
23
+ this.dropConstraintIfTableExists('catalog_product_offers', 'catalog_product_offers_product_id_foreign');
24
+ this.dropConstraintIfTableExists('catalog_product_options', 'catalog_product_options_product_id_foreign');
25
+ this.dropConstraintIfTableExists('catalog_product_relations', 'catalog_product_relations_child_product_id_foreign');
26
+ this.dropConstraintIfTableExists('catalog_product_relations', 'catalog_product_relations_parent_product_id_foreign');
27
+ this.dropConstraintIfTableExists('catalog_product_tag_assignments', 'catalog_product_tag_assignments_product_id_foreign');
28
+ this.dropConstraintIfTableExists('catalog_product_variant_prices', 'catalog_product_variant_prices_product_id_foreign');
29
+ this.dropConstraintIfTableExists('catalog_product_variants', 'catalog_product_variants_product_id_foreign');
30
+ this.dropConstraintIfTableExists('customer_activities', 'customer_activities_deal_id_foreign');
31
+ this.dropConstraintIfTableExists('customer_comments', 'customer_comments_deal_id_foreign');
32
+ this.dropConstraintIfTableExists('customer_deal_companies', 'customer_deal_companies_deal_id_foreign');
33
+ this.dropConstraintIfTableExists('customer_deal_people', 'customer_deal_people_deal_id_foreign');
34
+ this.dropConstraintIfTableExists('customer_activities', 'customer_activities_entity_id_foreign');
35
+ this.dropConstraintIfTableExists('customer_addresses', 'customer_addresses_entity_id_foreign');
36
+ this.dropConstraintIfTableExists('customer_comments', 'customer_comments_entity_id_foreign');
37
+ this.dropConstraintIfTableExists('customer_companies', 'customer_companies_entity_id_foreign');
38
+ this.dropConstraintIfTableExists('customer_deal_companies', 'customer_deal_companies_company_entity_id_foreign');
39
+ this.dropConstraintIfTableExists('customer_deal_people', 'customer_deal_people_person_entity_id_foreign');
40
+ this.dropConstraintIfTableExists('customer_people', 'customer_people_company_entity_id_foreign');
41
+ this.dropConstraintIfTableExists('customer_people', 'customer_people_entity_id_foreign');
42
+ this.dropConstraintIfTableExists('customer_tag_assignments', 'customer_tag_assignments_entity_id_foreign');
43
+ this.dropConstraintIfTableExists('customer_todo_links', 'customer_todo_links_entity_id_foreign');
44
+ this.dropConstraintIfTableExists('customer_tag_assignments', 'customer_tag_assignments_tag_id_foreign');
45
+ this.dropConstraintIfTableExists('dictionary_entries', 'dictionary_entries_dictionary_id_foreign');
46
+ this.dropConstraintIfTableExists('role_acls', 'role_acls_role_id_foreign');
47
+ this.dropConstraintIfTableExists('role_sidebar_preferences', 'role_sidebar_preferences_role_id_foreign');
48
+ this.dropConstraintIfTableExists('user_roles', 'user_roles_role_id_foreign');
49
+ this.dropConstraintIfTableExists('rule_set_members', 'rule_set_members_rule_set_id_foreign');
50
+ this.dropConstraintIfTableExists('sales_orders', 'sales_orders_channel_ref_id_foreign');
51
+ this.dropConstraintIfTableExists('sales_credit_memo_lines', 'sales_credit_memo_lines_credit_memo_id_foreign');
52
+ this.dropConstraintIfTableExists('sales_orders', 'sales_orders_delivery_window_ref_id_foreign');
53
+ this.dropConstraintIfTableExists('sales_credit_memos', 'sales_credit_memos_invoice_id_foreign');
54
+ this.dropConstraintIfTableExists('sales_invoice_lines', 'sales_invoice_lines_invoice_id_foreign');
55
+ this.dropConstraintIfTableExists('sales_payment_allocations', 'sales_payment_allocations_invoice_id_foreign');
56
+ this.dropConstraintIfTableExists('sales_credit_memo_lines', 'sales_credit_memo_lines_order_line_id_foreign');
57
+ this.dropConstraintIfTableExists('sales_invoice_lines', 'sales_invoice_lines_order_line_id_foreign');
58
+ this.dropConstraintIfTableExists('sales_order_adjustments', 'sales_order_adjustments_order_line_id_foreign');
59
+ this.dropConstraintIfTableExists('sales_shipment_items', 'sales_shipment_items_order_line_id_foreign');
60
+ this.dropConstraintIfTableExists('sales_credit_memos', 'sales_credit_memos_order_id_foreign');
61
+ this.dropConstraintIfTableExists('sales_invoices', 'sales_invoices_order_id_foreign');
62
+ this.dropConstraintIfTableExists('sales_notes', 'sales_notes_order_id_foreign');
63
+ this.dropConstraintIfTableExists('sales_order_adjustments', 'sales_order_adjustments_order_id_foreign');
64
+ this.dropConstraintIfTableExists('sales_order_lines', 'sales_order_lines_order_id_foreign');
65
+ this.dropConstraintIfTableExists('sales_payment_allocations', 'sales_payment_allocations_order_id_foreign');
66
+ this.dropConstraintIfTableExists('sales_payments', 'sales_payments_order_id_foreign');
67
+ this.dropConstraintIfTableExists('sales_shipments', 'sales_shipments_order_id_foreign');
68
+ this.dropConstraintIfTableExists('sales_orders', 'sales_orders_payment_method_ref_id_foreign');
69
+ this.dropConstraintIfTableExists('sales_payments', 'sales_payments_payment_method_id_foreign');
70
+ this.dropConstraintIfTableExists('sales_payment_allocations', 'sales_payment_allocations_payment_id_foreign');
71
+ this.dropConstraintIfTableExists('sales_quote_adjustments', 'sales_quote_adjustments_quote_line_id_foreign');
72
+ this.dropConstraintIfTableExists('sales_notes', 'sales_notes_quote_id_foreign');
73
+ this.dropConstraintIfTableExists('sales_quote_adjustments', 'sales_quote_adjustments_quote_id_foreign');
74
+ this.dropConstraintIfTableExists('sales_quote_lines', 'sales_quote_lines_quote_id_foreign');
75
+ this.dropConstraintIfTableExists('sales_shipment_items', 'sales_shipment_items_shipment_id_foreign');
76
+ this.dropConstraintIfTableExists('sales_orders', 'sales_orders_shipping_method_ref_id_foreign');
77
+ this.dropConstraintIfTableExists('organizations', 'organizations_tenant_id_foreign');
78
+ this.dropConstraintIfTableExists('password_resets', 'password_resets_user_id_foreign');
79
+ this.dropConstraintIfTableExists('sessions', 'sessions_user_id_foreign');
80
+ this.dropConstraintIfTableExists('user_acls', 'user_acls_user_id_foreign');
81
+ this.dropConstraintIfTableExists('user_roles', 'user_roles_user_id_foreign');
82
+ this.dropConstraintIfTableExists('user_sidebar_preferences', 'user_sidebar_preferences_user_id_foreign');
149
83
 
150
84
  this.addSql(`create table "step_instances" ("id" uuid not null default gen_random_uuid(), "workflow_instance_id" uuid not null, "step_id" varchar(100) not null, "step_name" varchar(255) not null, "step_type" varchar(50) not null, "status" varchar(20) not null, "input_data" jsonb null, "output_data" jsonb null, "error_data" jsonb null, "entered_at" timestamptz null, "exited_at" timestamptz null, "execution_time_ms" int null, "retry_count" int not null default 0, "tenant_id" uuid not null, "organization_id" uuid not null, "created_at" timestamptz not null, "updated_at" timestamptz not null, constraint "step_instances_pkey" primary key ("id"));`);
151
85
  this.addSql(`create index "step_instances_tenant_org_idx" on "step_instances" ("tenant_id", "organization_id");`);
@@ -0,0 +1,15 @@
1
+ import type { ModuleSetupConfig } from '@open-mercato/shared/modules/setup'
2
+ import { seedExampleWorkflows } from './lib/seeds'
3
+
4
+ export const setup: ModuleSetupConfig = {
5
+ seedDefaults: async (ctx) => {
6
+ const scope = { tenantId: ctx.tenantId, organizationId: ctx.organizationId }
7
+ await seedExampleWorkflows(ctx.em, scope)
8
+ },
9
+
10
+ defaultRoleFeatures: {
11
+ admin: ['workflows.*'],
12
+ },
13
+ }
14
+
15
+ export default setup