@apso/cli 0.51.0 → 0.53.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 (98) hide show
  1. package/dist/commands/generate.js +3 -2
  2. package/dist/commands/import/supabase.js +31 -6
  3. package/dist/commands/init.d.ts +9 -0
  4. package/dist/commands/init.js +31 -1
  5. package/dist/commands/mcp/serve.js +23 -2
  6. package/dist/lib/apsorc-parser.d.ts +13 -1
  7. package/dist/lib/apsorc-parser.js +47 -4
  8. package/dist/lib/ddl/catalog.js +5 -2
  9. package/dist/lib/ddl/change.js +13 -2
  10. package/dist/lib/ddl/index.d.ts +62 -3
  11. package/dist/lib/ddl/index.js +211 -40
  12. package/dist/lib/generators/go.js +17 -3
  13. package/dist/lib/generators/python.js +17 -3
  14. package/dist/lib/generators/typescript.d.ts +2 -1
  15. package/dist/lib/generators/typescript.js +87 -13
  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/templates/entities/entity-col-array.eta +2 -1
  27. package/dist/lib/templates/entities/entity-col-bigint.eta +2 -2
  28. package/dist/lib/templates/entities/entity-col-bigserial.eta +2 -2
  29. package/dist/lib/templates/entities/entity-col-boolean.eta +1 -1
  30. package/dist/lib/templates/entities/entity-col-bytea.eta +2 -2
  31. package/dist/lib/templates/entities/entity-col-char.eta +4 -3
  32. package/dist/lib/templates/entities/entity-col-date.eta +6 -2
  33. package/dist/lib/templates/entities/entity-col-datetime.eta +8 -1
  34. package/dist/lib/templates/entities/entity-col-decimal.eta +2 -2
  35. package/dist/lib/templates/entities/entity-col-double.eta +2 -2
  36. package/dist/lib/templates/entities/entity-col-float.eta +1 -1
  37. package/dist/lib/templates/entities/entity-col-geography.eta +1 -1
  38. package/dist/lib/templates/entities/entity-col-geometry.eta +1 -1
  39. package/dist/lib/templates/entities/entity-col-geometrycollection.eta +1 -1
  40. package/dist/lib/templates/entities/entity-col-inet.eta +2 -2
  41. package/dist/lib/templates/entities/entity-col-int4range.eta +1 -1
  42. package/dist/lib/templates/entities/entity-col-integer.eta +2 -2
  43. package/dist/lib/templates/entities/entity-col-interval.eta +2 -2
  44. package/dist/lib/templates/entities/entity-col-json-plain.eta +1 -1
  45. package/dist/lib/templates/entities/entity-col-json.eta +1 -1
  46. package/dist/lib/templates/entities/entity-col-jsonb.eta +1 -1
  47. package/dist/lib/templates/entities/entity-col-linestring.eta +1 -1
  48. package/dist/lib/templates/entities/entity-col-money.eta +2 -2
  49. package/dist/lib/templates/entities/entity-col-multilinestring.eta +1 -1
  50. package/dist/lib/templates/entities/entity-col-multipoint.eta +1 -1
  51. package/dist/lib/templates/entities/entity-col-multipolygon.eta +1 -1
  52. package/dist/lib/templates/entities/entity-col-numeric.eta +2 -2
  53. package/dist/lib/templates/entities/entity-col-point.eta +1 -1
  54. package/dist/lib/templates/entities/entity-col-polygon.eta +1 -1
  55. package/dist/lib/templates/entities/entity-col-real.eta +2 -2
  56. package/dist/lib/templates/entities/entity-col-serial.eta +2 -2
  57. package/dist/lib/templates/entities/entity-col-smallint.eta +2 -2
  58. package/dist/lib/templates/entities/entity-col-smallserial.eta +2 -2
  59. package/dist/lib/templates/entities/entity-col-string.eta +2 -2
  60. package/dist/lib/templates/entities/entity-col-text.eta +4 -3
  61. package/dist/lib/templates/entities/entity-col-time.eta +2 -2
  62. package/dist/lib/templates/entities/entity-col-timestamp.eta +8 -1
  63. package/dist/lib/templates/entities/entity-col-timestamptz.eta +8 -1
  64. package/dist/lib/templates/entities/entity-col-timetz.eta +2 -2
  65. package/dist/lib/templates/entities/entity-col-tsvector.eta +2 -2
  66. package/dist/lib/templates/entities/entity-col-uuid.eta +5 -2
  67. package/dist/lib/templates/entities/entity-col-varchar.eta +4 -3
  68. package/dist/lib/templates/entities/entity-col-xml.eta +2 -2
  69. package/dist/lib/templates/entities/entity.eta +30 -18
  70. package/dist/lib/templates/go/models/model.eta +3 -3
  71. package/dist/lib/templates/python/models/model.eta +1 -1
  72. package/dist/lib/templates/rest/controller-rest.eta +25 -7
  73. package/dist/lib/templates/rest/dto-rest.eta +2 -2
  74. package/dist/lib/templates/rest/index-module-rest.eta +10 -0
  75. package/dist/lib/templates/rest/schema-extras-module.eta +24 -0
  76. package/dist/lib/types/constraints.d.ts +13 -0
  77. package/dist/lib/types/entity.d.ts +67 -2
  78. package/dist/lib/types/entity.js +39 -1
  79. package/dist/lib/types/field.d.ts +20 -2
  80. package/dist/lib/types/generator.d.ts +16 -0
  81. package/dist/lib/types/index.d.ts +1 -1
  82. package/dist/lib/types/indices.d.ts +21 -0
  83. package/dist/lib/types/relationship.d.ts +33 -0
  84. package/dist/lib/types/relationship.js +13 -0
  85. package/dist/lib/utils/field.d.ts +22 -0
  86. package/dist/lib/utils/field.js +62 -3
  87. package/dist/lib/utils/relationships/index.d.ts +1 -1
  88. package/dist/lib/utils/relationships/index.js +2 -1
  89. package/dist/lib/utils/relationships/parse.d.ts +11 -0
  90. package/dist/lib/utils/relationships/parse.js +44 -1
  91. package/dist/lib/utils/template.d.ts +3 -3
  92. package/dist/lib/utils/template.js +4 -4
  93. package/dist/lib/verify/crud-plan.d.ts +2 -0
  94. package/dist/lib/verify/crud-plan.js +19 -5
  95. package/dist/lib/verify/index.js +32 -3
  96. package/npm-shrinkwrap.json +72 -87
  97. package/oclif.manifest.json +7 -1
  98. package/package.json +3 -2
