@anthonyalayo/drizzle-kit 1.0.2 → 1.0.4
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/api.d.mts +2891 -0
- package/api.d.ts +2891 -0
- package/api.js +47534 -0
- package/api.mjs +47521 -0
- package/bin.cjs +80043 -0
- package/{src/index.ts → index-Z-1TKnbX.d.mts} +123 -141
- package/index-Z-1TKnbX.d.ts +308 -0
- package/index.d.mts +2 -0
- package/index.d.ts +2 -0
- package/index.js +32 -0
- package/index.mjs +7 -0
- package/package.json +1 -1
- package/utils.js +6056 -0
- package/utils.mjs +6032 -0
- package/.gitignore +0 -25
- package/build.dev.ts +0 -51
- package/build.ts +0 -112
- package/imports-checker/analyze.ts +0 -78
- package/imports-checker/checker.ts +0 -296
- package/imports-checker/grammar/grammar.ohm +0 -121
- package/imports-checker/grammar/grammar.ohm-bundle.d.ts +0 -164
- package/imports-checker/grammar/grammar.ohm-bundle.js +0 -753
- package/imports-checker/index.ts +0 -48
- package/patches/difflib@0.2.4.patch +0 -31
- package/src/@types/utils.ts +0 -58
- package/src/api.ts +0 -504
- package/src/cli/commands/_es5.ts +0 -2
- package/src/cli/commands/check.ts +0 -52
- package/src/cli/commands/drop.ts +0 -60
- package/src/cli/commands/introspect.ts +0 -772
- package/src/cli/commands/libSqlPushUtils.ts +0 -355
- package/src/cli/commands/migrate.ts +0 -1526
- package/src/cli/commands/mysqlIntrospect.ts +0 -53
- package/src/cli/commands/mysqlPushUtils.ts +0 -352
- package/src/cli/commands/mysqlUp.ts +0 -102
- package/src/cli/commands/pgIntrospect.ts +0 -55
- package/src/cli/commands/pgPushUtils.ts +0 -269
- package/src/cli/commands/pgUp.ts +0 -217
- package/src/cli/commands/push.ts +0 -637
- package/src/cli/commands/singlestoreIntrospect.ts +0 -53
- package/src/cli/commands/singlestorePushUtils.ts +0 -456
- package/src/cli/commands/singlestoreUp.ts +0 -1
- package/src/cli/commands/sqliteIntrospect.ts +0 -96
- package/src/cli/commands/sqlitePushUtils.ts +0 -322
- package/src/cli/commands/sqliteUp.ts +0 -52
- package/src/cli/commands/utils.ts +0 -858
- package/src/cli/connections.ts +0 -914
- package/src/cli/index.ts +0 -48
- package/src/cli/schema.ts +0 -794
- package/src/cli/selector-ui.ts +0 -38
- package/src/cli/utils.ts +0 -112
- package/src/cli/validations/cli.ts +0 -79
- package/src/cli/validations/common.ts +0 -193
- package/src/cli/validations/libsql.ts +0 -27
- package/src/cli/validations/mysql.ts +0 -61
- package/src/cli/validations/outputs.ts +0 -91
- package/src/cli/validations/postgres.ts +0 -83
- package/src/cli/validations/singlestore.ts +0 -61
- package/src/cli/validations/sqlite.ts +0 -104
- package/src/cli/validations/studio.ts +0 -24
- package/src/cli/views.ts +0 -658
- package/src/extensions/getTablesFilterByExtensions.ts +0 -16
- package/src/extensions/vector.ts +0 -10
- package/src/global.ts +0 -61
- package/src/introspect-mysql.ts +0 -1030
- package/src/introspect-pg.ts +0 -1435
- package/src/introspect-singlestore.ts +0 -913
- package/src/introspect-sqlite.ts +0 -533
- package/src/jsonDiffer.js +0 -882
- package/src/jsonStatements.ts +0 -3590
- package/src/loader.mjs +0 -57
- package/src/migrationPreparator.ts +0 -217
- package/src/schemaValidator.ts +0 -23
- package/src/serializer/index.ts +0 -142
- package/src/serializer/mysqlImports.ts +0 -38
- package/src/serializer/mysqlSchema.ts +0 -423
- package/src/serializer/mysqlSerializer.ts +0 -999
- package/src/serializer/pgImports.ts +0 -106
- package/src/serializer/pgSchema.ts +0 -937
- package/src/serializer/pgSerializer.ts +0 -2223
- package/src/serializer/singlestoreImports.ts +0 -38
- package/src/serializer/singlestoreSchema.ts +0 -257
- package/src/serializer/singlestoreSerializer.ts +0 -767
- package/src/serializer/sqliteImports.ts +0 -41
- package/src/serializer/sqliteSchema.ts +0 -352
- package/src/serializer/sqliteSerializer.ts +0 -931
- package/src/serializer/studio.ts +0 -694
- package/src/serializer/utils.ts +0 -45
- package/src/simulator.ts +0 -157
- package/src/snapshotsDiffer.ts +0 -4398
- package/src/sqlgenerator.ts +0 -4212
- package/src/statementCombiner.ts +0 -597
- package/src/utils/certs.ts +0 -44
- package/src/utils/words.ts +0 -1333
- package/src/utils.ts +0 -370
- package/tests/bin.test.ts +0 -58
- package/tests/cli/d1http.config.ts +0 -12
- package/tests/cli/drizzle.config.ts +0 -9
- package/tests/cli/durable-sqlite.config.ts +0 -7
- package/tests/cli/expo.config.ts +0 -7
- package/tests/cli/postgres.config.ts +0 -13
- package/tests/cli/postgres2.config.ts +0 -17
- package/tests/cli/schema.ts +0 -1
- package/tests/cli/turso.config.ts +0 -10
- package/tests/cli-export.test.ts +0 -79
- package/tests/cli-generate.test.ts +0 -259
- package/tests/cli-migrate.test.ts +0 -103
- package/tests/cli-push.test.ts +0 -126
- package/tests/common.ts +0 -15
- package/tests/indexes/common.ts +0 -21
- package/tests/indexes/pg.test.ts +0 -245
- package/tests/introspect/libsql.test.ts +0 -35
- package/tests/introspect/mysql.test.ts +0 -319
- package/tests/introspect/pg.test.ts +0 -894
- package/tests/introspect/singlestore.test.ts +0 -275
- package/tests/introspect/sqlite.test.ts +0 -122
- package/tests/libsql-checks.test.ts +0 -308
- package/tests/libsql-statements.test.ts +0 -989
- package/tests/libsql-views.test.ts +0 -218
- package/tests/migrate/libsq-schema.ts +0 -6
- package/tests/migrate/libsql-migrate.test.ts +0 -58
- package/tests/migrate/migrations/0000_little_blizzard.sql +0 -4
- package/tests/migrate/migrations/0001_nebulous_storm.sql +0 -10
- package/tests/migrate/migrations/meta/0000_snapshot.json +0 -40
- package/tests/migrate/migrations/meta/0001_snapshot.json +0 -40
- package/tests/migrate/migrations/meta/_journal.json +0 -20
- package/tests/mysql-checks.test.ts +0 -291
- package/tests/mysql-generated.test.ts +0 -1290
- package/tests/mysql-schemas.test.ts +0 -156
- package/tests/mysql-views.test.ts +0 -553
- package/tests/mysql.test.ts +0 -863
- package/tests/pg-array.test.ts +0 -368
- package/tests/pg-checks.test.ts +0 -329
- package/tests/pg-columns.test.ts +0 -484
- package/tests/pg-domains.test.ts +0 -306
- package/tests/pg-enums.test.ts +0 -751
- package/tests/pg-generated.test.ts +0 -529
- package/tests/pg-identity.test.ts +0 -447
- package/tests/pg-schemas.test.ts +0 -105
- package/tests/pg-sequences.test.ts +0 -298
- package/tests/pg-tables.test.ts +0 -1021
- package/tests/pg-views.test.ts +0 -1929
- package/tests/push/common.ts +0 -58
- package/tests/push/libsql.test.ts +0 -1400
- package/tests/push/mysql-push.test.ts +0 -345
- package/tests/push/mysql.test.ts +0 -788
- package/tests/push/pg.test.ts +0 -4341
- package/tests/push/singlestore-push.test.ts +0 -894
- package/tests/push/singlestore.test.ts +0 -444
- package/tests/push/sqlite.test.ts +0 -1613
- package/tests/rls/pg-policy.test.ts +0 -1656
- package/tests/rls/pg-role.test.ts +0 -234
- package/tests/schemaDiffer.ts +0 -2852
- package/tests/singlestore-generated.test.ts +0 -1290
- package/tests/singlestore-schemas.test.ts +0 -155
- package/tests/singlestore.test.ts +0 -978
- package/tests/sqlite-checks.test.ts +0 -308
- package/tests/sqlite-columns.test.ts +0 -1049
- package/tests/sqlite-generated.test.ts +0 -1726
- package/tests/sqlite-tables.test.ts +0 -637
- package/tests/sqlite-views.test.ts +0 -218
- package/tests/statements-combiner/libsql-statements-combiner.test.ts +0 -1812
- package/tests/statements-combiner/singlestore-statements-combiner.test.ts +0 -882
- package/tests/statements-combiner/sqlite-statements-combiner.test.ts +0 -1211
- package/tests/test/sqlite.test.ts +0 -39
- package/tests/testsinglestore.ts +0 -29
- package/tests/validations.test.ts +0 -869
- package/tests/wrap-param.test.ts +0 -16
- package/tsconfig.build.json +0 -4
- package/tsconfig.cli-types.json +0 -9
- package/tsconfig.json +0 -28
- package/vitest.config.ts +0 -34
package/tests/mysql.test.ts
DELETED
|
@@ -1,863 +0,0 @@
|
|
|
1
|
-
import { sql } from 'drizzle-orm';
|
|
2
|
-
import {
|
|
3
|
-
foreignKey,
|
|
4
|
-
index,
|
|
5
|
-
int,
|
|
6
|
-
json,
|
|
7
|
-
mysqlEnum,
|
|
8
|
-
mysqlSchema,
|
|
9
|
-
mysqlTable,
|
|
10
|
-
primaryKey,
|
|
11
|
-
serial,
|
|
12
|
-
text,
|
|
13
|
-
unique,
|
|
14
|
-
uniqueIndex,
|
|
15
|
-
varchar,
|
|
16
|
-
} from 'drizzle-orm/mysql-core';
|
|
17
|
-
import { expect, test } from 'vitest';
|
|
18
|
-
import { diffTestSchemasMysql } from './schemaDiffer';
|
|
19
|
-
|
|
20
|
-
test('add table #1', async () => {
|
|
21
|
-
const to = {
|
|
22
|
-
users: mysqlTable('users', {}),
|
|
23
|
-
};
|
|
24
|
-
|
|
25
|
-
const { statements } = await diffTestSchemasMysql({}, to, []);
|
|
26
|
-
|
|
27
|
-
expect(statements.length).toBe(1);
|
|
28
|
-
expect(statements[0]).toStrictEqual({
|
|
29
|
-
type: 'create_table',
|
|
30
|
-
tableName: 'users',
|
|
31
|
-
schema: undefined,
|
|
32
|
-
columns: [],
|
|
33
|
-
compositePKs: [],
|
|
34
|
-
internals: {
|
|
35
|
-
tables: {},
|
|
36
|
-
indexes: {},
|
|
37
|
-
},
|
|
38
|
-
uniqueConstraints: [],
|
|
39
|
-
compositePkName: '',
|
|
40
|
-
checkConstraints: [],
|
|
41
|
-
});
|
|
42
|
-
});
|
|
43
|
-
|
|
44
|
-
test('add table #2', async () => {
|
|
45
|
-
const to = {
|
|
46
|
-
users: mysqlTable('users', {
|
|
47
|
-
id: serial('id').primaryKey(),
|
|
48
|
-
}),
|
|
49
|
-
};
|
|
50
|
-
|
|
51
|
-
const { statements } = await diffTestSchemasMysql({}, to, []);
|
|
52
|
-
|
|
53
|
-
expect(statements.length).toBe(1);
|
|
54
|
-
expect(statements[0]).toStrictEqual({
|
|
55
|
-
type: 'create_table',
|
|
56
|
-
tableName: 'users',
|
|
57
|
-
schema: undefined,
|
|
58
|
-
columns: [
|
|
59
|
-
{
|
|
60
|
-
name: 'id',
|
|
61
|
-
notNull: true,
|
|
62
|
-
primaryKey: false,
|
|
63
|
-
type: 'serial',
|
|
64
|
-
autoincrement: true,
|
|
65
|
-
},
|
|
66
|
-
],
|
|
67
|
-
compositePKs: ['users_id;id'],
|
|
68
|
-
compositePkName: 'users_id',
|
|
69
|
-
uniqueConstraints: [],
|
|
70
|
-
checkConstraints: [],
|
|
71
|
-
internals: {
|
|
72
|
-
tables: {},
|
|
73
|
-
indexes: {},
|
|
74
|
-
},
|
|
75
|
-
});
|
|
76
|
-
});
|
|
77
|
-
|
|
78
|
-
test('add table #3', async () => {
|
|
79
|
-
const to = {
|
|
80
|
-
users: mysqlTable(
|
|
81
|
-
'users',
|
|
82
|
-
{
|
|
83
|
-
id: serial('id'),
|
|
84
|
-
},
|
|
85
|
-
(t) => {
|
|
86
|
-
return {
|
|
87
|
-
pk: primaryKey({
|
|
88
|
-
name: 'users_pk',
|
|
89
|
-
columns: [t.id],
|
|
90
|
-
}),
|
|
91
|
-
};
|
|
92
|
-
},
|
|
93
|
-
),
|
|
94
|
-
};
|
|
95
|
-
|
|
96
|
-
const { statements } = await diffTestSchemasMysql({}, to, []);
|
|
97
|
-
|
|
98
|
-
expect(statements.length).toBe(1);
|
|
99
|
-
expect(statements[0]).toStrictEqual({
|
|
100
|
-
type: 'create_table',
|
|
101
|
-
tableName: 'users',
|
|
102
|
-
schema: undefined,
|
|
103
|
-
columns: [
|
|
104
|
-
{
|
|
105
|
-
name: 'id',
|
|
106
|
-
notNull: true,
|
|
107
|
-
primaryKey: false,
|
|
108
|
-
type: 'serial',
|
|
109
|
-
autoincrement: true,
|
|
110
|
-
},
|
|
111
|
-
],
|
|
112
|
-
compositePKs: ['users_pk;id'],
|
|
113
|
-
uniqueConstraints: [],
|
|
114
|
-
compositePkName: 'users_pk',
|
|
115
|
-
checkConstraints: [],
|
|
116
|
-
internals: {
|
|
117
|
-
tables: {},
|
|
118
|
-
indexes: {},
|
|
119
|
-
},
|
|
120
|
-
});
|
|
121
|
-
});
|
|
122
|
-
|
|
123
|
-
test('add table #4', async () => {
|
|
124
|
-
const to = {
|
|
125
|
-
users: mysqlTable('users', {}),
|
|
126
|
-
posts: mysqlTable('posts', {}),
|
|
127
|
-
};
|
|
128
|
-
|
|
129
|
-
const { statements } = await diffTestSchemasMysql({}, to, []);
|
|
130
|
-
|
|
131
|
-
expect(statements.length).toBe(2);
|
|
132
|
-
expect(statements[0]).toStrictEqual({
|
|
133
|
-
type: 'create_table',
|
|
134
|
-
tableName: 'users',
|
|
135
|
-
schema: undefined,
|
|
136
|
-
columns: [],
|
|
137
|
-
internals: {
|
|
138
|
-
tables: {},
|
|
139
|
-
indexes: {},
|
|
140
|
-
},
|
|
141
|
-
compositePKs: [],
|
|
142
|
-
uniqueConstraints: [],
|
|
143
|
-
compositePkName: '',
|
|
144
|
-
checkConstraints: [],
|
|
145
|
-
});
|
|
146
|
-
expect(statements[1]).toStrictEqual({
|
|
147
|
-
type: 'create_table',
|
|
148
|
-
tableName: 'posts',
|
|
149
|
-
schema: undefined,
|
|
150
|
-
columns: [],
|
|
151
|
-
compositePKs: [],
|
|
152
|
-
internals: {
|
|
153
|
-
tables: {},
|
|
154
|
-
indexes: {},
|
|
155
|
-
},
|
|
156
|
-
uniqueConstraints: [],
|
|
157
|
-
compositePkName: '',
|
|
158
|
-
checkConstraints: [],
|
|
159
|
-
});
|
|
160
|
-
});
|
|
161
|
-
|
|
162
|
-
test('add table #5', async () => {
|
|
163
|
-
const schema = mysqlSchema('folder');
|
|
164
|
-
const from = {
|
|
165
|
-
schema,
|
|
166
|
-
};
|
|
167
|
-
|
|
168
|
-
const to = {
|
|
169
|
-
schema,
|
|
170
|
-
users: schema.table('users', {}),
|
|
171
|
-
};
|
|
172
|
-
|
|
173
|
-
const { statements } = await diffTestSchemasMysql(from, to, []);
|
|
174
|
-
|
|
175
|
-
expect(statements.length).toBe(0);
|
|
176
|
-
});
|
|
177
|
-
|
|
178
|
-
test('add table #6', async () => {
|
|
179
|
-
const from = {
|
|
180
|
-
users1: mysqlTable('users1', {}),
|
|
181
|
-
};
|
|
182
|
-
|
|
183
|
-
const to = {
|
|
184
|
-
users2: mysqlTable('users2', {}),
|
|
185
|
-
};
|
|
186
|
-
|
|
187
|
-
const { statements } = await diffTestSchemasMysql(from, to, []);
|
|
188
|
-
|
|
189
|
-
expect(statements.length).toBe(2);
|
|
190
|
-
expect(statements[0]).toStrictEqual({
|
|
191
|
-
type: 'create_table',
|
|
192
|
-
tableName: 'users2',
|
|
193
|
-
schema: undefined,
|
|
194
|
-
columns: [],
|
|
195
|
-
internals: {
|
|
196
|
-
tables: {},
|
|
197
|
-
indexes: {},
|
|
198
|
-
},
|
|
199
|
-
compositePKs: [],
|
|
200
|
-
uniqueConstraints: [],
|
|
201
|
-
compositePkName: '',
|
|
202
|
-
checkConstraints: [],
|
|
203
|
-
});
|
|
204
|
-
expect(statements[1]).toStrictEqual({
|
|
205
|
-
type: 'drop_table',
|
|
206
|
-
policies: [],
|
|
207
|
-
tableName: 'users1',
|
|
208
|
-
schema: undefined,
|
|
209
|
-
});
|
|
210
|
-
});
|
|
211
|
-
|
|
212
|
-
test('add table #7', async () => {
|
|
213
|
-
const from = {
|
|
214
|
-
users1: mysqlTable('users1', {}),
|
|
215
|
-
};
|
|
216
|
-
|
|
217
|
-
const to = {
|
|
218
|
-
users: mysqlTable('users', {}),
|
|
219
|
-
users2: mysqlTable('users2', {}),
|
|
220
|
-
};
|
|
221
|
-
|
|
222
|
-
const { statements } = await diffTestSchemasMysql(from, to, [
|
|
223
|
-
'public.users1->public.users2',
|
|
224
|
-
]);
|
|
225
|
-
|
|
226
|
-
expect(statements.length).toBe(2);
|
|
227
|
-
expect(statements[0]).toStrictEqual({
|
|
228
|
-
type: 'create_table',
|
|
229
|
-
tableName: 'users',
|
|
230
|
-
schema: undefined,
|
|
231
|
-
columns: [],
|
|
232
|
-
compositePKs: [],
|
|
233
|
-
uniqueConstraints: [],
|
|
234
|
-
internals: {
|
|
235
|
-
tables: {},
|
|
236
|
-
indexes: {},
|
|
237
|
-
},
|
|
238
|
-
compositePkName: '',
|
|
239
|
-
checkConstraints: [],
|
|
240
|
-
});
|
|
241
|
-
expect(statements[1]).toStrictEqual({
|
|
242
|
-
type: 'rename_table',
|
|
243
|
-
tableNameFrom: 'users1',
|
|
244
|
-
tableNameTo: 'users2',
|
|
245
|
-
fromSchema: undefined,
|
|
246
|
-
toSchema: undefined,
|
|
247
|
-
});
|
|
248
|
-
});
|
|
249
|
-
|
|
250
|
-
test('add schema + table #1', async () => {
|
|
251
|
-
const schema = mysqlSchema('folder');
|
|
252
|
-
|
|
253
|
-
const to = {
|
|
254
|
-
schema,
|
|
255
|
-
users: schema.table('users', {}),
|
|
256
|
-
};
|
|
257
|
-
|
|
258
|
-
const { statements } = await diffTestSchemasMysql({}, to, []);
|
|
259
|
-
|
|
260
|
-
expect(statements.length).toBe(0);
|
|
261
|
-
});
|
|
262
|
-
|
|
263
|
-
test('change schema with tables #1', async () => {
|
|
264
|
-
const schema = mysqlSchema('folder');
|
|
265
|
-
const schema2 = mysqlSchema('folder2');
|
|
266
|
-
const from = {
|
|
267
|
-
schema,
|
|
268
|
-
users: schema.table('users', {}),
|
|
269
|
-
};
|
|
270
|
-
const to = {
|
|
271
|
-
schema2,
|
|
272
|
-
users: schema2.table('users', {}),
|
|
273
|
-
};
|
|
274
|
-
|
|
275
|
-
const { statements } = await diffTestSchemasMysql(from, to, [
|
|
276
|
-
'folder->folder2',
|
|
277
|
-
]);
|
|
278
|
-
|
|
279
|
-
expect(statements.length).toBe(0);
|
|
280
|
-
});
|
|
281
|
-
|
|
282
|
-
test('change table schema #1', async () => {
|
|
283
|
-
const schema = mysqlSchema('folder');
|
|
284
|
-
const from = {
|
|
285
|
-
schema,
|
|
286
|
-
users: mysqlTable('users', {}),
|
|
287
|
-
};
|
|
288
|
-
const to = {
|
|
289
|
-
schema,
|
|
290
|
-
users: schema.table('users', {}),
|
|
291
|
-
};
|
|
292
|
-
|
|
293
|
-
const { statements } = await diffTestSchemasMysql(from, to, [
|
|
294
|
-
'public.users->folder.users',
|
|
295
|
-
]);
|
|
296
|
-
|
|
297
|
-
expect(statements.length).toBe(1);
|
|
298
|
-
expect(statements[0]).toStrictEqual({
|
|
299
|
-
type: 'drop_table',
|
|
300
|
-
policies: [],
|
|
301
|
-
tableName: 'users',
|
|
302
|
-
schema: undefined,
|
|
303
|
-
});
|
|
304
|
-
});
|
|
305
|
-
|
|
306
|
-
test('change table schema #2', async () => {
|
|
307
|
-
const schema = mysqlSchema('folder');
|
|
308
|
-
const from = {
|
|
309
|
-
schema,
|
|
310
|
-
users: schema.table('users', {}),
|
|
311
|
-
};
|
|
312
|
-
const to = {
|
|
313
|
-
schema,
|
|
314
|
-
users: mysqlTable('users', {}),
|
|
315
|
-
};
|
|
316
|
-
|
|
317
|
-
const { statements } = await diffTestSchemasMysql(from, to, [
|
|
318
|
-
'folder.users->public.users',
|
|
319
|
-
]);
|
|
320
|
-
|
|
321
|
-
expect(statements.length).toBe(1);
|
|
322
|
-
expect(statements[0]).toStrictEqual({
|
|
323
|
-
type: 'create_table',
|
|
324
|
-
tableName: 'users',
|
|
325
|
-
schema: undefined,
|
|
326
|
-
columns: [],
|
|
327
|
-
uniqueConstraints: [],
|
|
328
|
-
compositePkName: '',
|
|
329
|
-
compositePKs: [],
|
|
330
|
-
checkConstraints: [],
|
|
331
|
-
internals: {
|
|
332
|
-
tables: {},
|
|
333
|
-
indexes: {},
|
|
334
|
-
},
|
|
335
|
-
});
|
|
336
|
-
});
|
|
337
|
-
|
|
338
|
-
test('change table schema #3', async () => {
|
|
339
|
-
const schema1 = mysqlSchema('folder1');
|
|
340
|
-
const schema2 = mysqlSchema('folder2');
|
|
341
|
-
const from = {
|
|
342
|
-
schema1,
|
|
343
|
-
schema2,
|
|
344
|
-
users: schema1.table('users', {}),
|
|
345
|
-
};
|
|
346
|
-
const to = {
|
|
347
|
-
schema1,
|
|
348
|
-
schema2,
|
|
349
|
-
users: schema2.table('users', {}),
|
|
350
|
-
};
|
|
351
|
-
|
|
352
|
-
const { statements } = await diffTestSchemasMysql(from, to, [
|
|
353
|
-
'folder1.users->folder2.users',
|
|
354
|
-
]);
|
|
355
|
-
|
|
356
|
-
expect(statements.length).toBe(0);
|
|
357
|
-
});
|
|
358
|
-
|
|
359
|
-
test('change table schema #4', async () => {
|
|
360
|
-
const schema1 = mysqlSchema('folder1');
|
|
361
|
-
const schema2 = mysqlSchema('folder2');
|
|
362
|
-
const from = {
|
|
363
|
-
schema1,
|
|
364
|
-
users: schema1.table('users', {}),
|
|
365
|
-
};
|
|
366
|
-
const to = {
|
|
367
|
-
schema1,
|
|
368
|
-
schema2, // add schema
|
|
369
|
-
users: schema2.table('users', {}), // move table
|
|
370
|
-
};
|
|
371
|
-
|
|
372
|
-
const { statements } = await diffTestSchemasMysql(from, to, [
|
|
373
|
-
'folder1.users->folder2.users',
|
|
374
|
-
]);
|
|
375
|
-
|
|
376
|
-
expect(statements.length).toBe(0);
|
|
377
|
-
});
|
|
378
|
-
|
|
379
|
-
test('change table schema #5', async () => {
|
|
380
|
-
const schema1 = mysqlSchema('folder1');
|
|
381
|
-
const schema2 = mysqlSchema('folder2');
|
|
382
|
-
const from = {
|
|
383
|
-
schema1, // remove schema
|
|
384
|
-
users: schema1.table('users', {}),
|
|
385
|
-
};
|
|
386
|
-
const to = {
|
|
387
|
-
schema2, // add schema
|
|
388
|
-
users: schema2.table('users', {}), // move table
|
|
389
|
-
};
|
|
390
|
-
|
|
391
|
-
const { statements } = await diffTestSchemasMysql(from, to, [
|
|
392
|
-
'folder1.users->folder2.users',
|
|
393
|
-
]);
|
|
394
|
-
|
|
395
|
-
expect(statements.length).toBe(0);
|
|
396
|
-
});
|
|
397
|
-
|
|
398
|
-
test('change table schema #5', async () => {
|
|
399
|
-
const schema1 = mysqlSchema('folder1');
|
|
400
|
-
const schema2 = mysqlSchema('folder2');
|
|
401
|
-
const from = {
|
|
402
|
-
schema1,
|
|
403
|
-
schema2,
|
|
404
|
-
users: schema1.table('users', {}),
|
|
405
|
-
};
|
|
406
|
-
const to = {
|
|
407
|
-
schema1,
|
|
408
|
-
schema2,
|
|
409
|
-
users: schema2.table('users2', {}), // rename and move table
|
|
410
|
-
};
|
|
411
|
-
|
|
412
|
-
const { statements } = await diffTestSchemasMysql(from, to, [
|
|
413
|
-
'folder1.users->folder2.users2',
|
|
414
|
-
]);
|
|
415
|
-
|
|
416
|
-
expect(statements.length).toBe(0);
|
|
417
|
-
});
|
|
418
|
-
|
|
419
|
-
test('change table schema #6', async () => {
|
|
420
|
-
const schema1 = mysqlSchema('folder1');
|
|
421
|
-
const schema2 = mysqlSchema('folder2');
|
|
422
|
-
const from = {
|
|
423
|
-
schema1,
|
|
424
|
-
users: schema1.table('users', {}),
|
|
425
|
-
};
|
|
426
|
-
const to = {
|
|
427
|
-
schema2, // rename schema
|
|
428
|
-
users: schema2.table('users2', {}), // rename table
|
|
429
|
-
};
|
|
430
|
-
|
|
431
|
-
const { statements } = await diffTestSchemasMysql(from, to, [
|
|
432
|
-
'folder1->folder2',
|
|
433
|
-
'folder2.users->folder2.users2',
|
|
434
|
-
]);
|
|
435
|
-
|
|
436
|
-
expect(statements.length).toBe(0);
|
|
437
|
-
});
|
|
438
|
-
|
|
439
|
-
test('add table #10', async () => {
|
|
440
|
-
const to = {
|
|
441
|
-
users: mysqlTable('table', {
|
|
442
|
-
json: json('json').default({}),
|
|
443
|
-
}),
|
|
444
|
-
};
|
|
445
|
-
|
|
446
|
-
const { sqlStatements } = await diffTestSchemasMysql({}, to, []);
|
|
447
|
-
expect(sqlStatements.length).toBe(1);
|
|
448
|
-
expect(sqlStatements[0]).toBe(
|
|
449
|
-
"CREATE TABLE `table` (\n\t`json` json DEFAULT ('{}')\n);\n",
|
|
450
|
-
);
|
|
451
|
-
});
|
|
452
|
-
|
|
453
|
-
test('add table #11', async () => {
|
|
454
|
-
const to = {
|
|
455
|
-
users: mysqlTable('table', {
|
|
456
|
-
json: json('json').default([]),
|
|
457
|
-
}),
|
|
458
|
-
};
|
|
459
|
-
|
|
460
|
-
const { sqlStatements } = await diffTestSchemasMysql({}, to, []);
|
|
461
|
-
expect(sqlStatements.length).toBe(1);
|
|
462
|
-
expect(sqlStatements[0]).toBe(
|
|
463
|
-
"CREATE TABLE `table` (\n\t`json` json DEFAULT ('[]')\n);\n",
|
|
464
|
-
);
|
|
465
|
-
});
|
|
466
|
-
|
|
467
|
-
test('add table #12', async () => {
|
|
468
|
-
const to = {
|
|
469
|
-
users: mysqlTable('table', {
|
|
470
|
-
json: json('json').default([1, 2, 3]),
|
|
471
|
-
}),
|
|
472
|
-
};
|
|
473
|
-
|
|
474
|
-
const { sqlStatements } = await diffTestSchemasMysql({}, to, []);
|
|
475
|
-
expect(sqlStatements.length).toBe(1);
|
|
476
|
-
expect(sqlStatements[0]).toBe(
|
|
477
|
-
"CREATE TABLE `table` (\n\t`json` json DEFAULT ('[1,2,3]')\n);\n",
|
|
478
|
-
);
|
|
479
|
-
});
|
|
480
|
-
|
|
481
|
-
test('add table #13', async () => {
|
|
482
|
-
const to = {
|
|
483
|
-
users: mysqlTable('table', {
|
|
484
|
-
json: json('json').default({ key: 'value' }),
|
|
485
|
-
}),
|
|
486
|
-
};
|
|
487
|
-
|
|
488
|
-
const { sqlStatements } = await diffTestSchemasMysql({}, to, []);
|
|
489
|
-
expect(sqlStatements.length).toBe(1);
|
|
490
|
-
expect(sqlStatements[0]).toBe(
|
|
491
|
-
'CREATE TABLE `table` (\n\t`json` json DEFAULT (\'{"key":"value"}\')\n);\n',
|
|
492
|
-
);
|
|
493
|
-
});
|
|
494
|
-
|
|
495
|
-
test('add table #14', async () => {
|
|
496
|
-
const to = {
|
|
497
|
-
users: mysqlTable('table', {
|
|
498
|
-
json: json('json').default({
|
|
499
|
-
key: 'value',
|
|
500
|
-
arr: [1, 2, 3],
|
|
501
|
-
}),
|
|
502
|
-
}),
|
|
503
|
-
};
|
|
504
|
-
|
|
505
|
-
const { sqlStatements } = await diffTestSchemasMysql({}, to, []);
|
|
506
|
-
expect(sqlStatements.length).toBe(1);
|
|
507
|
-
expect(sqlStatements[0]).toBe(
|
|
508
|
-
'CREATE TABLE `table` (\n\t`json` json DEFAULT (\'{"key":"value","arr":[1,2,3]}\')\n);\n',
|
|
509
|
-
);
|
|
510
|
-
});
|
|
511
|
-
|
|
512
|
-
test('drop index', async () => {
|
|
513
|
-
const from = {
|
|
514
|
-
users: mysqlTable(
|
|
515
|
-
'table',
|
|
516
|
-
{
|
|
517
|
-
name: text('name'),
|
|
518
|
-
},
|
|
519
|
-
(t) => {
|
|
520
|
-
return {
|
|
521
|
-
idx: index('name_idx').on(t.name),
|
|
522
|
-
};
|
|
523
|
-
},
|
|
524
|
-
),
|
|
525
|
-
};
|
|
526
|
-
|
|
527
|
-
const to = {
|
|
528
|
-
users: mysqlTable('table', {
|
|
529
|
-
name: text('name'),
|
|
530
|
-
}),
|
|
531
|
-
};
|
|
532
|
-
|
|
533
|
-
const { sqlStatements } = await diffTestSchemasMysql(from, to, []);
|
|
534
|
-
expect(sqlStatements.length).toBe(1);
|
|
535
|
-
expect(sqlStatements[0]).toBe('DROP INDEX `name_idx` ON `table`;');
|
|
536
|
-
});
|
|
537
|
-
|
|
538
|
-
test('drop unique constraint', async () => {
|
|
539
|
-
const from = {
|
|
540
|
-
users: mysqlTable(
|
|
541
|
-
'table',
|
|
542
|
-
{
|
|
543
|
-
name: text('name'),
|
|
544
|
-
},
|
|
545
|
-
(t) => {
|
|
546
|
-
return {
|
|
547
|
-
uq: unique('name_uq').on(t.name),
|
|
548
|
-
};
|
|
549
|
-
},
|
|
550
|
-
),
|
|
551
|
-
};
|
|
552
|
-
|
|
553
|
-
const to = {
|
|
554
|
-
users: mysqlTable('table', {
|
|
555
|
-
name: text('name'),
|
|
556
|
-
}),
|
|
557
|
-
};
|
|
558
|
-
|
|
559
|
-
const { sqlStatements } = await diffTestSchemasMysql(from, to, []);
|
|
560
|
-
expect(sqlStatements.length).toBe(1);
|
|
561
|
-
expect(sqlStatements[0]).toBe('ALTER TABLE `table` DROP INDEX `name_uq`;');
|
|
562
|
-
});
|
|
563
|
-
|
|
564
|
-
test('add table with indexes', async () => {
|
|
565
|
-
const from = {};
|
|
566
|
-
|
|
567
|
-
const to = {
|
|
568
|
-
users: mysqlTable(
|
|
569
|
-
'users',
|
|
570
|
-
{
|
|
571
|
-
id: serial('id').primaryKey(),
|
|
572
|
-
name: text('name'),
|
|
573
|
-
email: text('email'),
|
|
574
|
-
},
|
|
575
|
-
(t) => ({
|
|
576
|
-
uniqueExpr: uniqueIndex('uniqueExpr').on(sql`(lower(${t.email}))`),
|
|
577
|
-
indexExpr: index('indexExpr').on(sql`(lower(${t.email}))`),
|
|
578
|
-
indexExprMultiple: index('indexExprMultiple').on(
|
|
579
|
-
sql`(lower(${t.email}))`,
|
|
580
|
-
sql`(lower(${t.email}))`,
|
|
581
|
-
),
|
|
582
|
-
|
|
583
|
-
uniqueCol: uniqueIndex('uniqueCol').on(t.email),
|
|
584
|
-
indexCol: index('indexCol').on(t.email),
|
|
585
|
-
indexColMultiple: index('indexColMultiple').on(t.email, t.email),
|
|
586
|
-
|
|
587
|
-
indexColExpr: index('indexColExpr').on(
|
|
588
|
-
sql`(lower(${t.email}))`,
|
|
589
|
-
t.email,
|
|
590
|
-
),
|
|
591
|
-
}),
|
|
592
|
-
),
|
|
593
|
-
};
|
|
594
|
-
|
|
595
|
-
const { sqlStatements } = await diffTestSchemasMysql(from, to, []);
|
|
596
|
-
expect(sqlStatements.length).toBe(6);
|
|
597
|
-
expect(sqlStatements).toStrictEqual([
|
|
598
|
-
`CREATE TABLE \`users\` (\n\t\`id\` serial AUTO_INCREMENT NOT NULL,\n\t\`name\` text,\n\t\`email\` text,\n\tCONSTRAINT \`users_id\` PRIMARY KEY(\`id\`),\n\tCONSTRAINT \`uniqueExpr\` UNIQUE((lower(\`email\`))),\n\tCONSTRAINT \`uniqueCol\` UNIQUE(\`email\`)
|
|
599
|
-
);
|
|
600
|
-
`,
|
|
601
|
-
'CREATE INDEX `indexExpr` ON `users` ((lower(`email`)));',
|
|
602
|
-
'CREATE INDEX `indexExprMultiple` ON `users` ((lower(`email`)),(lower(`email`)));',
|
|
603
|
-
'CREATE INDEX `indexCol` ON `users` (`email`);',
|
|
604
|
-
'CREATE INDEX `indexColMultiple` ON `users` (`email`,`email`);',
|
|
605
|
-
'CREATE INDEX `indexColExpr` ON `users` ((lower(`email`)),`email`);',
|
|
606
|
-
]);
|
|
607
|
-
});
|
|
608
|
-
|
|
609
|
-
test('varchar and text default values escape single quotes', async (t) => {
|
|
610
|
-
const schema1 = {
|
|
611
|
-
table: mysqlTable('table', {
|
|
612
|
-
id: serial('id').primaryKey(),
|
|
613
|
-
}),
|
|
614
|
-
};
|
|
615
|
-
|
|
616
|
-
const schem2 = {
|
|
617
|
-
table: mysqlTable('table', {
|
|
618
|
-
id: serial('id').primaryKey(),
|
|
619
|
-
enum: mysqlEnum('enum', ["escape's quotes", "escape's quotes 2"]).default("escape's quotes"),
|
|
620
|
-
text: text('text').default("escape's quotes"),
|
|
621
|
-
varchar: varchar('varchar', { length: 255 }).default("escape's quotes"),
|
|
622
|
-
}),
|
|
623
|
-
};
|
|
624
|
-
|
|
625
|
-
const { sqlStatements } = await diffTestSchemasMysql(schema1, schem2, []);
|
|
626
|
-
|
|
627
|
-
expect(sqlStatements.length).toBe(3);
|
|
628
|
-
expect(sqlStatements[0]).toStrictEqual(
|
|
629
|
-
"ALTER TABLE `table` ADD `enum` enum('escape''s quotes','escape''s quotes 2') DEFAULT 'escape''s quotes';",
|
|
630
|
-
);
|
|
631
|
-
expect(sqlStatements[1]).toStrictEqual(
|
|
632
|
-
"ALTER TABLE `table` ADD `text` text DEFAULT ('escape''s quotes');",
|
|
633
|
-
);
|
|
634
|
-
expect(sqlStatements[2]).toStrictEqual(
|
|
635
|
-
"ALTER TABLE `table` ADD `varchar` varchar(255) DEFAULT 'escape''s quotes';",
|
|
636
|
-
);
|
|
637
|
-
});
|
|
638
|
-
|
|
639
|
-
test('composite primary key', async () => {
|
|
640
|
-
const from = {};
|
|
641
|
-
const to = {
|
|
642
|
-
table: mysqlTable('works_to_creators', {
|
|
643
|
-
workId: int('work_id').notNull(),
|
|
644
|
-
creatorId: int('creator_id').notNull(),
|
|
645
|
-
classification: text('classification').notNull(),
|
|
646
|
-
}, (t) => ({
|
|
647
|
-
pk: primaryKey({
|
|
648
|
-
columns: [t.workId, t.creatorId, t.classification],
|
|
649
|
-
}),
|
|
650
|
-
})),
|
|
651
|
-
};
|
|
652
|
-
|
|
653
|
-
const { sqlStatements } = await diffTestSchemasMysql(from, to, []);
|
|
654
|
-
|
|
655
|
-
expect(sqlStatements).toStrictEqual([
|
|
656
|
-
'CREATE TABLE `works_to_creators` (\n\t`work_id` int NOT NULL,\n\t`creator_id` int NOT NULL,\n\t`classification` text NOT NULL,\n\tCONSTRAINT `works_to_creators_work_id_creator_id_classification_pk` PRIMARY KEY(`work_id`,`creator_id`,`classification`)\n);\n',
|
|
657
|
-
]);
|
|
658
|
-
});
|
|
659
|
-
|
|
660
|
-
test('add column before creating unique constraint', async () => {
|
|
661
|
-
const from = {
|
|
662
|
-
table: mysqlTable('table', {
|
|
663
|
-
id: serial('id').primaryKey(),
|
|
664
|
-
}),
|
|
665
|
-
};
|
|
666
|
-
const to = {
|
|
667
|
-
table: mysqlTable('table', {
|
|
668
|
-
id: serial('id').primaryKey(),
|
|
669
|
-
name: text('name').notNull(),
|
|
670
|
-
}, (t) => ({
|
|
671
|
-
uq: unique('uq').on(t.name),
|
|
672
|
-
})),
|
|
673
|
-
};
|
|
674
|
-
|
|
675
|
-
const { sqlStatements } = await diffTestSchemasMysql(from, to, []);
|
|
676
|
-
|
|
677
|
-
expect(sqlStatements).toStrictEqual([
|
|
678
|
-
'ALTER TABLE `table` ADD `name` text NOT NULL;',
|
|
679
|
-
'ALTER TABLE `table` ADD CONSTRAINT `uq` UNIQUE(`name`);',
|
|
680
|
-
]);
|
|
681
|
-
});
|
|
682
|
-
|
|
683
|
-
test('optional db aliases (snake case)', async () => {
|
|
684
|
-
const from = {};
|
|
685
|
-
|
|
686
|
-
const t1 = mysqlTable(
|
|
687
|
-
't1',
|
|
688
|
-
{
|
|
689
|
-
t1Id1: int().notNull().primaryKey(),
|
|
690
|
-
t1Col2: int().notNull(),
|
|
691
|
-
t1Col3: int().notNull(),
|
|
692
|
-
t2Ref: int().notNull().references(() => t2.t2Id),
|
|
693
|
-
t1Uni: int().notNull(),
|
|
694
|
-
t1UniIdx: int().notNull(),
|
|
695
|
-
t1Idx: int().notNull(),
|
|
696
|
-
},
|
|
697
|
-
(table) => ({
|
|
698
|
-
uni: unique('t1_uni').on(table.t1Uni),
|
|
699
|
-
uniIdx: uniqueIndex('t1_uni_idx').on(table.t1UniIdx),
|
|
700
|
-
idx: index('t1_idx').on(table.t1Idx),
|
|
701
|
-
fk: foreignKey({
|
|
702
|
-
columns: [table.t1Col2, table.t1Col3],
|
|
703
|
-
foreignColumns: [t3.t3Id1, t3.t3Id2],
|
|
704
|
-
}),
|
|
705
|
-
}),
|
|
706
|
-
);
|
|
707
|
-
|
|
708
|
-
const t2 = mysqlTable(
|
|
709
|
-
't2',
|
|
710
|
-
{
|
|
711
|
-
t2Id: serial().primaryKey(),
|
|
712
|
-
},
|
|
713
|
-
);
|
|
714
|
-
|
|
715
|
-
const t3 = mysqlTable(
|
|
716
|
-
't3',
|
|
717
|
-
{
|
|
718
|
-
t3Id1: int(),
|
|
719
|
-
t3Id2: int(),
|
|
720
|
-
},
|
|
721
|
-
(table) => ({
|
|
722
|
-
pk: primaryKey({
|
|
723
|
-
columns: [table.t3Id1, table.t3Id2],
|
|
724
|
-
}),
|
|
725
|
-
}),
|
|
726
|
-
);
|
|
727
|
-
|
|
728
|
-
const to = {
|
|
729
|
-
t1,
|
|
730
|
-
t2,
|
|
731
|
-
t3,
|
|
732
|
-
};
|
|
733
|
-
|
|
734
|
-
const { sqlStatements } = await diffTestSchemasMysql(from, to, [], false, 'snake_case');
|
|
735
|
-
|
|
736
|
-
const st1 = `CREATE TABLE \`t1\` (
|
|
737
|
-
\`t1_id1\` int NOT NULL,
|
|
738
|
-
\`t1_col2\` int NOT NULL,
|
|
739
|
-
\`t1_col3\` int NOT NULL,
|
|
740
|
-
\`t2_ref\` int NOT NULL,
|
|
741
|
-
\`t1_uni\` int NOT NULL,
|
|
742
|
-
\`t1_uni_idx\` int NOT NULL,
|
|
743
|
-
\`t1_idx\` int NOT NULL,
|
|
744
|
-
CONSTRAINT \`t1_t1_id1\` PRIMARY KEY(\`t1_id1\`),
|
|
745
|
-
CONSTRAINT \`t1_uni\` UNIQUE(\`t1_uni\`),
|
|
746
|
-
CONSTRAINT \`t1_uni_idx\` UNIQUE(\`t1_uni_idx\`)
|
|
747
|
-
);
|
|
748
|
-
`;
|
|
749
|
-
|
|
750
|
-
const st2 = `CREATE TABLE \`t2\` (
|
|
751
|
-
\`t2_id\` serial AUTO_INCREMENT NOT NULL,
|
|
752
|
-
CONSTRAINT \`t2_t2_id\` PRIMARY KEY(\`t2_id\`)
|
|
753
|
-
);
|
|
754
|
-
`;
|
|
755
|
-
|
|
756
|
-
const st3 = `CREATE TABLE \`t3\` (
|
|
757
|
-
\`t3_id1\` int NOT NULL,
|
|
758
|
-
\`t3_id2\` int NOT NULL,
|
|
759
|
-
CONSTRAINT \`t3_t3_id1_t3_id2_pk\` PRIMARY KEY(\`t3_id1\`,\`t3_id2\`)
|
|
760
|
-
);
|
|
761
|
-
`;
|
|
762
|
-
|
|
763
|
-
const st4 =
|
|
764
|
-
`ALTER TABLE \`t1\` ADD CONSTRAINT \`t1_t2_ref_t2_t2_id_fk\` FOREIGN KEY (\`t2_ref\`) REFERENCES \`t2\`(\`t2_id\`) ON DELETE no action ON UPDATE no action;`;
|
|
765
|
-
|
|
766
|
-
const st5 =
|
|
767
|
-
`ALTER TABLE \`t1\` ADD CONSTRAINT \`t1_t1_col2_t1_col3_t3_t3_id1_t3_id2_fk\` FOREIGN KEY (\`t1_col2\`,\`t1_col3\`) REFERENCES \`t3\`(\`t3_id1\`,\`t3_id2\`) ON DELETE no action ON UPDATE no action;`;
|
|
768
|
-
|
|
769
|
-
const st6 = `CREATE INDEX \`t1_idx\` ON \`t1\` (\`t1_idx\`);`;
|
|
770
|
-
|
|
771
|
-
expect(sqlStatements).toStrictEqual([st1, st2, st3, st4, st5, st6]);
|
|
772
|
-
});
|
|
773
|
-
|
|
774
|
-
test('optional db aliases (camel case)', async () => {
|
|
775
|
-
const from = {};
|
|
776
|
-
|
|
777
|
-
const t1 = mysqlTable(
|
|
778
|
-
't1',
|
|
779
|
-
{
|
|
780
|
-
t1_id1: int().notNull().primaryKey(),
|
|
781
|
-
t1_col2: int().notNull(),
|
|
782
|
-
t1_col3: int().notNull(),
|
|
783
|
-
t2_ref: int().notNull().references(() => t2.t2_id),
|
|
784
|
-
t1_uni: int().notNull(),
|
|
785
|
-
t1_uni_idx: int().notNull(),
|
|
786
|
-
t1_idx: int().notNull(),
|
|
787
|
-
},
|
|
788
|
-
(table) => ({
|
|
789
|
-
uni: unique('t1Uni').on(table.t1_uni),
|
|
790
|
-
uni_idx: uniqueIndex('t1UniIdx').on(table.t1_uni_idx),
|
|
791
|
-
idx: index('t1Idx').on(table.t1_idx),
|
|
792
|
-
fk: foreignKey({
|
|
793
|
-
columns: [table.t1_col2, table.t1_col3],
|
|
794
|
-
foreignColumns: [t3.t3_id1, t3.t3_id2],
|
|
795
|
-
}),
|
|
796
|
-
}),
|
|
797
|
-
);
|
|
798
|
-
|
|
799
|
-
const t2 = mysqlTable(
|
|
800
|
-
't2',
|
|
801
|
-
{
|
|
802
|
-
t2_id: serial().primaryKey(),
|
|
803
|
-
},
|
|
804
|
-
);
|
|
805
|
-
|
|
806
|
-
const t3 = mysqlTable(
|
|
807
|
-
't3',
|
|
808
|
-
{
|
|
809
|
-
t3_id1: int(),
|
|
810
|
-
t3_id2: int(),
|
|
811
|
-
},
|
|
812
|
-
(table) => ({
|
|
813
|
-
pk: primaryKey({
|
|
814
|
-
columns: [table.t3_id1, table.t3_id2],
|
|
815
|
-
}),
|
|
816
|
-
}),
|
|
817
|
-
);
|
|
818
|
-
|
|
819
|
-
const to = {
|
|
820
|
-
t1,
|
|
821
|
-
t2,
|
|
822
|
-
t3,
|
|
823
|
-
};
|
|
824
|
-
|
|
825
|
-
const { sqlStatements } = await diffTestSchemasMysql(from, to, [], false, 'camelCase');
|
|
826
|
-
|
|
827
|
-
const st1 = `CREATE TABLE \`t1\` (
|
|
828
|
-
\`t1Id1\` int NOT NULL,
|
|
829
|
-
\`t1Col2\` int NOT NULL,
|
|
830
|
-
\`t1Col3\` int NOT NULL,
|
|
831
|
-
\`t2Ref\` int NOT NULL,
|
|
832
|
-
\`t1Uni\` int NOT NULL,
|
|
833
|
-
\`t1UniIdx\` int NOT NULL,
|
|
834
|
-
\`t1Idx\` int NOT NULL,
|
|
835
|
-
CONSTRAINT \`t1_t1Id1\` PRIMARY KEY(\`t1Id1\`),
|
|
836
|
-
CONSTRAINT \`t1Uni\` UNIQUE(\`t1Uni\`),
|
|
837
|
-
CONSTRAINT \`t1UniIdx\` UNIQUE(\`t1UniIdx\`)
|
|
838
|
-
);
|
|
839
|
-
`;
|
|
840
|
-
|
|
841
|
-
const st2 = `CREATE TABLE \`t2\` (
|
|
842
|
-
\`t2Id\` serial AUTO_INCREMENT NOT NULL,
|
|
843
|
-
CONSTRAINT \`t2_t2Id\` PRIMARY KEY(\`t2Id\`)
|
|
844
|
-
);
|
|
845
|
-
`;
|
|
846
|
-
|
|
847
|
-
const st3 = `CREATE TABLE \`t3\` (
|
|
848
|
-
\`t3Id1\` int NOT NULL,
|
|
849
|
-
\`t3Id2\` int NOT NULL,
|
|
850
|
-
CONSTRAINT \`t3_t3Id1_t3Id2_pk\` PRIMARY KEY(\`t3Id1\`,\`t3Id2\`)
|
|
851
|
-
);
|
|
852
|
-
`;
|
|
853
|
-
|
|
854
|
-
const st4 =
|
|
855
|
-
`ALTER TABLE \`t1\` ADD CONSTRAINT \`t1_t2Ref_t2_t2Id_fk\` FOREIGN KEY (\`t2Ref\`) REFERENCES \`t2\`(\`t2Id\`) ON DELETE no action ON UPDATE no action;`;
|
|
856
|
-
|
|
857
|
-
const st5 =
|
|
858
|
-
`ALTER TABLE \`t1\` ADD CONSTRAINT \`t1_t1Col2_t1Col3_t3_t3Id1_t3Id2_fk\` FOREIGN KEY (\`t1Col2\`,\`t1Col3\`) REFERENCES \`t3\`(\`t3Id1\`,\`t3Id2\`) ON DELETE no action ON UPDATE no action;`;
|
|
859
|
-
|
|
860
|
-
const st6 = `CREATE INDEX \`t1Idx\` ON \`t1\` (\`t1Idx\`);`;
|
|
861
|
-
|
|
862
|
-
expect(sqlStatements).toStrictEqual([st1, st2, st3, st4, st5, st6]);
|
|
863
|
-
});
|