@contember/schema-migrations 2.1.0-alpha.13 → 2.1.0-alpha.15

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@contember/schema-migrations",
3
- "version": "2.1.0-alpha.13",
3
+ "version": "2.1.0-alpha.15",
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.1.0-alpha.13",
27
- "@contember/database-migrations": "2.1.0-alpha.13",
28
- "@contember/engine-common": "2.1.0-alpha.13",
29
- "@contember/schema": "2.1.0-alpha.13",
30
- "@contember/schema-utils": "2.1.0-alpha.13",
26
+ "@contember/database": "2.1.0-alpha.15",
27
+ "@contember/database-migrations": "2.1.0-alpha.15",
28
+ "@contember/engine-common": "2.1.0-alpha.15",
29
+ "@contember/schema": "2.1.0-alpha.15",
30
+ "@contember/schema-utils": "2.1.0-alpha.15",
31
31
  "fast-deep-equal": "^3.1.3",
32
32
  "rfc6902": "^5.1.1"
33
33
  },
34
34
  "devDependencies": {
35
- "@contember/schema-definition": "2.1.0-alpha.13"
35
+ "@contember/schema-definition": "2.1.0-alpha.15"
36
36
  },
37
37
  "peerDependencies": {
38
38
  "pg": "^8.9.0"
@@ -28,7 +28,9 @@ export class UpdateColumnDefinitionModificationHandler implements ModificationHa
28
28
 
29
29
  const columnNameWrapped = wrapIdentifier(oldColumn.columnName)
30
30
  const isChangedToArray = !oldColumn.list && newColumn.list
31
- const usingCast = (isChangedToArray ? `ARRAY[${columnNameWrapped}]` : columnNameWrapped) + `::${columnType}`
31
+ const usingCast = isChangedToArray
32
+ ? `CASE WHEN ${columnNameWrapped} IS NULL THEN ${newColumn.nullable ? 'NULL' : `ARRAY[]::${columnType}`} ELSE ARRAY[${columnNameWrapped}]::${columnType} END`
33
+ : `${columnNameWrapped}::${columnType}`
32
34
 
33
35
  const seedExpression = formatSeedExpression({
34
36
  model: this.schema.model,
@@ -251,5 +251,32 @@ describe('change string to array string', () => testMigrations({
251
251
  },
252
252
  }),
253
253
  ],
254
- sql: SQL`ALTER TABLE "author" ALTER "email" SET DATA TYPE text[] USING ARRAY["email"]::text[];`,
254
+ sql: SQL`ALTER TABLE "author" ALTER "email" SET DATA TYPE text[] USING CASE WHEN "email" IS NULL THEN NULL ELSE ARRAY["email"]::text[] END;`,
255
+ }))
256
+
257
+ describe('change string to array string not null', () => testMigrations({
258
+ original: createSchema({
259
+ Author: class Author {
260
+ email = def.stringColumn().notNull()
261
+ },
262
+ }),
263
+ updated: createSchema({
264
+ Author: class Author {
265
+ email = def.stringColumn().list().notNull()
266
+ },
267
+ }),
268
+ diff: [
269
+ updateColumnDefinitionModification.createModification({
270
+ entityName: 'Author',
271
+ fieldName: 'email',
272
+ definition: {
273
+ type: Model.ColumnType.String,
274
+ columnType: 'text',
275
+ nullable: false,
276
+ list: true,
277
+ },
278
+ }),
279
+ ],
280
+ sql: SQL`ALTER TABLE "author"
281
+ ALTER "email" SET DATA TYPE text[] USING CASE WHEN "email" IS NULL THEN ARRAY[]::text[] ELSE ARRAY["email"]::text[] END;`,
255
282
  }))