@@ -17,6 +17,8 @@ const fs = tslib_1.__importStar(require("fs"));
17
17
  const path = tslib_1.__importStar(require("path"));
18
18
  const paths_1 = require("../config/paths");
19
19
  const snapshot_1 = require("./snapshot");
20
+ const entity_1 = require("../types/entity");
21
+ const relationship_1 = require("../types/relationship");
20
22
  const field_1 = require("../utils/field");
21
23
  const casing_1 = require("../utils/casing");
22
24
  const relationships_1 = require("../utils/relationships");
@@ -87,10 +89,16 @@ function buildEntityClasses(entities, relationshipMap = {}) {
87
89
  }
88
90
  }
89
91
  if (entityDef.created_at) {
90
- typeorm.CreateDateColumn()(EntityClass.prototype, "created_at");
92
+ typeorm.CreateDateColumn({
93
+ type: (0, entity_1.timestampTypeOf)(entityDef, "created_at"),
94
+ nullable: (0, entity_1.timestampNullableOf)(entityDef, "created_at"),
95
+ })(EntityClass.prototype, "created_at");
91
96
  }
92
97
  if (entityDef.updated_at) {
93
- typeorm.UpdateDateColumn()(EntityClass.prototype, "updated_at");
98
+ typeorm.UpdateDateColumn({
99
+ type: (0, entity_1.timestampTypeOf)(entityDef, "updated_at"),
100
+ nullable: (0, entity_1.timestampNullableOf)(entityDef, "updated_at"),
101
+ })(EntityClass.prototype, "updated_at");
94
102
  }
95
103
  const fields = entityDef.fields || [];
