@apso/cli 0.52.0 → 0.54.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 (106) hide show
  1. package/dist/commands/import/supabase.js +31 -6
  2. package/dist/commands/init.d.ts +9 -0
  3. package/dist/commands/init.js +31 -1
  4. package/dist/commands/mcp/serve.js +20 -0
  5. package/dist/commands/schema/validate.js +18 -1
  6. package/dist/lib/apsorc-parser.js +7 -3
  7. package/dist/lib/base-command.js +14 -3
  8. package/dist/lib/config/types.d.ts +5 -0
  9. package/dist/lib/ddl/catalog.js +5 -2
  10. package/dist/lib/ddl/change.js +13 -2
  11. package/dist/lib/ddl/index.d.ts +62 -3
  12. package/dist/lib/ddl/index.js +211 -40
  13. package/dist/lib/generators/go.js +17 -3
  14. package/dist/lib/generators/python.js +17 -3
  15. package/dist/lib/generators/typescript.js +85 -15
  16. package/dist/lib/import/copy-data.js +4 -0
  17. package/dist/lib/import/introspect.d.ts +40 -0
  18. package/dist/lib/import/introspect.js +137 -49
  19. package/dist/lib/import/pg-to-apsorc.d.ts +62 -0
  20. package/dist/lib/import/pg-to-apsorc.js +248 -37
  21. package/dist/lib/import/types.d.ts +48 -3
  22. package/dist/lib/migrate/sandbox.js +23 -6
  23. package/dist/lib/migrate/snapshot.d.ts +5 -0
  24. package/dist/lib/plan/index.d.ts +4 -1
  25. package/dist/lib/plan/index.js +9 -3
  26. package/dist/lib/telemetry/error-utils.d.ts +74 -0
  27. package/dist/lib/telemetry/error-utils.js +221 -0
  28. package/dist/lib/telemetry/internal-constants.d.ts +27 -0
  29. package/dist/lib/telemetry/internal-constants.js +32 -0
  30. package/dist/lib/telemetry/internal-detection.d.ts +37 -0
  31. package/dist/lib/telemetry/internal-detection.js +78 -0
  32. package/dist/lib/telemetry/telemetry.d.ts +11 -0
  33. package/dist/lib/telemetry/telemetry.js +197 -3
  34. package/dist/lib/templates/entities/entity-col-array.eta +2 -1
  35. package/dist/lib/templates/entities/entity-col-bigint.eta +2 -2
  36. package/dist/lib/templates/entities/entity-col-bigserial.eta +2 -2
  37. package/dist/lib/templates/entities/entity-col-boolean.eta +1 -1
  38. package/dist/lib/templates/entities/entity-col-bytea.eta +2 -2
  39. package/dist/lib/templates/entities/entity-col-char.eta +4 -3
  40. package/dist/lib/templates/entities/entity-col-date.eta +6 -2
  41. package/dist/lib/templates/entities/entity-col-datetime.eta +8 -1
  42. package/dist/lib/templates/entities/entity-col-decimal.eta +2 -2
  43. package/dist/lib/templates/entities/entity-col-double.eta +2 -2
  44. package/dist/lib/templates/entities/entity-col-float.eta +1 -1
  45. package/dist/lib/templates/entities/entity-col-geography.eta +1 -1
  46. package/dist/lib/templates/entities/entity-col-geometry.eta +1 -1
  47. package/dist/lib/templates/entities/entity-col-geometrycollection.eta +1 -1
  48. package/dist/lib/templates/entities/entity-col-inet.eta +2 -2
  49. package/dist/lib/templates/entities/entity-col-int4range.eta +1 -1
  50. package/dist/lib/templates/entities/entity-col-integer.eta +2 -2
  51. package/dist/lib/templates/entities/entity-col-interval.eta +2 -2
  52. package/dist/lib/templates/entities/entity-col-json-plain.eta +1 -1
  53. package/dist/lib/templates/entities/entity-col-json.eta +1 -1
  54. package/dist/lib/templates/entities/entity-col-jsonb.eta +1 -1
  55. package/dist/lib/templates/entities/entity-col-linestring.eta +1 -1
  56. package/dist/lib/templates/entities/entity-col-money.eta +2 -2
  57. package/dist/lib/templates/entities/entity-col-multilinestring.eta +1 -1
  58. package/dist/lib/templates/entities/entity-col-multipoint.eta +1 -1
  59. package/dist/lib/templates/entities/entity-col-multipolygon.eta +1 -1
  60. package/dist/lib/templates/entities/entity-col-numeric.eta +2 -2
  61. package/dist/lib/templates/entities/entity-col-point.eta +1 -1
  62. package/dist/lib/templates/entities/entity-col-polygon.eta +1 -1
  63. package/dist/lib/templates/entities/entity-col-real.eta +2 -2
  64. package/dist/lib/templates/entities/entity-col-serial.eta +2 -2
  65. package/dist/lib/templates/entities/entity-col-smallint.eta +2 -2
  66. package/dist/lib/templates/entities/entity-col-smallserial.eta +2 -2
  67. package/dist/lib/templates/entities/entity-col-string.eta +2 -2
  68. package/dist/lib/templates/entities/entity-col-text.eta +4 -3
  69. package/dist/lib/templates/entities/entity-col-time.eta +2 -2
  70. package/dist/lib/templates/entities/entity-col-timestamp.eta +8 -1
  71. package/dist/lib/templates/entities/entity-col-timestamptz.eta +8 -1
  72. package/dist/lib/templates/entities/entity-col-timetz.eta +2 -2
  73. package/dist/lib/templates/entities/entity-col-tsvector.eta +2 -2
  74. package/dist/lib/templates/entities/entity-col-uuid.eta +5 -2
  75. package/dist/lib/templates/entities/entity-col-varchar.eta +4 -3
  76. package/dist/lib/templates/entities/entity-col-xml.eta +2 -2
  77. package/dist/lib/templates/entities/entity.eta +30 -18
  78. package/dist/lib/templates/go/models/model.eta +3 -3
  79. package/dist/lib/templates/python/models/model.eta +1 -1
  80. package/dist/lib/templates/rest/controller-rest.eta +16 -5
  81. package/dist/lib/templates/rest/dto-rest.eta +2 -2
  82. package/dist/lib/templates/rest/index-module-rest.eta +6 -0
  83. package/dist/lib/templates/rest/schema-extras-module.eta +24 -0
  84. package/dist/lib/types/constraints.d.ts +13 -0
  85. package/dist/lib/types/entity.d.ts +67 -2
  86. package/dist/lib/types/entity.js +39 -1
  87. package/dist/lib/types/field.d.ts +20 -2
  88. package/dist/lib/types/indices.d.ts +21 -0
  89. package/dist/lib/types/relationship.d.ts +33 -0
  90. package/dist/lib/types/relationship.js +13 -0
  91. package/dist/lib/upgrade.d.ts +5 -6
  92. package/dist/lib/upgrade.js +12 -23
  93. package/dist/lib/utils/field.d.ts +22 -0
  94. package/dist/lib/utils/field.js +62 -3
  95. package/dist/lib/utils/relationships/index.d.ts +1 -1
  96. package/dist/lib/utils/relationships/index.js +2 -1
  97. package/dist/lib/utils/relationships/parse.d.ts +11 -0
  98. package/dist/lib/utils/relationships/parse.js +44 -1
  99. package/dist/lib/utils/template.d.ts +3 -3
  100. package/dist/lib/utils/template.js +4 -4
  101. package/dist/lib/verify/crud-plan.d.ts +2 -0
  102. package/dist/lib/verify/crud-plan.js +19 -5
  103. package/dist/lib/verify/index.js +32 -3
  104. package/npm-shrinkwrap.json +77 -91
  105. package/oclif.manifest.json +7 -1
  106. package/package.json +4 -2
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.__testing = exports.shutdownTelemetry = exports.elapsedMs = exports.captureException = exports.track = exports.markFirstRunNoticeShown = exports.shouldShowFirstRunNotice = exports.FIRST_RUN_NOTICE = exports.initTelemetry = void 0;
3
+ exports.__testing = exports.shutdownTelemetry = exports.elapsedMs = exports.capturePostHogException = exports.captureException = exports.track = exports.markFirstRunNoticeShown = exports.shouldShowFirstRunNotice = exports.FIRST_RUN_NOTICE = exports.initTelemetry = void 0;
4
4
  const tslib_1 = require("tslib");
