@supawatch/target-seed 0.8.0 → 0.9.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.
Files changed (2) hide show
  1. package/dist/index.js +24 -0
  2. package/package.json +2 -2
package/dist/index.js CHANGED
@@ -69,6 +69,8 @@ function literalFor(runtime, col, table, rowIndex, rand, baseTypeOf) {
69
69
  case "json":
70
70
  return sqlString("{}") + "::jsonb";
71
71
  case "enum": {
72
+ if (runtime.labels.length === 0)
73
+ return null; // zero-label enums hold nothing
72
74
  const label = runtime.labels[rowIndex % runtime.labels.length];
73
75
  return sqlString(label) + `::"${col.pgTypeName.replace(/^_/, "")}"`;
74
76
  }
@@ -199,6 +201,10 @@ export class SeedTarget {
199
201
  const col = t.columns.find((c) => c.name === pkName);
200
202
  if (!col)
201
203
  return null;
204
+ // A stored-generated pk computes its own value from an expression
205
+ // the generator cannot predict; children cannot reference it.
206
+ if (col.generated)
207
+ return null;
202
208
  if (col.runtime.kind === "number")
203
209
  return String(i + 1);
204
210
  // bigint primary keys arrive as strings from the driver but seed
@@ -245,6 +251,16 @@ export class SeedTarget {
245
251
  continue;
246
252
  }
247
253
  if (col.name === pk) {
254
+ // A pk with no honest literal (interval, composite, ...) can
255
+ // only work when the database fills it; without a default the
256
+ // table cannot be seeded at all.
257
+ const pkProbe = literalFor(col.runtime, col, table, 0, mulberry32(1), baseTypeOf);
258
+ if (pkProbe === null) {
259
+ if (col.identity || col.hasDefault)
260
+ continue; // db fills it
261
+ skipReasons.push(`primary key ${col.name} has no honest literal (${col.sqlType})`);
262
+ continue;
263
+ }
248
264
  cols.push(col);
249
265
  continue;
250
266
  }
@@ -264,6 +280,14 @@ export class SeedTarget {
264
280
  }
265
281
  continue;
266
282
  }
283
+ // ... and the parent's pk values must be predictable
284
+ // (generated or literal-less pks are not).
285
+ if (parent !== undefined && pkLiteral(parent, 0) === null) {
286
+ if (!col.nullable && !col.hasDefault) {
287
+ skipReasons.push(`foreign key ${col.name} references ${fk.referencedTable}, whose primary key values the generator cannot predict`);
288
+ }
289
+ continue;
290
+ }
267
291
  cols.push(col);
268
292
  continue;
269
293
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@supawatch/target-seed",
3
- "version": "0.8.0",
3
+ "version": "0.9.0",
4
4
  "description": "Deterministic FK-aware seed.sql generated from live Postgres by supawatch: topological order, identity overriding, sequence resync.",
5
5
  "keywords": [
6
6
  "supabase",
@@ -34,7 +34,7 @@
34
34
  "dist"
35
35
  ],
36
36
  "dependencies": {
37
- "@supawatch/core": "0.8.0"
37
+ "@supawatch/core": "0.9.0"
38
38
  },
39
39
  "devDependencies": {
40
40
  "@types/node": "^22.20.1",