96
104
  for (const field of fields) {
@@ -108,7 +116,8 @@ function buildEntityClasses(entities, relationshipMap = {}) {
108
116
  if (field.unique)
109
117
  colOpts.unique = true;
110
118
  if (field.default !== undefined && field.default !== null) {
111
- colOpts.default = field.default;
119
+ const sql = (0, field_1.defaultSqlOf)(field);
120
+ colOpts.default = sql === undefined ? field.default : () => sql;
112
121
  }
113
122
  if (field.type === "enum" && field.values) {
114
123
  colOpts.enum = field.values;
@@ -145,8 +154,8 @@ function buildEntityClasses(entities, relationshipMap = {}) {
145
154
  if (relationship.nullable !== undefined) {
146
155
  relationOptions.nullable = relationship.nullable;
147
156
  }
148
- if (relationship.cascadeDelete) {
149
- relationOptions.onDelete = "CASCADE";
157
+ if ((0, relationship_1.onDeleteOf)(relationship)) {
158
+ relationOptions.onDelete = (0, relationship_1.onDeleteOf)(relationship);
150
159
  }
151
160
  if (relationship.type === "ManyToOne") {
152
161
  if (relationship.index) {
@@ -156,7 +165,9 @@ function buildEntityClasses(entities, relationshipMap = {}) {
156
165
  ? (target) => target[inversePropertyName]
157
166
  : undefined;
158
167
  typeorm.ManyToOne(() => targetClass, inverseSide, relationOptions)(EntityClass.prototype, relationship.relationshipName);
159
- typeorm.JoinColumn({ name: relationship.camelCasedId })(EntityClass.prototype, relationship.relationshipName);
168
+ typeorm.JoinColumn({
169
+ name: relationship.joinColumnName || relationship.camelCasedId,
170
+ })(EntityClass.prototype, relationship.relationshipName);
160
171
  }
161
172
  if (relationship.type === "OneToMany" && relationship.biDirectional) {
162
173
  typeorm.OneToMany(() => targetClass, (target) => target[inversePropertyName])(EntityClass.prototype, relationship.pluralizedRelationshipName);
@@ -303,6 +314,8 @@ async function runMigrationSandbox(current, projectDir) {
303
314
  primaryKeyType: e.primaryKeyType,
304
315
  created_at: e.created_at,
305
316
  updated_at: e.updated_at,
317
+ timestampType: e.timestampType,
318
+ timestampNullable: e.timestampNullable,
306
319
  scopeBy: e.scopeBy,
307
320
  });
308
321
  }),
@@ -337,6 +350,8 @@ async function runMigrationSandbox(current, projectDir) {
337
350
  primaryKeyType: se.primaryKeyType,
338
351
  created_at: se.created_at,
339
352
  updated_at: se.updated_at,
353
+ timestampType: se.timestampType,
354
+ timestampNullable: se.timestampNullable,
340
355
  scopeBy: se.scopeBy,
341
356
  });
342
357
  })
@@ -435,6 +450,8 @@ function applyMigration(current, projectDir) {
435
450
  primaryKeyType: e.primaryKeyType,
436
451
  created_at: e.created_at,
437
452
  updated_at: e.updated_at,
453
+ timestampType: e.timestampType,
454
+ timestampNullable: e.timestampNullable,
438
455
  scopeBy: e.scopeBy,
439
456
  });
440
457
  }),
@@ -5,6 +5,7 @@
5
5
  * The snapshot stores the .apsorc content at the time of last successful migration.
6
6
  * Comparing current .apsorc against the snapshot detects whether a migration is needed.
7
7
  */
8
+ import { Entity } from "../types/entity";
8
9
  /**
9
10
  * Shape of the stored snapshot (mirrors the parsed .apsorc structure)
10
11
  */
@@ -22,6 +23,8 @@ export interface ApsorcSnapshot {
22
23
  primaryKeyType?: string;
23
24
  created_at?: boolean;
24
25
  updated_at?: boolean;
26
+ timestampType?: Entity["timestampType"];
27
+ timestampNullable?: Entity["timestampNullable"];
25
28
  scopeBy?: string | string[];
26
29
  }>;
27
30
  relationships?: Array<{
@@ -55,6 +58,8 @@ export interface ComparableSchema {
55
58
  primaryKeyType?: string;
56
59
  created_at?: boolean;
57
60
  updated_at?: boolean;
61
+ timestampType?: Entity["timestampType"];
62
+ timestampNullable?: Entity["timestampNullable"];
58
63
  scopeBy?: string | string[];
59
64
  }>;
60
65
  relationships?: ApsorcSnapshot["relationships"];
@@ -3,8 +3,11 @@ interface PlanField {
3
3
  type: string;
4
4
  values?: string[];
5
5
  nullable?: boolean;
6
- default?: string | null;
6
+ /** A literal, or { sql } for an expression; the plan only asks whether one is set. */
7
+ default?: unknown;
7
8
  elementType?: string;
9
+ /** The expression of a stored generated column. */
10
+ generated?: string;
8
11
  }
9
12
  interface PlanEntity {
10
13
  name: string;
@@ -147,7 +147,8 @@ function planMigration(before, after, previous) {
147
147
  });
148
148
  continue;
149
149
  }