5
5
  /**
6
6
  * CLI telemetry — usage analytics (PostHog) + error reporting (Sentry).
@@ -25,7 +25,10 @@ const posthog_node_1 = require("posthog-node");
25
25
  const Sentry = tslib_1.__importStar(require("@sentry/node"));
26
26
  const crypto_1 = require("crypto");
27
27
  const os_1 = tslib_1.__importDefault(require("os"));
28
+ const ci_info_1 = tslib_1.__importDefault(require("ci-info"));
28
29
  const config_1 = require("../config");
30
+ const error_utils_1 = require("./error-utils");
31
+ const internal_detection_1 = require("./internal-detection");
29
32
  // Public ingestion keys (same tokens the browser/build-engine ship, per env).
30
33
  const POSTHOG_KEY_PROD = "phc_Es9UUMw8pOs7Bs21b5PhfC5Qdo94GpYVv8MfdrG12LC";
31
34
  const POSTHOG_KEY_STAGING = "phc_bkc33v3wo5LRvgPF6IdjsgDEDOwgJMz95MR2YIlvELk";
@@ -51,6 +54,7 @@ let serviceId;
51
54
  let environment = "production";
52
55
  let startedAt = Date.now();
53
56
  let noticePending = false;
57
+ let internalDetection = { internal: false };
54
58
  function isDisabled(telemetryDisabled) {
55
59
  if (process.env.DO_NOT_TRACK === "1" || process.env.DO_NOT_TRACK === "true")
56
60
  return true;
@@ -88,7 +92,7 @@ function getOrCreateInstallId(currentInstallId) {
88
92
  * when disabled — it just no-ops everything downstream.
89
93
  */
