nextjs-cms 0.8.3 → 0.8.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.
@@ -1 +1 @@
1
- {"version":3,"file":"update-sections.d.ts","sourceRoot":"","sources":["../../../src/cli/lib/update-sections.ts"],"names":[],"mappings":"AAolCA,wBAAsB,cAAc,CAAC,SAAS,UAAQ,iBAoBrD"}
1
+ {"version":3,"file":"update-sections.d.ts","sourceRoot":"","sources":["../../../src/cli/lib/update-sections.ts"],"names":[],"mappings":"AA8lCA,wBAAsB,cAAc,CAAC,SAAS,UAAQ,iBAoBrD"}
@@ -557,10 +557,20 @@ const main = async (s) => {
557
557
  /**
558
558
  * Generate the Drizzle schema for the table
559
559
  */
560
+ // Filter out unique constraints that exactly match the primary key columns,
561
+ // since primary keys already enforce uniqueness
562
+ const pkNames = new Set(s.db.primaryKey.map((f) => f.name));
563
+ const schemaUniqueConstraints = s.db.unique?.filter((u) => {
564
+ if (u.columns.length !== pkNames.size)
565
+ return true;
566
+ return !u.columns.every((c) => pkNames.has(c.name));
567
+ });
560
568
  const drizzleSchema = generateDrizzleSchema({
561
569
  name: s.db.table,
562
570
  fields: s.fieldConfigs,
563
571
  identifier: s.db.identifier,
572
+ index: s.db.index,
573
+ unique: schemaUniqueConstraints?.length ? schemaUniqueConstraints : undefined,
564
574
  }, caseStyleFns);
565
575
  drizzleTableSchemas.push(drizzleSchema.schema);
566
576
  drizzleSchema.drizzleImports.forEach((type) => drizzleImports.add(type));
@@ -19,6 +19,24 @@ export declare function generateDrizzleSchema(table: {
19
19
  compositePrimaryKey?: {
20
20
  name: string;
21
21
  }[];
22
+ index?: {
23
+ columns: {
24
+ name: string;
25
+ }[];
26
+ name?: string;
27
+ }[];
28
+ unique?: {
29
+ columns: {
30
+ name: string;
31
+ }[];
32
+ name?: string;
33
+ }[];
34
+ fulltext?: {
35
+ columns: {
36
+ name: string;
37
+ }[];
38
+ name?: string;
39
+ }[];
22
40
  }, caseStyleFns: CaseStyleFns): {
23
41
  schema: string;
24
42
  drizzleImports: string[];
@@ -1 +1 @@
1
- {"version":3,"file":"schema-generator.d.ts","sourceRoot":"","sources":["../../../src/cli/utils/schema-generator.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,4BAA4B,CAAA;AAoB7D,MAAM,WAAW,YAAY;IACzB,gBAAgB,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,MAAM,CAAA;IACzC,iBAAiB,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,MAAM,CAAA;CAC7C;AAED,MAAM,WAAW,YAAY;IACzB,MAAM,EAAE,WAAW,GAAG,WAAW,GAAG,YAAY,CAAA;IAChD,OAAO,EAAE,WAAW,GAAG,WAAW,GAAG,YAAY,CAAA;CACpD;AAED;;;GAGG;AACH,wBAAgB,mBAAmB,CAAC,MAAM,EAAE,YAAY,GAAG,YAAY,CA8BtE;AAED,wBAAgB,qBAAqB,CACjC,KAAK,EAAE;IACH,IAAI,EAAE,MAAM,CAAA;IACZ,MAAM,EAAE,WAAW,EAAE,CAAA;IACrB,UAAU,CAAC,EAAE,WAAW,CAAA;IACxB,mBAAmB,CAAC,EAAE;QAAE,IAAI,EAAE,MAAM,CAAA;KAAE,EAAE,CAAA;CAC3C,EACD,YAAY,EAAE,YAAY,GAC3B;IACC,MAAM,EAAE,MAAM,CAAA;IACd,cAAc,EAAE,MAAM,EAAE,CAAA;CAC3B,CAwIA"}
1
+ {"version":3,"file":"schema-generator.d.ts","sourceRoot":"","sources":["../../../src/cli/utils/schema-generator.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,4BAA4B,CAAA;AAoB7D,MAAM,WAAW,YAAY;IACzB,gBAAgB,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,MAAM,CAAA;IACzC,iBAAiB,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,MAAM,CAAA;CAC7C;AAED,MAAM,WAAW,YAAY;IACzB,MAAM,EAAE,WAAW,GAAG,WAAW,GAAG,YAAY,CAAA;IAChD,OAAO,EAAE,WAAW,GAAG,WAAW,GAAG,YAAY,CAAA;CACpD;AAED;;;GAGG;AACH,wBAAgB,mBAAmB,CAAC,MAAM,EAAE,YAAY,GAAG,YAAY,CA8BtE;AAED,wBAAgB,qBAAqB,CACjC,KAAK,EAAE;IACH,IAAI,EAAE,MAAM,CAAA;IACZ,MAAM,EAAE,WAAW,EAAE,CAAA;IACrB,UAAU,CAAC,EAAE,WAAW,CAAA;IACxB,mBAAmB,CAAC,EAAE;QAAE,IAAI,EAAE,MAAM,CAAA;KAAE,EAAE,CAAA;IACxC,KAAK,CAAC,EAAE;QAAE,OAAO,EAAE;YAAE,IAAI,EAAE,MAAM,CAAA;SAAE,EAAE,CAAC;QAAC,IAAI,CAAC,EAAE,MAAM,CAAA;KAAE,EAAE,CAAA;IACxD,MAAM,CAAC,EAAE;QAAE,OAAO,EAAE;YAAE,IAAI,EAAE,MAAM,CAAA;SAAE,EAAE,CAAC;QAAC,IAAI,CAAC,EAAE,MAAM,CAAA;KAAE,EAAE,CAAA;IACzD,QAAQ,CAAC,EAAE;QAAE,OAAO,EAAE;YAAE,IAAI,EAAE,MAAM,CAAA;SAAE,EAAE,CAAC;QAAC,IAAI,CAAC,EAAE,MAAM,CAAA;KAAE,EAAE,CAAA;CAC9D,EACD,YAAY,EAAE,YAAY,GAC3B;IACC,MAAM,EAAE,MAAM,CAAA;IACd,cAAc,EAAE,MAAM,EAAE,CAAA;CAC3B,CA2KA"}
@@ -157,13 +157,43 @@ export function generateDrizzleSchema(table, caseStyleFns) {
157
157
  }
158
158
  }
159
159
  schema = schema.slice(0, -2); // Remove the last comma and newline
160
+ // Collect all table callback entries (constraints and indexes)
161
+ const callbackEntries = [];
162
+ // Composite primary key
160
163
  if (table.compositePrimaryKey && table.compositePrimaryKey.length > 1) {
161
164
  const pkCols = table.compositePrimaryKey.map((f) => `table.${columnCaseStyleFn(f.name)}`).join(', ');
162
- schema += `\n}, (table) => [primaryKey({ columns: [${pkCols}] })]);\n\n`;
165
+ callbackEntries.push(`primaryKey({ columns: [${pkCols}] })`);
163
166
  if (!drizzleImports.includes('primaryKey')) {
164
167
  drizzleImports.push('primaryKey');
165
168
  }
166
169
  }
170
+ // Indexes
171
+ if (table.index?.length) {
172
+ for (const idx of table.index) {
173
+ const cols = idx.columns.map((c) => `table.${columnCaseStyleFn(c.name)}`).join(', ');
174
+ const name = idx.name ?? `${table.name}_${idx.columns.map((c) => c.name).join('_')}_idx`;
175
+ callbackEntries.push(`index('${name}').on(${cols})`);
176
+ }
177
+ if (!drizzleImports.includes('index')) {
178
+ drizzleImports.push('index');
179
+ }
180
+ }
181
+ // Unique constraints
182
+ if (table.unique?.length) {
183
+ for (const uniq of table.unique) {
184
+ const cols = uniq.columns.map((c) => `table.${columnCaseStyleFn(c.name)}`).join(', ');
185
+ const name = uniq.name ?? `${table.name}_${uniq.columns.map((c) => c.name).join('_')}_unique`;
186
+ callbackEntries.push(`unique('${name}').on(${cols})`);
187
+ }
188
+ if (!drizzleImports.includes('unique')) {
189
+ drizzleImports.push('unique');
190
+ }
191
+ }
192
+ // Fulltext indexes (Drizzle doesn't have a native fulltext helper, so we use index with a comment)
193
+ // These are still applied to the database via raw SQL in addTableKeys()
194
+ if (callbackEntries.length > 0) {
195
+ schema += `\n}, (table) => [\n${callbackEntries.map((e) => ` ${e}`).join(',\n')}\n]);\n\n`;
196
+ }
167
197
  else {
168
198
  schema += `\n});\n\n`;
169
199
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nextjs-cms",
3
- "version": "0.8.3",
3
+ "version": "0.8.5",
4
4
  "main": "./dist/index.js",
5
5
  "types": "./dist/index.d.ts",
6
6
  "type": "module",
@@ -202,8 +202,8 @@
202
202
  "tsx": "^4.20.6",
203
203
  "typescript": "^5.9.2",
204
204
  "@lzcms/eslint-config": "0.3.0",
205
- "@lzcms/tsconfig": "0.1.0",
206
- "@lzcms/prettier-config": "0.1.0"
205
+ "@lzcms/prettier-config": "0.1.0",
206
+ "@lzcms/tsconfig": "0.1.0"
207
207
  },
208
208
  "license": "MIT",
209
209
  "keywords": [