@pattern-stack/codegen 0.7.4 → 0.7.5
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.
package/package.json
CHANGED
|
@@ -45,8 +45,10 @@ export const <%= tableVarName %> = pgTable(
|
|
|
45
45
|
<%= rightColumnCamel %>: uuid('<%= rightColumn %>').notNull().references(() => <%= rightTable %>.id, { onDelete: '<%= onDeleteRight %>' }),
|
|
46
46
|
<%_ if (hasRole) { _%>
|
|
47
47
|
|
|
48
|
-
// Role enum (per-pairing; declared in junction YAML's fields.role.choices)
|
|
49
|
-
role
|
|
48
|
+
// Role enum (per-pairing; declared in junction YAML's fields.role.choices).
|
|
49
|
+
// NOT NULL because role is part of the junction's identity (composite PK
|
|
50
|
+
// below): the same pair with two different roles is two distinct rows.
|
|
51
|
+
role: <%= roleEnumName %>('role').notNull(),
|
|
50
52
|
<%_ } _%>
|
|
51
53
|
|
|
52
54
|
// BaseJunctionFields — is_primary is always emitted
|
|
@@ -83,8 +85,17 @@ export const <%= tableVarName %> = pgTable(
|
|
|
83
85
|
updatedAt: timestamp('updated_at').notNull().defaultNow(),
|
|
84
86
|
},
|
|
85
87
|
(table) => [
|
|
88
|
+
<%_ if (hasRole) { _%>
|
|
89
|
+
// Composite primary key on the two FK columns PLUS role (Q4 resolution: no
|
|
90
|
+
// surrogate id). Role is part of the junction's identity — the same pair
|
|
91
|
+
// with two different roles is two distinct rows (e.g. a contact who is both
|
|
92
|
+
// `champion` and `decision_maker` on one opportunity). This is the
|
|
93
|
+
// ON CONFLICT target for syncUpsert on role-bearing junctions.
|
|
94
|
+
primaryKey({ columns: [table.<%= leftColumnCamel %>, table.<%= rightColumnCamel %>, table.role] }),
|
|
95
|
+
<%_ } else { _%>
|
|
86
96
|
// Composite primary key on the two FK columns (Q4 resolution: no surrogate id)
|
|
87
97
|
primaryKey({ columns: [table.<%= leftColumnCamel %>, table.<%= rightColumnCamel %>] }),
|
|
98
|
+
<%_ } _%>
|
|
88
99
|
],
|
|
89
100
|
);
|
|
90
101
|
|