90
94
  function initTelemetry() {
91
- var _a, _b;
95
+ var _a, _b, _c;
92
96
  try {
93
97
  startedAt = Date.now();
94
98
  const cfg = config_1.globalConfig.read();
@@ -97,6 +101,8 @@ function initTelemetry() {
97
101
  return;
98
102
  }
99
103
  enabled = true;
104
+ // Install uncaught exception and unhandled rejection handlers
105
+ installGlobalErrorHandlers();
100
106
  environment = (cfg.apiUrl || "").includes("staging")
101
107
  ? "staging"
102
108
  : "production";
@@ -120,6 +126,13 @@ function initTelemetry() {
120
126
  workspaceId = (link === null || link === void 0 ? void 0 : link.workspaceId) || cfg.activeWorkspaceId || undefined;
121
127
  workspaceSlug = (link === null || link === void 0 ? void 0 : link.workspaceSlug) || cfg.activeWorkspaceSlug || undefined;
122
128
  serviceId = (link === null || link === void 0 ? void 0 : link.serviceId) || undefined;
129
+ // Detect internal runs (Apso team/system)
130
+ internalDetection = (0, internal_detection_1.detectInternal)({
131
+ configInternal: cfg.internal,
132
+ userEmail: (_c = creds === null || creds === void 0 ? void 0 : creds.user) === null || _c === void 0 ? void 0 : _c.email,
133
+ workspaceSlug,
134
+ workspaceId,
135
+ });
123
136
  posthog = new posthog_node_1.PostHog(environment === "staging" ? POSTHOG_KEY_STAGING : POSTHOG_KEY_PROD, { host: POSTHOG_HOST, flushAt: 1, flushInterval: 0 });
124
137
  // First run after login: merge this install's earlier anonymous events
125
138
  // into the user, once per user.
@@ -146,6 +159,11 @@ function initTelemetry() {
146
159
  Sentry.setTag("workspace_id", workspaceId);
147
160
  if (serviceId)
148
161
  Sentry.setTag("service_id", serviceId);
162
+ // Tag internal runs in Sentry
163
+ Sentry.setTag("internal", String(internalDetection.internal));
164
+ if (internalDetection.reason) {
165
+ Sentry.setTag("internal_reason", internalDetection.reason);
166
+ }
149
167
  sentryOn = true;
150
168
  }
151
169
  }
@@ -162,6 +180,10 @@ function commonProps() {
162
180
  arch: os_1.default.arch(),
163
181
  node_version: process.version,
164
182
  authenticated: authenticatedUser,
183
+ ci: ci_info_1.default.isCI,
184
+ internal: internalDetection.internal,
185
+ // eslint-disable-next-line camelcase
186
+ ...(internalDetection.reason ? { internal_reason: internalDetection.reason } : {}),
165
187
  ...(workspaceId ? { workspace_id: workspaceId } : {}),
166
188
  ...(workspaceSlug ? { workspace_slug: workspaceSlug } : {}),
167
189
  ...(serviceId ? { service_id: serviceId } : {}),
@@ -202,7 +224,17 @@ function track(event, properties = {}) {
202
224
  posthog.capture({
203
225
  distinctId,
204
226
  event,
205
- properties: { ...commonProps(), ...properties },
227
+ properties: {
228
+ ...commonProps(),
229
+ ...properties,
230
+ // Set internal as person properties via $set (posthog-node types don't include it, but it works)
231
+ // eslint-disable-next-line camelcase
232
+ $set: {
233
+ internal: internalDetection.internal,
234
+ // eslint-disable-next-line camelcase
235
+ ...(internalDetection.reason ? { internal_reason: internalDetection.reason } : {}),
236
+ },
237
+ },
206
238
  // PostHog group analytics: roll activity up per workspace.
207
239
  ...(workspaceId ? { groups: { workspace: workspaceId } } : {}),
208
240
  });
@@ -224,6 +256,83 @@ function captureException(err, context = {}) {
224
256
  }
225
257
  }
226
258
  exports.captureException = captureException;
259
+ /**
260
+ * Capture an exception event in PostHog with structured error properties.
261
+ *
262
+ * PostHog's posthog-node SDK (v5.21.2+) doesn't have a direct captureException
263
+ * method, so we send an $exception event with $exception_list in the standard
264
+ * format: https://posthog.com/docs/data/exceptions
265
+ *
266
+ * @param err - The error to capture
267
+ * @param context - Additional context properties (command, etc.)
268
+ */
269
+ function capturePostHogException(err, context = {}) {
270
+ try {
271
+ if (!enabled || !posthog)
272
+ return;
273
+ const errorProps = (0, error_utils_1.extractErrorProperties)(err);
274
+ const stack = err instanceof Error ? err.stack : undefined;
275
+ // PostHog exception format: $exception event with $exception_list
276
+ posthog.capture({
277
+ distinctId,
278
+ event: "$exception",
279
+ properties: {
280
+ ...commonProps(),
281
+ ...context,
282
+ // eslint-disable-next-line camelcase
283
+ $exception_list: [
284
+ {
285
+ // eslint-disable-next-line camelcase
286
+ type: errorProps.error_class || "Error",
287
+ // eslint-disable-next-line camelcase
288
+ value: errorProps.error_message || String(err),
289
+ ...(stack ? { stacktrace: { frames: parseStackTrace(stack) } } : {}),
290
+ },
291
+ ],
292
+ // Additional structured error properties
293
+ ...errorProps,
294
+ // Set internal as person properties via $set (posthog-node types don't include it, but it works)
295
+ // eslint-disable-next-line camelcase
296
+ $set: {
297
+ internal: internalDetection.internal,
298
+ // eslint-disable-next-line camelcase
299
+ ...(internalDetection.reason ? { internal_reason: internalDetection.reason } : {}),
300
+ },
301
+ },
302
+ ...(workspaceId ? { groups: { workspace: workspaceId } } : {}),
303
+ });
304
+ }
305
+ catch {
306
+ // never break a command over telemetry
307
+ }
308
+ }
309
+ exports.capturePostHogException = capturePostHogException;
310
+ /**
311
+ * Parse a stack trace string into PostHog's frame format.
312
+ * Best-effort parsing; PostHog accepts frames with minimal structure.
313
+ */
314
+ function parseStackTrace(stack) {
315
+ try {
316
+ const lines = stack.split("\n").slice(1); // Skip the error message line
317
+ return lines.slice(0, 10).map((line) => {
318
+ // Basic parsing: extract function name and location if available
319
+ const match = line.match(/at\s+(?:(.+?)\s+\()?(.+?):(\d+):(\d+)\)?/);
320
+ if (match) {
321
+ const [, fn, filename, lineno, colno] = match;
322
+ return {
323
+ function: fn || "<anonymous>",
324
+ filename: (filename === null || filename === void 0 ? void 0 : filename.replace(os_1.default.homedir(), "~")) || "unknown",
325
+ lineno: Number.parseInt(lineno, 10),
326
+ colno: Number.parseInt(colno, 10),
327
+ };
328
+ }
329
+ return { raw: line.trim() };
330
+ });
331
+ }
332
+ catch {
333
+ return [{ raw: "Failed to parse stack trace" }];
334
+ }
335
+ }
227
336
  /** Milliseconds since the process (CLI invocation) started. */
228
337
  function elapsedMs() {
229
338
  return Date.now() - startedAt;
@@ -247,4 +356,89 @@ async function shutdownTelemetry() {
247
356
  }
248
357
  }
249
358
  exports.shutdownTelemetry = shutdownTelemetry;
359
+ /**
360
+ * Guard against re-entry in global error handlers.
361
+ */
362
+ let handlingFatalError = false;
363
+ /**
364
+ * Install global handlers for uncaught exceptions and unhandled rejections.
365
+ * These handlers capture telemetry, flush with a timeout, then crash properly
366
+ * with non-zero exit and stderr output (preserving Node's default behavior).
367
+ */
368
+ function installGlobalErrorHandlers() {
369
+ process.on("uncaughtException", (err) => {
370
+ if (handlingFatalError) {
371
+ // Re-entry during error handling - bail immediately
372
+ process.stderr.write("Fatal error during error handling\n");
373
+ // eslint-disable-next-line no-process-exit
374
+ process.exit(1);
375
+ }
376
+ handlingFatalError = true;
377
+ // Capture telemetry (best-effort, non-blocking)
378
+ try {
379
+ // eslint-disable-next-line camelcase
380
+ captureException(err, { event_type: "uncaught_exception" });
381
+ // eslint-disable-next-line camelcase
382
+ capturePostHogException(err, { event_type: "uncaught_exception" });
383
+ }
384
+ catch {
385
+ // ignore telemetry errors
386
+ }
387
+ // Flush telemetry with a short timeout (2s), then crash properly
388
+ const flushWithTimeout = Promise.race([
389
+ shutdownTelemetry(),
390
+ new Promise((resolve) => {
391
+ setTimeout(() => resolve(), 2000);
392
+ }),
393
+ ]);
394
+ flushWithTimeout
395
+ .catch(() => {
396
+ // ignore flush errors
397
+ })
398
+ .finally(() => {
399
+ // Print error to stderr (Node's default behavior)
400
+ process.stderr.write(`\n${err.stack || err.message}\n`);
401
+ // Exit non-zero (Node's default behavior)
402
+ // eslint-disable-next-line no-process-exit
403
+ process.exit(1);
404
+ });
405
+ });
406
+ process.on("unhandledRejection", (reason) => {
407
+ if (handlingFatalError) {
408
+ process.stderr.write("Fatal error during error handling\n");
409
+ // eslint-disable-next-line no-process-exit
410
+ process.exit(1);
411
+ }
412
+ handlingFatalError = true;
413
+ const err = reason instanceof Error ? reason : new Error(String(reason));
414
+ // Capture telemetry (best-effort, non-blocking)
415
+ try {
416
+ // eslint-disable-next-line camelcase
417
+ captureException(err, { event_type: "unhandled_rejection" });
418
+ // eslint-disable-next-line camelcase
419
+ capturePostHogException(err, { event_type: "unhandled_rejection" });
420
+ }
421
+ catch {
422
+ // ignore telemetry errors
423
+ }
424
+ // Flush telemetry with a short timeout (2s), then crash properly
425
+ const flushWithTimeout = Promise.race([
426
+ shutdownTelemetry(),
427
+ new Promise((resolve) => {
428
+ setTimeout(() => resolve(), 2000);
429
+ }),
430
+ ]);
431
+ flushWithTimeout
432
+ .catch(() => {
433
+ // ignore flush errors
434
+ })
435
+ .finally(() => {
436
+ // Print error to stderr (Node's default behavior)
437
+ process.stderr.write(`\nUnhandled rejection: ${err.stack || err.message}\n`);
438
+ // Exit non-zero (Node's default behavior)
439
+ // eslint-disable-next-line no-process-exit
440
+ process.exit(1);
441
+ });
442
+ });
443
+ }
250
444
  exports.__testing = { isDisabled, anonMachineId, getOrCreateInstallId };
@@ -3,7 +3,8 @@
3
3
  @Column({
4
4
  type: "<%= field.elementType || 'text' %>",
5
5
  array: true<% if (field.nullable) {%>,
6
- nullable: true<% } %>
6
+ nullable: true<% } %><% if (field.defaultSql) { %>,
7
+ default: () => <%~ JSON.stringify(field.defaultSql) %><% } %>
7
8
  })
8
9
  <% if (field.index ) {%>
9
10
  @Index()
@@ -1,11 +1,11 @@
1
1
  <% const {field} = it; %>
2
2
 
3
- @Column({ "type": "bigint", nullable: <%= Boolean(field.nullable) %><% if (field.default !== null) {%>, default: <%= field.default %><% } %> })
3
+ @Column({ "type": "bigint", nullable: <%= Boolean(field.nullable) %><% if (field.default !== null) {%>, default: <%= field.default %><% } %><% if (field.defaultSql) { %>, default: () => <%~ JSON.stringify(field.defaultSql) %><% } %> })
4
4
  <% if (field.index ) {%>
5
5
  @Index()
6
6
  <% } %>
7
7
  <% if (field.primary ) {%>
8
- @PrimaryColumn()
8
+ @PrimaryColumn(<% if (field.primaryKeyName) { %>{ primaryKeyConstraintName: '<%= field.primaryKeyName %>' }<% } %>)
9
9
  <% } %>
10
10
 
11
11
  <%= field.name %>: string;
@@ -1,12 +1,12 @@
1
1
  <% const {field} = it; %>
2
2
 
3
- @Column({ "type": "bigint" })
3
+ @Column({ "type": "bigint"<% if (field.defaultSql) { %>, default: () => <%~ JSON.stringify(field.defaultSql) %><% } %> })
4
4
  @Generated("increment")
5
5
  <% if (field.index ) {%>
6
6
  @Index()
7
7
  <% } %>
8
8
  <% if (field.primary ) {%>
9
- @PrimaryColumn()
9
+ @PrimaryColumn(<% if (field.primaryKeyName) { %>{ primaryKeyConstraintName: '<%= field.primaryKeyName %>' }<% } %>)
10
10
  <% } %>
11
11
 
12
12
  <%= field.name %>: string;
@@ -3,7 +3,7 @@
3
3
  @IsOptional({ groups: [CREATE, UPDATE] })
4
4
  @IsBoolean({ always: true })
5
5
 
6
- @Column({ type: 'boolean', nullable: <%= Boolean(field.nullable) %>, default: <%= field.default === true || String(field.default).toLowerCase() === 'true' %> })
6
+ @Column({ type: 'boolean', nullable: <%= Boolean(field.nullable) %><% if (field.defaultSql) { %>, default: () => <%~ JSON.stringify(field.defaultSql) %><% } else if (!field.noDefault) { %>, default: <%= field.default === true || String(field.default).toLowerCase() === 'true' %><% } %> })
7
7
  <% if (field.index ) {%>
8
8
  @Index()
9
9
  <% } %>
@@ -1,11 +1,11 @@
1
1
  <% const {field} = it; %>
2
2
 
3
- @Column({ "type": "bytea", nullable: <%= Boolean(field.nullable) %><% if (field.default !== null) {%>, default: <%= field.default %><% } %> })
3
+ @Column({ "type": "bytea", nullable: <%= Boolean(field.nullable) %><% if (field.default !== null) {%>, default: <%= field.default %><% } %><% if (field.defaultSql) { %>, default: () => <%~ JSON.stringify(field.defaultSql) %><% } %> })
4
4
  <% if (field.index ) {%>
5
5
  @Index()
6
6
  <% } %>
7
7
  <% if (field.primary ) {%>
8
- @PrimaryColumn()
8
+ @PrimaryColumn(<% if (field.primaryKeyName) { %>{ primaryKeyConstraintName: '<%= field.primaryKeyName %>' }<% } %>)
9
9
  <% } %>
10
10
 
11
11
  <%= field.name %>: Buffer;
@@ -7,9 +7,10 @@
7
7
  <% if (field.index ) {%>
8
8
  @Index()
9
9
  <% } %>
10
- @Column({ type: "char", length: <%= field.length || 1 %>, nullable: <%= Boolean(field.nullable) %><% if (field.unique) {%>, unique: true <% } %><% if (field.default !== null) {%>, default: '<%= field.default %>'<% } %> })
11
- <% if (field.primary ) {%>
12
- @PrimaryColumn()
10
+ <% if (field.primary) { %>
11
+ @PrimaryColumn({ type: "char", length: <%= field.length || 1 %><% if (field.primaryKeyName) { %>, primaryKeyConstraintName: '<%= field.primaryKeyName %>'<% } %> })
12
+ <% } else { %>
13
+ @Column({ type: "char", length: <%= field.length || 1 %>, nullable: <%= Boolean(field.nullable) %><% if (field.unique) {%>, unique: true <% } %><% if (field.default !== null) {%>, default: '<%= field.default %>'<% } %><% if (field.defaultSql) { %>, default: () => <%~ JSON.stringify(field.defaultSql) %><% } %> })
13
14
  <% } %>
14
15
 
15
16
  <%= field.name %>: string;
@@ -1,8 +1,12 @@
1
1
  <% const {field} = it; %>
2
2
 
3
- @Column({ type: 'date', nullable: <%= Boolean(field.nullable) %> })
4
- <% if (field.index ) {%>
3
+ <% if (field.primary) { %>
4
+ @PrimaryColumn({ type: 'date'<% if (field.primaryKeyName) { %>, primaryKeyConstraintName: '<%= field.primaryKeyName %>'<% } %> })
5
+ <% } else { %>
6
+ <% if (field.index) { %>
5
7
  @Index()
6
8
  <% } %>
9
+ @Column({ type: 'date', nullable: <%= Boolean(field.nullable) %><% if (field.unique) { %>, unique: true<% } %><% if (field.defaultSql) { %>, default: () => <%~ JSON.stringify(field.defaultSql) %><% } %> })
10
+ <% } %>
7
11
 
8
12
  <%= field.name %>: string;
@@ -1,4 +1,11 @@
1
1
  <% const {field} = it; %>
2
2
 
3
- @Column({ type: 'timestamp', nullable: <%= Boolean(field.nullable) %> })
3
+ <% if (field.primary) { %>
4
+ @PrimaryColumn({ type: 'timestamp'<% if (field.primaryKeyName) { %>, primaryKeyConstraintName: '<%= field.primaryKeyName %>'<% } %> })
5
+ <% } else { %>
6
+ <% if (field.index) { %>
7
+ @Index()
8
+ <% } %>
9
+ @Column({ type: 'timestamp', nullable: <%= Boolean(field.nullable) %><% if (field.unique) { %>, unique: true<% } %><% if (field.defaultSql) { %>, default: () => <%~ JSON.stringify(field.defaultSql) %><% } %> })
10
+ <% } %>
4
11
  <%= field.name %>: Date;
@@ -1,11 +1,11 @@
1
1
  <% const {field} = it; %>
2
2
 
3
- @Column({ "type": "decimal", precision: <%= field.precision || 10 %>, scale: <%= field.scale || 2 %>, nullable: <%= Boolean(field.nullable) %><% if (field.default !== null) {%>, default: <%= field.default %><% } %> })
3
+ @Column({ "type": "decimal", precision: <%= field.precision || 10 %>, scale: <%= field.scale || 2 %>, nullable: <%= Boolean(field.nullable) %><% if (field.default !== null) {%>, default: <%= field.default %><% } %><% if (field.defaultSql) { %>, default: () => <%~ JSON.stringify(field.defaultSql) %><% } %> })
4
4
  <% if (field.index ) {%>
5
5
  @Index()
6
6
  <% } %>
7
7
  <% if (field.primary ) {%>
8
- @PrimaryColumn()
8
+ @PrimaryColumn(<% if (field.primaryKeyName) { %>{ primaryKeyConstraintName: '<%= field.primaryKeyName %>' }<% } %>)
9
9
  <% } %>
10
10
 
11
11
  <%= field.name %>: number;
@@ -1,11 +1,11 @@
1
1
  <% const {field} = it; %>
2
2
 
3
- @Column({ "type": "float8", nullable: <%= Boolean(field.nullable) %><% if (field.default !== null) {%>, default: <%= field.default %><% } %> })
3
+ @Column({ "type": "float8", nullable: <%= Boolean(field.nullable) %><% if (field.default !== null) {%>, default: <%= field.default %><% } %><% if (field.defaultSql) { %>, default: () => <%~ JSON.stringify(field.defaultSql) %><% } %> })
4
4
  <% if (field.index ) {%>
5
5
  @Index()
6
6
  <% } %>
7
7
  <% if (field.primary ) {%>
8
- @PrimaryColumn()
8
+ @PrimaryColumn(<% if (field.primaryKeyName) { %>{ primaryKeyConstraintName: '<%= field.primaryKeyName %>' }<% } %>)
9
9
  <% } %>
10
10
 
11
11
  <%= field.name %>: number;
@@ -1,6 +1,6 @@
1
1
  <% const {field} = it; %>
2
2
 
3
- @Column({ "type": "decimal", nullable: <%= Boolean(field.nullable) %><% if (field.default !== null) {%>, default: <%= field.default %><% } %> })
3
+ @Column({ "type": "decimal", nullable: <%= Boolean(field.nullable) %><% if (field.default !== null) {%>, default: <%= field.default %><% } %><% if (field.defaultSql) { %>, default: () => <%~ JSON.stringify(field.defaultSql) %><% } %> })
4
4
  <% if (field.index ) {%>
5
5
  @Index()
6
6
  <% } %>
@@ -23,7 +23,7 @@
23
23
  @Index()
24
24
  <% } %>
25
25
  <% if (field.primary ) {%>
26
- @PrimaryColumn()
26
+ @PrimaryColumn(<% if (field.primaryKeyName) { %>{ primaryKeyConstraintName: '<%= field.primaryKeyName %>' }<% } %>)
27
27
  <% } %>
28
28
 
29
29
  <%= field.name %>: any;
@@ -23,7 +23,7 @@
23
23
  @Index()
24
24
  <% } %>
25
25
  <% if (field.primary ) {%>
26
- @PrimaryColumn()
26
+ @PrimaryColumn(<% if (field.primaryKeyName) { %>{ primaryKeyConstraintName: '<%= field.primaryKeyName %>' }<% } %>)
27
27
  <% } %>
28
28
 
29
29
  <%= field.name %>: any;
@@ -23,7 +23,7 @@
23
23
  @Index()
24
24
  <% } %>
25
25
  <% if (field.primary ) {%>
26
- @PrimaryColumn()
26
+ @PrimaryColumn(<% if (field.primaryKeyName) { %>{ primaryKeyConstraintName: '<%= field.primaryKeyName %>' }<% } %>)
27
27
  <% } %>
28
28
 
29
29
  <%= field.name %>: { geometries: Array<any> };
@@ -1,11 +1,11 @@
1
1
  <% const {field} = it; %>
2
2
 
3
- @Column({ "type": "inet"<% if (field.default !== null) {%>, default: <%= field.default %><% } %><% if (field.nullable) {%>, nullable: true<% } %> })
3
+ @Column({ "type": "inet"<% if (field.default !== null) {%>, default: <%= field.default %><% } %><% if (field.nullable) {%>, nullable: true<% } %><% if (field.defaultSql) { %>, default: () => <%~ JSON.stringify(field.defaultSql) %><% } %> })
4
4
  <% if (field.index ) {%>
5
5
  @Index()
6
6
  <% } %>
7
7
  <% if (field.primary ) {%>
8
- @PrimaryColumn()
8
+ @PrimaryColumn(<% if (field.primaryKeyName) { %>{ primaryKeyConstraintName: '<%= field.primaryKeyName %>' }<% } %>)
9
9
  <% } %>
10
10
 
11
11
  <%= field.name %>: string;
@@ -28,7 +28,7 @@
28
28
  @Index()
29
29
  <% } %>
30
30
  <% if (field.primary ) {%>
31
- @PrimaryColumn()
31
+ @PrimaryColumn(<% if (field.primaryKeyName) { %>{ primaryKeyConstraintName: '<%= field.primaryKeyName %>' }<% } %>)
32
32
  <% } %>
33
33
 
34
34
  <%= field.name %>: {lower: number, upper: number, lowerInclusive: boolean, upperInclusive: boolean};
@@ -1,11 +1,11 @@
1
1
  <% const {field} = it; %>
2
2
 
3
- @Column({ "type": "int", nullable: <%= Boolean(field.nullable) %><% if (field.default !== null) {%>, default: <%= field.default %><% } %> })
3
+ @Column({ "type": "int", nullable: <%= Boolean(field.nullable) %><% if (field.default !== null) {%>, default: <%= field.default %><% } %><% if (field.defaultSql) { %>, default: () => <%~ JSON.stringify(field.defaultSql) %><% } %> })
4
4
  <% if (field.index ) {%>
5
5
  @Index()
6
6
  <% } %>
7
7
  <% if (field.primary ) {%>
8
- @PrimaryColumn()
8
+ @PrimaryColumn(<% if (field.primaryKeyName) { %>{ primaryKeyConstraintName: '<%= field.primaryKeyName %>' }<% } %>)
9
9
  <% } %>
10
10
 
11
11
  <%= field.name %>: <%= field.dataType %>;
@@ -1,11 +1,11 @@
1
1
  <% const {field} = it; %>
2
2
 
3
- @Column({ "type": "interval", nullable: <%= Boolean(field.nullable) %><% if (field.default !== null) {%>, default: <%= field.default %><% } %> })
3
+ @Column({ "type": "interval", nullable: <%= Boolean(field.nullable) %><% if (field.default !== null) {%>, default: <%= field.default %><% } %><% if (field.defaultSql) { %>, default: () => <%~ JSON.stringify(field.defaultSql) %><% } %> })
4
4
  <% if (field.index ) {%>
5
5
  @Index()
6
6
  <% } %>
7
7
  <% if (field.primary ) {%>
8
- @PrimaryColumn()
8
+ @PrimaryColumn(<% if (field.primaryKeyName) { %>{ primaryKeyConstraintName: '<%= field.primaryKeyName %>' }<% } %>)
9
9
  <% } %>
10
10
 
11
11
  <%= field.name %>: string;
@@ -1,6 +1,6 @@
1
1
  <% const {field} = it; %>
2
2
 
3
- @Column('json',{ nullable: <%= Boolean(field.nullable) %> })
3
+ @Column('json',{ nullable: <%= Boolean(field.nullable) %><% if (field.defaultSql) { %>, default: () => <%~ JSON.stringify(field.defaultSql) %><% } %> })
4
4
  <% if (field.index ) {%>
5
5
  @Index()
6
6
  <% } %>
@@ -1,5 +1,5 @@
1
1
  <% const {field} = it; %>
2
2
 
3
- @Column('jsonb', { nullable: <%= Boolean(field.nullable) %> })
3
+ @Column('jsonb', { nullable: <%= Boolean(field.nullable) %><% if (field.defaultSql) { %>, default: () => <%~ JSON.stringify(field.defaultSql) %><% } %> })
4
4
 
5
5
  <%= field.name %>: JSON;
@@ -1,5 +1,5 @@
1
1
  <% const {field} = it; %>
2
2
 
3
- @Column('jsonb', { nullable: <%= Boolean(field.nullable) %> })
3
+ @Column('jsonb', { nullable: <%= Boolean(field.nullable) %><% if (field.defaultSql) { %>, default: () => <%~ JSON.stringify(field.defaultSql) %><% } %> })
4
4
 
5
5
  <%= field.name %>: any;
@@ -31,7 +31,7 @@
31
31
  @Index()
32
32
  <% } %>
