@contember/schema-migrations 2.0.0-beta.1 → 2.0.0-beta.3
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/development/index.cjs +1 -0
- package/dist/development/index.cjs.map +1 -1
- package/dist/development/index.js +2 -1
- package/dist/development/src/modifications/ModificationVersions.cjs +3 -1
- package/dist/development/src/modifications/ModificationVersions.cjs.map +1 -1
- package/dist/development/src/modifications/ModificationVersions.js +3 -1
- package/dist/development/src/modifications/ModificationVersions.js.map +1 -1
- package/dist/development/src/modifications/entities/CreateEntityModification.cjs +3 -1
- package/dist/development/src/modifications/entities/CreateEntityModification.cjs.map +1 -1
- package/dist/development/src/modifications/entities/CreateEntityModification.js +3 -1
- package/dist/development/src/modifications/entities/CreateEntityModification.js.map +1 -1
- package/dist/production/index.cjs +1 -0
- package/dist/production/index.cjs.map +1 -1
- package/dist/production/index.js +2 -1
- package/dist/production/src/modifications/ModificationVersions.cjs +3 -1
- package/dist/production/src/modifications/ModificationVersions.cjs.map +1 -1
- package/dist/production/src/modifications/ModificationVersions.js +3 -1
- package/dist/production/src/modifications/ModificationVersions.js.map +1 -1
- package/dist/production/src/modifications/entities/CreateEntityModification.cjs +3 -1
- package/dist/production/src/modifications/entities/CreateEntityModification.cjs.map +1 -1
- package/dist/production/src/modifications/entities/CreateEntityModification.js +3 -1
- package/dist/production/src/modifications/entities/CreateEntityModification.js.map +1 -1
- package/dist/tests/tsconfig.tsbuildinfo +1 -1
- package/dist/types/modifications/ModificationVersions.d.ts +2 -1
- package/dist/types/modifications/ModificationVersions.d.ts.map +1 -1
- package/dist/types/modifications/entities/CreateEntityModification.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +7 -7
- package/src/modifications/ModificationVersions.ts +2 -1
- package/src/modifications/entities/CreateEntityModification.ts +5 -1
- package/tests/cases/integration/createEntity.test.ts +51 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@contember/schema-migrations",
|
|
3
|
-
"version": "2.0.0-beta.
|
|
3
|
+
"version": "2.0.0-beta.3",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"main": "./dist/production/index.js",
|
|
6
6
|
"typings": "./dist/types/index.d.ts",
|
|
@@ -23,16 +23,16 @@
|
|
|
23
23
|
}
|
|
24
24
|
},
|
|
25
25
|
"dependencies": {
|
|
26
|
-
"@contember/database": "2.0.0-beta.
|
|
27
|
-
"@contember/database-migrations": "2.0.0-beta.
|
|
28
|
-
"@contember/engine-common": "2.0.0-beta.
|
|
29
|
-
"@contember/schema": "2.0.0-beta.
|
|
30
|
-
"@contember/schema-utils": "2.0.0-beta.
|
|
26
|
+
"@contember/database": "2.0.0-beta.3",
|
|
27
|
+
"@contember/database-migrations": "2.0.0-beta.3",
|
|
28
|
+
"@contember/engine-common": "2.0.0-beta.3",
|
|
29
|
+
"@contember/schema": "2.0.0-beta.3",
|
|
30
|
+
"@contember/schema-utils": "2.0.0-beta.3",
|
|
31
31
|
"fast-deep-equal": "^3.1.3",
|
|
32
32
|
"rfc6902": "^5.1.1"
|
|
33
33
|
},
|
|
34
34
|
"devDependencies": {
|
|
35
|
-
"@contember/schema-definition": "2.0.0-beta.
|
|
35
|
+
"@contember/schema-definition": "2.0.0-beta.3"
|
|
36
36
|
},
|
|
37
37
|
"peerDependencies": {
|
|
38
38
|
"pg": "^8.9.0"
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export const VERSION_INITIAL = 1
|
|
2
|
-
export const VERSION_LATEST =
|
|
2
|
+
export const VERSION_LATEST = 6
|
|
3
3
|
|
|
4
4
|
export const VERSION_ACL_PATCH = 2
|
|
5
5
|
export const VERSION_UPDATE_CONSTRAINT_FIELDS = 2
|
|
@@ -7,3 +7,4 @@ export const VERSION_REMOVE_RELATION_INVERSE_SIDE = 3
|
|
|
7
7
|
export const VERSION_REMOVE_REFERENCING_RELATIONS = 3
|
|
8
8
|
export const _REMOVED_VERSION_UPDATE_CONSTRAINT_NAME_ONE_HAS_ONE = 4
|
|
9
9
|
export const VERSION_UPDATE_INDEX_FIELDS = 5
|
|
10
|
+
export const VERSION_CORRECT_PRIMARY_COLUMN_NAME = 6
|
|
@@ -10,6 +10,7 @@ import {
|
|
|
10
10
|
import { createEventTrigger, createEventTrxTrigger } from '../utils/sqlUpdateUtils'
|
|
11
11
|
import { PossibleEntityShapeInMigrations } from '../../utils/PartialEntity.js'
|
|
12
12
|
import { getColumnSqlType } from '../utils/columnUtils'
|
|
13
|
+
import { VERSION_CORRECT_PRIMARY_COLUMN_NAME } from '../ModificationVersions'
|
|
13
14
|
|
|
14
15
|
export class CreateEntityModificationHandler implements ModificationHandler<CreateEntityModificationData> {
|
|
15
16
|
constructor(
|
|
@@ -27,8 +28,11 @@ export class CreateEntityModificationHandler implements ModificationHandler<Crea
|
|
|
27
28
|
}
|
|
28
29
|
const primaryColumn = entity.fields[entity.primary] as Model.AnyColumn
|
|
29
30
|
|
|
31
|
+
const primaryColumnName = this.options.formatVersion >= VERSION_CORRECT_PRIMARY_COLUMN_NAME
|
|
32
|
+
? primaryColumn.columnName
|
|
33
|
+
: primaryColumn.name
|
|
30
34
|
builder.createTable(entity.tableName, {
|
|
31
|
-
[
|
|
35
|
+
[primaryColumnName]: {
|
|
32
36
|
primaryKey: true,
|
|
33
37
|
type: getColumnSqlType(primaryColumn),
|
|
34
38
|
notNull: true,
|
|
@@ -148,3 +148,54 @@ describe('create a view', () => testMigrations({
|
|
|
148
148
|
],
|
|
149
149
|
sql: SQL`CREATE VIEW "author" AS SELECT null as id, 'John' AS name;`,
|
|
150
150
|
}))
|
|
151
|
+
|
|
152
|
+
namespace SchemaWithCustomIdName {
|
|
153
|
+
export class Author {
|
|
154
|
+
id = def.uuidColumn().notNull().columnName('author_id')
|
|
155
|
+
name = def.stringColumn()
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
describe('custom primary key name', () => testMigrations({
|
|
159
|
+
original: {},
|
|
160
|
+
updated: createSchema(SchemaWithCustomIdName),
|
|
161
|
+
diff: [
|
|
162
|
+
{
|
|
163
|
+
modification: 'createEntity',
|
|
164
|
+
entity: {
|
|
165
|
+
fields: {
|
|
166
|
+
id: {
|
|
167
|
+
columnName: 'author_id',
|
|
168
|
+
name: 'id',
|
|
169
|
+
nullable: false,
|
|
170
|
+
type: Model.ColumnType.Uuid,
|
|
171
|
+
columnType: 'uuid',
|
|
172
|
+
},
|
|
173
|
+
},
|
|
174
|
+
name: 'Author',
|
|
175
|
+
primary: 'id',
|
|
176
|
+
primaryColumn: 'author_id',
|
|
177
|
+
tableName: 'author',
|
|
178
|
+
unique: [],
|
|
179
|
+
eventLog: {
|
|
180
|
+
enabled: true,
|
|
181
|
+
},
|
|
182
|
+
indexes: [],
|
|
183
|
+
},
|
|
184
|
+
},
|
|
185
|
+
{
|
|
186
|
+
modification: 'createColumn',
|
|
187
|
+
entityName: 'Author',
|
|
188
|
+
field: {
|
|
189
|
+
columnName: 'name',
|
|
190
|
+
name: 'name',
|
|
191
|
+
nullable: true,
|
|
192
|
+
type: Model.ColumnType.String,
|
|
193
|
+
columnType: 'text',
|
|
194
|
+
},
|
|
195
|
+
},
|
|
196
|
+
],
|
|
197
|
+
sql: SQL`CREATE TABLE "author" ( "author_id" uuid PRIMARY KEY NOT NULL );
|
|
198
|
+
CREATE TRIGGER "log_event" AFTER INSERT OR UPDATE OR DELETE ON "author" FOR EACH ROW EXECUTE PROCEDURE "system"."trigger_event"($pga$author_id$pga$);
|
|
199
|
+
CREATE CONSTRAINT TRIGGER "log_event_trx" AFTER INSERT OR UPDATE OR DELETE ON "author" DEFERRABLE INITIALLY DEFERRED FOR EACH ROW EXECUTE PROCEDURE "system"."trigger_event_commit"();
|
|
200
|
+
ALTER TABLE "author" ADD "name" text;`,
|
|
201
|
+
}))
|