@easy-cms/drizzle 0.43.0 → 0.45.0

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/dist/index.d.ts CHANGED
@@ -38,10 +38,10 @@ interface Dialect {
38
38
  readonly singleWriter?: boolean;
39
39
  table(name: string, columns: Record<string, ColumnBuilder>, indexes: (t: Record<string, AnyColumn>) => IndexBuilder[]): AnyTable;
40
40
  index(name: string): {
41
- on(column: AnyColumn): IndexBuilder;
41
+ on(...columns: AnyColumn[]): IndexBuilder;
42
42
  };
43
43
  uniqueIndex(name: string): {
44
- on(column: AnyColumn): IndexBuilder;
44
+ on(...columns: AnyColumn[]): IndexBuilder;
45
45
  };
46
46
  /** Auto-incrementing integer primary key. */
47
47
  serial(name: string): ColumnBuilder;
package/dist/index.js CHANGED
@@ -386,7 +386,15 @@ function buildTable(builder, name, kind, fields, options) {
386
386
  defaultLocale: locale === localization?.defaultLocale
387
387
  }
388
388
  );
389
- if (topLevel && kind === "root" && (field.unique || field.type === "slug" && field.uniqueWithin === void 0)) {
389
+ if (topLevel && kind === "root" && (field.unique || field.type === "slug") && field.uniqueWithin !== void 0) {
390
+ const within = [field.uniqueWithin].flat().map(snake);
391
+ indexes.push({
392
+ column,
393
+ unique: true,
394
+ within: within.length === 1 ? within[0] : within
395
+ });
396
+ indexes.push({ column, unique: false });
397
+ } else if (topLevel && kind === "root" && (field.unique || field.type === "slug")) {
390
398
  indexes.push({ column, unique: true });
391
399
  } else if (field.index || field.unique || field.type === "slug" || field.type === "relationship" || field.type === "upload") {
392
400
  indexes.push({ column, unique: false });
@@ -399,8 +407,12 @@ function buildTable(builder, name, kind, fields, options) {
399
407
  const table = dialect.table(
400
408
  name,
401
409
  columns,
402
- (t) => indexes.map(({ column, unique }) => {
410
+ (t) => indexes.map(({ column, unique, within }) => {
403
411
  const col3 = t[column];
412
+ if (within) {
413
+ const columns2 = [within].flat();
414
+ return dialect.uniqueIndex(`${name}_${columns2.join("_")}_${column}_unique`).on(...columns2.map((w) => t[w]), col3);
415
+ }
404
416
  return unique ? dialect.uniqueIndex(`${name}_${column}_unique`).on(col3) : dialect.index(`${name}_${column}_idx`).on(col3);
405
417
  })
406
418
  );
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@easy-cms/drizzle",
3
- "version": "0.43.0",
3
+ "version": "0.45.0",
4
4
  "description": "Shared Drizzle ORM layer for Easy CMS database adapters",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -23,10 +23,10 @@
23
23
  "drizzle-orm": "0.45.3"
24
24
  },
25
25
  "peerDependencies": {
26
- "@easy-cms/core": "^0.43.0"
26
+ "@easy-cms/core": "^0.45.0"
27
27
  },
28
28
  "devDependencies": {
29
- "@easy-cms/core": "^0.43.0"
29
+ "@easy-cms/core": "^0.45.0"
30
30
  },
31
31
  "publishConfig": {
32
32
  "access": "public"