@contember/schema-migrations 2.0.0 → 2.1.0-alpha.1
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/src/modifications/columns/UpdateColumnDefinitionModification.cjs +5 -2
- package/dist/development/src/modifications/columns/UpdateColumnDefinitionModification.cjs.map +1 -1
- package/dist/development/src/modifications/columns/UpdateColumnDefinitionModification.js +5 -2
- package/dist/development/src/modifications/columns/UpdateColumnDefinitionModification.js.map +1 -1
- package/dist/development/src/modifications/utils/columnUtils.cjs +1 -1
- package/dist/development/src/modifications/utils/columnUtils.cjs.map +1 -1
- package/dist/development/src/modifications/utils/columnUtils.js +1 -1
- package/dist/development/src/modifications/utils/columnUtils.js.map +1 -1
- package/dist/production/src/modifications/columns/UpdateColumnDefinitionModification.cjs +5 -2
- package/dist/production/src/modifications/columns/UpdateColumnDefinitionModification.cjs.map +1 -1
- package/dist/production/src/modifications/columns/UpdateColumnDefinitionModification.js +5 -2
- package/dist/production/src/modifications/columns/UpdateColumnDefinitionModification.js.map +1 -1
- package/dist/production/src/modifications/utils/columnUtils.cjs +1 -1
- package/dist/production/src/modifications/utils/columnUtils.cjs.map +1 -1
- package/dist/production/src/modifications/utils/columnUtils.js +1 -1
- package/dist/production/src/modifications/utils/columnUtils.js.map +1 -1
- package/dist/tests/tsconfig.tsbuildinfo +1 -1
- package/dist/types/modifications/columns/UpdateColumnDefinitionModification.d.ts.map +1 -1
- package/dist/types/modifications/utils/columnUtils.d.ts +1 -1
- package/dist/types/modifications/utils/columnUtils.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +7 -7
- package/src/modifications/columns/UpdateColumnDefinitionModification.ts +5 -2
- package/src/modifications/utils/columnUtils.ts +6 -3
- package/tests/cases/integration/createColumn.test.ts +27 -0
- package/tests/cases/integration/updateColumnDefinition.test.ts +27 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@contember/schema-migrations",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.1.0-alpha.1",
|
|
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.
|
|
27
|
-
"@contember/database-migrations": "2.0.
|
|
28
|
-
"@contember/engine-common": "2.0.
|
|
29
|
-
"@contember/schema": "2.0.
|
|
30
|
-
"@contember/schema-utils": "2.0.
|
|
26
|
+
"@contember/database": "2.1.0-alpha.1",
|
|
27
|
+
"@contember/database-migrations": "2.1.0-alpha.1",
|
|
28
|
+
"@contember/engine-common": "2.1.0-alpha.1",
|
|
29
|
+
"@contember/schema": "2.1.0-alpha.1",
|
|
30
|
+
"@contember/schema-utils": "2.1.0-alpha.1",
|
|
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.
|
|
35
|
+
"@contember/schema-definition": "2.1.0-alpha.1"
|
|
36
36
|
},
|
|
37
37
|
"peerDependencies": {
|
|
38
38
|
"pg": "^8.9.0"
|
|
@@ -20,11 +20,14 @@ export class UpdateColumnDefinitionModificationHandler implements ModificationHa
|
|
|
20
20
|
const newColumn = this.data.definition
|
|
21
21
|
|
|
22
22
|
const hasNewSequence = !oldColumn.sequence && newColumn.sequence
|
|
23
|
-
const
|
|
23
|
+
const oldColumnType = getColumnSqlType(oldColumn)
|
|
24
24
|
const columnType = getColumnSqlType(newColumn)
|
|
25
|
+
const hasNewType = columnType !== oldColumnType
|
|
25
26
|
const hasNullableChanged = oldColumn.nullable !== newColumn.nullable
|
|
26
27
|
|
|
27
|
-
const
|
|
28
|
+
const columnNameWrapped = wrapIdentifier(oldColumn.columnName)
|
|
29
|
+
const isChangedToArray = !oldColumn.list && newColumn.list
|
|
30
|
+
const usingCast = (isChangedToArray ? `ARRAY[${columnNameWrapped}]` : columnNameWrapped) + `::${columnType}`
|
|
28
31
|
|
|
29
32
|
const seedExpression = formatSeedExpression({
|
|
30
33
|
model: this.schema.model,
|
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
import { Model } from '@contember/schema'
|
|
2
2
|
|
|
3
|
-
export const getColumnSqlType = (column: Pick<Model.AnyColumn, 'type' | 'columnType'>) =>
|
|
4
|
-
|
|
5
|
-
|
|
3
|
+
export const getColumnSqlType = (column: Pick<Model.AnyColumn, 'type' | 'columnType' | 'list'>) =>
|
|
4
|
+
(column.type === Model.ColumnType.Enum
|
|
5
|
+
? `"${column.columnType}"`
|
|
6
|
+
: column.columnType
|
|
7
|
+
)
|
|
8
|
+
+ (column.list ? '[]' : '')
|
|
@@ -172,3 +172,30 @@ ALTER "active" SET NOT NULL; ALTER TABLE "author" ADD "created_at" timestamptz;
|
|
|
172
172
|
ALTER TABLE "author" ALTER "created_at" SET DATA TYPE timestamptz USING $pga$2024-01-01 10:00$pga$, ALTER "created_at" SET NOT NULL;
|
|
173
173
|
`,
|
|
174
174
|
}))
|
|
175
|
+
|
|
176
|
+
describe('create list column', () => testMigrations({
|
|
177
|
+
original: createSchema({
|
|
178
|
+
Author: class Author {
|
|
179
|
+
},
|
|
180
|
+
}),
|
|
181
|
+
updated: createSchema({
|
|
182
|
+
Author: class Author {
|
|
183
|
+
emails = def.stringColumn().list()
|
|
184
|
+
},
|
|
185
|
+
}),
|
|
186
|
+
diff: [
|
|
187
|
+
{
|
|
188
|
+
modification: 'createColumn',
|
|
189
|
+
entityName: 'Author',
|
|
190
|
+
field: {
|
|
191
|
+
columnName: 'emails',
|
|
192
|
+
name: 'emails',
|
|
193
|
+
nullable: true,
|
|
194
|
+
type: Model.ColumnType.String,
|
|
195
|
+
columnType: 'text',
|
|
196
|
+
list: true,
|
|
197
|
+
},
|
|
198
|
+
},
|
|
199
|
+
],
|
|
200
|
+
sql: SQL`ALTER TABLE "author" ADD "emails" text[];`,
|
|
201
|
+
}))
|
|
@@ -226,3 +226,30 @@ describe('set not null and fill with "using"', () => testMigrations({
|
|
|
226
226
|
],
|
|
227
227
|
sql: SQL` ALTER TABLE "author" ALTER "name" SET DATA TYPE text USING COALESCE("name"::text, $pga$unnamed$pga$), ALTER "name" SET NOT NULL;`,
|
|
228
228
|
}))
|
|
229
|
+
|
|
230
|
+
|
|
231
|
+
describe('change string to array string', () => testMigrations({
|
|
232
|
+
original: createSchema({
|
|
233
|
+
Author: class Author {
|
|
234
|
+
email = def.stringColumn()
|
|
235
|
+
},
|
|
236
|
+
}),
|
|
237
|
+
updated: createSchema({
|
|
238
|
+
Author: class Author {
|
|
239
|
+
email = def.stringColumn().list()
|
|
240
|
+
},
|
|
241
|
+
}),
|
|
242
|
+
diff: [
|
|
243
|
+
updateColumnDefinitionModification.createModification({
|
|
244
|
+
entityName: 'Author',
|
|
245
|
+
fieldName: 'email',
|
|
246
|
+
definition: {
|
|
247
|
+
type: Model.ColumnType.String,
|
|
248
|
+
columnType: 'text',
|
|
249
|
+
nullable: true,
|
|
250
|
+
list: true,
|
|
251
|
+
},
|
|
252
|
+
}),
|
|
253
|
+
],
|
|
254
|
+
sql: SQL`ALTER TABLE "author" ALTER "email" SET DATA TYPE text[] USING ARRAY["email"]::text[];`,
|
|
255
|
+
}))
|