33
33
  <% if (field.primary ) {%>
34
- @PrimaryColumn()
34
+ @PrimaryColumn(<% if (field.primaryKeyName) { %>{ primaryKeyConstraintName: '<%= field.primaryKeyName %>' }<% } %>)
35
35
  <% } %>
36
36
 
37
37
  <%= field.name %>: { coordinates: Array<{ x: number, y: number }> };
@@ -1,11 +1,11 @@
1
1
  <% const {field} = it; %>
2
2
 
3
- @Column({ "type": "money", nullable: <%= Boolean(field.nullable) %><% if (field.default !== null) {%>, default: <%= field.default %><% } %> })
3
+ @Column({ "type": "money", nullable: <%= Boolean(field.nullable) %><% if (field.default !== null) {%>, default: <%= field.default %><% } %><% if (field.defaultSql) { %>, default: () => <%~ JSON.stringify(field.defaultSql) %><% } %> })
4
4
  <% if (field.index ) {%>
5
5
  @Index()
6
6
  <% } %>
7
7
  <% if (field.primary ) {%>
8
- @PrimaryColumn()
8
+ @PrimaryColumn(<% if (field.primaryKeyName) { %>{ primaryKeyConstraintName: '<%= field.primaryKeyName %>' }<% } %>)
9
9
  <% } %>