150
- if (!sameType(cur, old)) {
150
+ // Postgres rebuilds a generated column from its expression: no cast.
151
+ if (!sameType(cur, old) && !cur.generated) {
151
152
  questions.push({
152
153
  id: `cast:${now.name}.${old.name}`,
153
154
  kind: "cast",
@@ -168,7 +169,10 @@ function planMigration(before, after, previous) {
168
169
  });
169
170
  }
170
171
  }
171
- if (old.nullable && !cur.nullable && cur.default === undefined) {
172
+ if (old.nullable &&
173
+ !cur.nullable &&
174
+ cur.default === undefined &&
175
+ !cur.generated) {
172
176
  questions.push({
173
177
  id: `backfill:${now.name}.${old.name}`,
174
178
  kind: "backfill",
@@ -222,7 +226,9 @@ function planMigration(before, after, previous) {
222
226
  for (const f of fieldsOf(now)) {
223
227
  if (byName(fieldsOf(was), f.name) ||
224
228
  f.nullable ||
225
- f.default !== undefined)
229
+ f.default !== undefined ||
230
+ // Postgres computes a generated column for the existing rows.
231
+ f.generated)
226
232
  continue;
227
233
  const key = `${now.name}.${f.name}`;
228
234
  if (claimed.has(key) || pending.has(key))
@@ -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;
@@ -1,12 +1,12 @@
1
1
  <% const {field} = it; %>
2
2
 
3
- @Column({ "type": "int" })
3
+ @Column({ "type": "int"<% 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 %>: number;
@@ -1,11 +1,11 @@
1
1
  <% const {field} = it; %>
2
2
 
3
- @Column({ "type": "smallint", nullable: <%= Boolean(field.nullable) %><% if (field.default !== null) {%>, default: <%= field.default %><% } %> })
3
+ @Column({ "type": "smallint", 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,12 +1,12 @@
1
1
  <% const {field} = it; %>
2
2
 
3
- @Column({ "type": "smallint" })
3
+ @Column({ "type": "smallint"<% 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 %>: number;
@@ -15,9 +15,9 @@
15
15
  <% if (field.index ) {%>
16
16
  @Index()
17
17
  <% } %>
18
- @Column({ type: "text", nullable: <%= Boolean(field.nullable) %><% if (field.unique) {%>, unique: true <% } %><% if (field.default !== null) {%>, default: '<%= field.default %>'<% } %> })
18
+ @Column({ type: "text", nullable: <%= Boolean(field.nullable) %><% if (field.unique) {%>, unique: true <% } %><% if (field.default !== null) {%>, default: '<%= field.default %>'<% } %><% if (field.defaultSql) { %>, default: () => <%~ JSON.stringify(field.defaultSql) %><% } %> })
19
19
  <% if (field.primary ) {%>
20
- @PrimaryColumn()
20
+ @PrimaryColumn(<% if (field.primaryKeyName) { %>{ primaryKeyConstraintName: '<%= field.primaryKeyName %>' }<% } %>)
21
21
  <% } %>
22
22
 
23
23
  <%= field.name %>: <%= field.dataType %>;
@@ -15,9 +15,10 @@
15
15
  <% if (field.index ) {%>
16
16
  @Index()
17
17
  <% } %>
18
- @Column({ type: "text", nullable: <%= Boolean(field.nullable) %><% if (field.unique) {%>, unique: true <% } %><% if (field.default !== null) {%>, default: '<%= field.default %>'<% } %> })
19
- <% if (field.primary ) {%>
20
- @PrimaryColumn()
18
+ <% if (field.primary) { %>
19
+ @PrimaryColumn({ type: "text"<% if (field.primaryKeyName) { %>, primaryKeyConstraintName: '<%= field.primaryKeyName %>'<% } %> })
20
+ <% } else { %>
21
+ @Column({ type: "text", nullable: <%= Boolean(field.nullable) %><% if (field.unique) {%>, unique: true <% } %><% if (field.default !== null) {%>, default: '<%= field.default %>'<% } %><% if (field.defaultSql) { %>, default: () => <%~ JSON.stringify(field.defaultSql) %><% } %> })
21
22
  <% } %>
22
23
 
23
24
  <%= field.name %>: <%= field.dataType %>;
@@ -1,11 +1,11 @@
1
1
  <% const {field} = it; %>
2
2
 
3
- @Column({ "type": "time", nullable: <%= Boolean(field.nullable) %><% if (field.default !== null) {%>, default: <%= field.default %><% } %> })
3
+ @Column({ "type": "time", 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;