@contember/schema-migrations 2.0.0-alpha.18 → 2.0.0-alpha.20

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.0.0-alpha.18",
3
+ "version": "2.0.0-alpha.20",
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-alpha.18",
27
- "@contember/database-migrations": "2.0.0-alpha.18",
28
- "@contember/engine-common": "2.0.0-alpha.18",
29
- "@contember/schema": "2.0.0-alpha.18",
30
- "@contember/schema-utils": "2.0.0-alpha.18",
26
+ "@contember/database": "2.0.0-alpha.20",
27
+ "@contember/database-migrations": "2.0.0-alpha.20",
28
+ "@contember/engine-common": "2.0.0-alpha.20",
29
+ "@contember/schema": "2.0.0-alpha.20",
30
+ "@contember/schema-utils": "2.0.0-alpha.20",
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-alpha.18"
35
+ "@contember/schema-definition": "2.0.0-alpha.20"
36
36
  },
37
37
  "peerDependencies": {
38
38
  "pg": "^8.9.0"
@@ -18,7 +18,7 @@ import {
18
18
  ModificationHandlerOptions,
19
19
  } from '../ModificationHandler'
20
20
  import { VERSION_ACL_PATCH, VERSION_REMOVE_REFERENCING_RELATIONS } from '../ModificationVersions'
21
- import { isRelation, PredicateDefinitionProcessor } from '@contember/schema-utils'
21
+ import { acceptEveryFieldVisitor, isRelation, PredicateDefinitionProcessor } from '@contember/schema-utils'
22
22
  import { removeFieldModification } from '../fields'
23
23
 
24
24
  export class RemoveEntityModificationHandler implements ModificationHandler<RemoveEntityModificationData> {
@@ -40,6 +40,17 @@ export class RemoveEntityModificationHandler implements ModificationHandler<Remo
40
40
  removeFieldHandler.createSql(builder, options)
41
41
  })
42
42
  }
43
+ acceptEveryFieldVisitor(this.schema.model, entity, {
44
+ visitManyHasManyOwning: ({ relation }) => {
45
+ builder.dropTable(relation.joiningTable.tableName)
46
+ },
47
+ visitManyHasManyInverse: () => {},
48
+ visitColumn: () => {},
49
+ visitOneHasOneInverse: () => {},
50
+ visitOneHasOneOwning: () => {},
51
+ visitManyHasOne: () => {},
52
+ visitOneHasMany: () => {},
53
+ })
43
54
  builder.dropTable(entity.tableName)
44
55
  }
45
56
 
@@ -119,3 +119,77 @@ testMigrations('remove a view', {
119
119
  sql: SQL`
120
120
  DROP VIEW "author";`,
121
121
  })
122
+
123
+
124
+ namespace EntityWithManyHasManyOriginalSchema {
125
+
126
+ export class Book {
127
+ title = def.stringColumn()
128
+ tags = def.manyHasMany(Tag, 'books')
129
+ }
130
+
131
+ export class Tag {
132
+ name = def.stringColumn()
133
+ books = def.manyHasManyInverse(Book, 'tags')
134
+ }
135
+ }
136
+ testMigrations('remove junction table, when both entities are removed', {
137
+ original: createSchema(EntityWithManyHasManyOriginalSchema),
138
+ updated: {},
139
+ diff: [
140
+ {
141
+ modification: 'removeEntity',
142
+ entityName: 'Book',
143
+ },
144
+ {
145
+ modification: 'removeEntity',
146
+ entityName: 'Tag',
147
+ },
148
+ ],
149
+ sql: SQL`DROP TABLE "book_tags";
150
+ DROP TABLE "book";
151
+ DROP TABLE "tag";`,
152
+ })
153
+
154
+
155
+ namespace EntityWithManyHasManyUpdatedSchema {
156
+
157
+ export class Tag {
158
+ name = def.stringColumn()
159
+ }
160
+ }
161
+ testMigrations('remove junction table, when owning entity is removed', {
162
+ original: createSchema(EntityWithManyHasManyOriginalSchema),
163
+ updated: createSchema(EntityWithManyHasManyUpdatedSchema),
164
+ diff: [
165
+ {
166
+ modification: 'removeEntity',
167
+ entityName: 'Book',
168
+ },
169
+
170
+ ],
171
+ sql: SQL`DROP TABLE "book_tags";
172
+ DROP TABLE "book";`,
173
+ })
174
+
175
+
176
+ namespace EntityWithManyHasMany2UpdatedSchema {
177
+
178
+ export class Book {
179
+ title = def.stringColumn()
180
+ }
181
+ }
182
+ testMigrations('remove junction table, when inverse entity is removed', {
183
+ original: createSchema(EntityWithManyHasManyOriginalSchema),
184
+ updated: createSchema(EntityWithManyHasMany2UpdatedSchema),
185
+ diff: [
186
+ {
187
+ modification: 'removeEntity',
188
+ entityName: 'Tag',
189
+ },
190
+
191
+ ],
192
+ sql: SQL`
193
+ DROP TABLE "book_tags";
194
+ DROP TABLE "tag";`,
195
+ })