10
10
 
11
11
  <%= field.name %>: string;
@@ -38,7 +38,7 @@
38
38
  @Index()
39
39
  <% } %>
40
40
  <% if (field.primary ) {%>
41
- @PrimaryColumn()
41
+ @PrimaryColumn(<% if (field.primaryKeyName) { %>{ primaryKeyConstraintName: '<%= field.primaryKeyName %>' }<% } %>)
42
42
  <% } %>
43
43
 
44
44
  <%= field.name %>: { coordinates: Array<Array<{ x: number, y: number }>> };
@@ -31,7 +31,7 @@
31
31
  @Index()
32
32
  <% } %>
33
33
  <% if (field.primary ) {%>
34
- @PrimaryColumn()
34
+ @PrimaryColumn(<% if (field.primaryKeyName) { %>{ primaryKeyConstraintName: '<%= field.primaryKeyName %>' }<% } %>)
35
35
  <% } %>
36
36
 
37
37
  <%= field.name %>: { coordinates: Array<{ x: number, y: number }> };
@@ -44,7 +44,7 @@
44
44
  @Index()
45
45
  <% } %>
46
46
  <% if (field.primary ) {%>
47
- @PrimaryColumn()
47
+ @PrimaryColumn(<% if (field.primaryKeyName) { %>{ primaryKeyConstraintName: '<%= field.primaryKeyName %>' }<% } %>)
48
48
  <% } %>
