nextjs-cms 0.9.10 → 0.9.12

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":"AA+xCA,wBAAsB,cAAc,CAAC,SAAS,UAAQ,iBAoBrD"}
1
+ {"version":3,"file":"update-sections.d.ts","sourceRoot":"","sources":["../../../src/cli/lib/update-sections.ts"],"names":[],"mappings":"AAkyCA,wBAAsB,cAAc,CAAC,SAAS,UAAQ,iBAoBrD"}
@@ -13,6 +13,17 @@ import { intro, select, spinner, log } from '@clack/prompts';
13
13
  import { MysqlTableChecker } from '../../core/db/index.js';
14
14
  import { generateDrizzleSchema, generateLocalesTableSchema, resolveCaseStyleFns } from '../utils/schema-generator.js';
15
15
  import { addTableKeys } from '../utils/add-table-keys.js';
16
+ /**
17
+ * Returns all DB column names a field owns.
18
+ * Most fields own a single column (field.name), but rarely some fields own two,
19
+ * like DateRangeField (startName, endName).
20
+ */
21
+ function getFieldColumnName(field) {
22
+ if (is(field, DateRangeField)) {
23
+ return [field.startName, field.endName];
24
+ }
25
+ return [field.name];
26
+ }
16
27
  function generateFieldSQL(input) {
17
28
  /**
18
29
  * DateRangeField emits two columns — one for startName, one for endName.
@@ -322,21 +333,21 @@ async function updateTable(table, s) {
322
333
  * Filter out the fields that already exist in the table
323
334
  */
324
335
  const existingFields = existingFieldsData ? Object.keys(existingFieldsData) : [];
325
- const fieldsToAdd = table.fields.filter((field) => !existingFields.some((existingField) => existingField === field.name));
336
+ const fieldsToAdd = table.fields.filter((field) => !getFieldColumnName(field).some((col) => existingFields.includes(col)));
326
337
  /**
327
338
  * Let's find out fields that need to be updated.
328
339
  * If a field exists in both the desired fields and the existing fields, we should mark it for update.
329
340
  * TODO: Actually, we should check if the field needs to be updated, and only update if necessary. (INFORMATION_SCHEMA will help)
330
341
  */
331
- const fieldsToUpdate = table.fields.filter((field) => existingFields.some((existingField) => existingField === field.name));
342
+ const fieldsToUpdate = table.fields.filter((field) => getFieldColumnName(field).some((col) => existingFields.includes(col)));
332
343
  /**
333
344
  * Let's find out fields to remove as well.
334
345
  * If a field exists in the table but not in the desired fields,
335
346
  * or if it has a destinationDb, TODO: Add the values to the destination table? (CRITICAL! Loss of data if not done)
336
347
  * we should mark it for removal.
337
348
  */
338
- let fieldsToRemove = existingFields.filter((existingField) => !table.fields.some((field) => field.name === existingField) ||
339
- table.fields.some((field) => field.destinationDb && field.name === existingField));
349
+ let fieldsToRemove = existingFields.filter((existingField) => !table.fields.some((field) => getFieldColumnName(field).includes(existingField)) ||
350
+ table.fields.some((field) => field.destinationDb && getFieldColumnName(field).includes(existingField)));
340
351
  /**
341
352
  * Check if there are fields to update
342
353
  */
@@ -350,22 +361,15 @@ async function updateTable(table, s) {
350
361
  // and data may be lost! (e.g. changing a field from VARCHAR to INT)
351
362
  if (field.destinationDb)
352
363
  continue;
353
- let fieldSQL = generateFieldSQL(field);
354
- /**
355
- * Check if the field is a primary key
356
- */
357
- if (field.name === table.identifier?.name) {
358
- fieldSQL += ' FIRST';
364
+ const fieldSQLResult = [generateFieldSQL(field)].flat();
365
+ for (const fieldSQL of fieldSQLResult) {
366
+ alterTableSQLs.push({
367
+ field: field.name,
368
+ table: table.name,
369
+ action: 'modify',
370
+ sql: `MODIFY COLUMN ${fieldSQL}`,
371
+ });
359
372
  }
360
- /**
361
- * Add the SQL to modify the field
362
- */
363
- alterTableSQLs.push({
364
- field: field.name,
365
- table: table.name,
366
- action: 'modify',
367
- sql: `MODIFY COLUMN ${fieldSQL}`,
368
- });
369
373
  }
370
374
  }
371
375
  /**
@@ -378,13 +382,8 @@ async function updateTable(table, s) {
378
382
  for (const field of fieldsToAdd) {
379
383
  if (field.destinationDb)
380
384
  continue;
381
- let fieldSQL = generateFieldSQL(field);
382
- /**
383
- * Check if the field is an identifier
384
- */
385
- if (field.name === table.identifier?.name) {
386
- fieldSQL += ' UNIQUE FIRST';
387
- }
385
+ const fieldSQLResult = [generateFieldSQL(field)].flat();
386
+ const isIdentifier = fieldSQLResult.length === 1 && field.name === table.identifier?.name;
388
387
  /**
389
388
  * Check if there are fields to remove
390
389
  * If there are, ask the user if they want to add the new field or rename a to-be-removed field
@@ -405,12 +404,14 @@ async function updateTable(table, s) {
405
404
  * Field doesn't exist.
406
405
  * Add the field to the table
407
406
  */
408
- alterTableSQLs.push({
409
- field: field.name,
410
- table: table.name,
411
- action: 'add',
412
- sql: `ADD COLUMN ${fieldSQL}`,
413
- });
407
+ for (const fieldSQL of fieldSQLResult) {
408
+ alterTableSQLs.push({
409
+ field: field.name,
410
+ table: table.name,
411
+ action: 'add',
412
+ sql: `ADD COLUMN ${fieldSQL}${isIdentifier ? ' UNIQUE FIRST' : ''}`,
413
+ });
414
+ }
414
415
  break;
415
416
  case 'rename': {
416
417
  s.stop();
@@ -448,12 +449,14 @@ async function updateTable(table, s) {
448
449
  * Field doesn't exist.
449
450
  * Add the field to the table
450
451
  */
451
- alterTableSQLs.push({
452
- field: field.name,
453
- table: table.name,
454
- action: 'add',
455
- sql: `ADD COLUMN ${fieldSQL}`,
456
- });
452
+ for (const fieldSQL of fieldSQLResult) {
453
+ alterTableSQLs.push({
454
+ field: field.name,
455
+ table: table.name,
456
+ action: 'add',
457
+ sql: `ADD COLUMN ${fieldSQL}${isIdentifier ? ' UNIQUE FIRST' : ''}`,
458
+ });
459
+ }
457
460
  }
458
461
  }
459
462
  }
@@ -1,5 +1,5 @@
1
1
  import dayjs from 'dayjs';
2
- import utc from 'dayjs/plugin/utc';
2
+ import utc from 'dayjs/plugin/utc.js';
3
3
  import * as z from 'zod';
4
4
  dayjs.extend(utc);
5
5
  export const dateBoundSchema = z.union([z.date(), z.literal('now')]);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nextjs-cms",
3
- "version": "0.9.10",
3
+ "version": "0.9.12",
4
4
  "main": "./dist/index.js",
5
5
  "types": "./dist/index.d.ts",
6
6
  "type": "module",
@@ -209,9 +209,9 @@
209
209
  "prettier": "^3.3.3",
210
210
  "tsx": "^4.20.6",
211
211
  "typescript": "^5.9.2",
212
- "@lzcms/tsconfig": "0.1.0",
213
212
  "@lzcms/eslint-config": "0.3.0",
214
- "@lzcms/prettier-config": "0.1.0"
213
+ "@lzcms/prettier-config": "0.1.0",
214
+ "@lzcms/tsconfig": "0.1.0"
215
215
  },
216
216
  "license": "MIT",
217
217
  "keywords": [