49
49
 
50
50
  <%= field.name %>: { coordinates: Array<Array<Array<{ x: number, y: number }>>> };
@@ -1,11 +1,11 @@
1
1
  <% const {field} = it; %>
2
2
 
3
- @Column({ "type": "numeric", precision: <%= field.precision || 10 %>, scale: <%= field.scale || 2 %>, nullable: <%= Boolean(field.nullable) %><% if (field.default !== null) {%>, default: <%= field.default %><% } %> })
3
+ @Column({ "type": "numeric", precision: <%= field.precision || 10 %>, scale: <%= field.scale || 2 %>, nullable: <%= Boolean(field.nullable) %><% if (field.default !== null) {%>, default: <%= field.default %><% } %><% if (field.defaultSql) { %>, default: () => <%~ JSON.stringify(field.defaultSql) %><% } %> })
4
4
  <% if (field.index ) {%>
5
5
  @Index()
6
6
  <% } %>
7
7
  <% if (field.primary ) {%>
8
- @PrimaryColumn()
8
+ @PrimaryColumn(<% if (field.primaryKeyName) { %>{ primaryKeyConstraintName: '<%= field.primaryKeyName %>' }<% } %>)
9
9
  <% } %>
10
10
 
11
11
  <%= field.name %>: number;
@@ -19,7 +19,7 @@
19
19
  @Index()
20
20
  <% } %>
21
21
  <% if (field.primary ) {%>
22
- @PrimaryColumn()
22
+ @PrimaryColumn(<% if (field.primaryKeyName) { %>{ primaryKeyConstraintName: '<%= field.primaryKeyName %>' }<% } %>)
23
23
  <% } %>
24
24
 
25
25
  <%= field.name %>: { x: number, y: number };
@@ -38,7 +38,7 @@
38
38
  @Index()
39
39
  <% } %>
40
40
  <% if (field.primary ) {%>
41
- @PrimaryColumn()
41
+ @PrimaryColumn(<% if (field.primaryKeyName) { %>{ primaryKeyConstraintName: '<%= field.primaryKeyName %>' }<% } %>)
42
42
  <% } %>
43
43
 
44
44
  <%= field.name %>: { coordinates: Array<Array<{ x: number, y: number }>> };
@@ -1,11 +1,11 @@
1
1
  <% const {field} = it; %>
2
2
 
3
- @Column({ "type": "real", nullable: <%= Boolean(field.nullable) %><% if (field.default !== null) {%>, default: <%= field.default %><% } %> })
3
+ @Column({ "type": "real", nullable: <%= Boolean(field.nullable) %><% if (field.default !== null) {%>, default: <%= field.default %><% } %><% if (field.defaultSql) { %>, default: () => <%~ JSON.stringify(field.defaultSql) %><% } %> })
4
4
  <% if (field.index ) {%>
5
5
  @Index()
6
6
  <% } %>
7
7
  <% if (field.primary ) {%>
8
- @PrimaryColumn()
8
+ @PrimaryColumn(<% if (field.primaryKeyName) { %>{ primaryKeyConstraintName: '<%= field.primaryKeyName %>' }<% } %>)
9
9
  <% } %>
10
10
 
11
11
  <%= field.name %>: number;