@anthonyalayo/drizzle-kit 1.0.2 → 1.0.5
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 +2 -2
- 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
|
@@ -1,978 +0,0 @@
|
|
|
1
|
-
import { sql } from 'drizzle-orm';
|
|
2
|
-
import {
|
|
3
|
-
index,
|
|
4
|
-
int,
|
|
5
|
-
json,
|
|
6
|
-
primaryKey,
|
|
7
|
-
serial,
|
|
8
|
-
singlestoreSchema,
|
|
9
|
-
singlestoreTable,
|
|
10
|
-
text,
|
|
11
|
-
uniqueIndex,
|
|
12
|
-
} from 'drizzle-orm/singlestore-core';
|
|
13
|
-
import { expect, test } from 'vitest';
|
|
14
|
-
import { diffTestSchemasSingleStore } from './schemaDiffer';
|
|
15
|
-
|
|
16
|
-
test('add table #1', async () => {
|
|
17
|
-
const to = {
|
|
18
|
-
users: singlestoreTable('users', {}),
|
|
19
|
-
};
|
|
20
|
-
|
|
21
|
-
const { statements } = await diffTestSchemasSingleStore({}, to, []);
|
|
22
|
-
|
|
23
|
-
expect(statements.length).toBe(1);
|
|
24
|
-
expect(statements[0]).toStrictEqual({
|
|
25
|
-
type: 'create_table',
|
|
26
|
-
tableName: 'users',
|
|
27
|
-
schema: undefined,
|
|
28
|
-
columns: [],
|
|
29
|
-
compositePKs: [],
|
|
30
|
-
internals: {
|
|
31
|
-
tables: {},
|
|
32
|
-
indexes: {},
|
|
33
|
-
},
|
|
34
|
-
uniqueConstraints: [],
|
|
35
|
-
compositePkName: '',
|
|
36
|
-
});
|
|
37
|
-
});
|
|
38
|
-
|
|
39
|
-
test('add table #2', async () => {
|
|
40
|
-
const to = {
|
|
41
|
-
users: singlestoreTable('users', {
|
|
42
|
-
id: serial('id').primaryKey(),
|
|
43
|
-
}),
|
|
44
|
-
};
|
|
45
|
-
|
|
46
|
-
const { statements } = await diffTestSchemasSingleStore({}, to, []);
|
|
47
|
-
|
|
48
|
-
expect(statements.length).toBe(1);
|
|
49
|
-
expect(statements[0]).toStrictEqual({
|
|
50
|
-
type: 'create_table',
|
|
51
|
-
tableName: 'users',
|
|
52
|
-
schema: undefined,
|
|
53
|
-
columns: [
|
|
54
|
-
{
|
|
55
|
-
name: 'id',
|
|
56
|
-
notNull: true,
|
|
57
|
-
primaryKey: false,
|
|
58
|
-
type: 'serial',
|
|
59
|
-
autoincrement: true,
|
|
60
|
-
},
|
|
61
|
-
],
|
|
62
|
-
compositePKs: ['users_id;id'],
|
|
63
|
-
compositePkName: 'users_id',
|
|
64
|
-
uniqueConstraints: [],
|
|
65
|
-
internals: {
|
|
66
|
-
tables: {},
|
|
67
|
-
indexes: {},
|
|
68
|
-
},
|
|
69
|
-
});
|
|
70
|
-
});
|
|
71
|
-
|
|
72
|
-
test('add table #3', async () => {
|
|
73
|
-
const to = {
|
|
74
|
-
users: singlestoreTable(
|
|
75
|
-
'users',
|
|
76
|
-
{
|
|
77
|
-
id: serial('id'),
|
|
78
|
-
},
|
|
79
|
-
(t) => {
|
|
80
|
-
return {
|
|
81
|
-
pk: primaryKey({
|
|
82
|
-
name: 'users_pk',
|
|
83
|
-
columns: [t.id],
|
|
84
|
-
}),
|
|
85
|
-
};
|
|
86
|
-
},
|
|
87
|
-
),
|
|
88
|
-
};
|
|
89
|
-
|
|
90
|
-
const { statements } = await diffTestSchemasSingleStore({}, to, []);
|
|
91
|
-
|
|
92
|
-
expect(statements.length).toBe(1);
|
|
93
|
-
expect(statements[0]).toStrictEqual({
|
|
94
|
-
type: 'create_table',
|
|
95
|
-
tableName: 'users',
|
|
96
|
-
schema: undefined,
|
|
97
|
-
columns: [
|
|
98
|
-
{
|
|
99
|
-
name: 'id',
|
|
100
|
-
notNull: true,
|
|
101
|
-
primaryKey: false,
|
|
102
|
-
type: 'serial',
|
|
103
|
-
autoincrement: true,
|
|
104
|
-
},
|
|
105
|
-
],
|
|
106
|
-
compositePKs: ['users_pk;id'],
|
|
107
|
-
uniqueConstraints: [],
|
|
108
|
-
compositePkName: 'users_pk',
|
|
109
|
-
internals: {
|
|
110
|
-
tables: {},
|
|
111
|
-
indexes: {},
|
|
112
|
-
},
|
|
113
|
-
});
|
|
114
|
-
});
|
|
115
|
-
|
|
116
|
-
test('add table #4', async () => {
|
|
117
|
-
const to = {
|
|
118
|
-
users: singlestoreTable('users', {}),
|
|
119
|
-
posts: singlestoreTable('posts', {}),
|
|
120
|
-
};
|
|
121
|
-
|
|
122
|
-
const { statements } = await diffTestSchemasSingleStore({}, to, []);
|
|
123
|
-
|
|
124
|
-
expect(statements.length).toBe(2);
|
|
125
|
-
expect(statements[0]).toStrictEqual({
|
|
126
|
-
type: 'create_table',
|
|
127
|
-
tableName: 'users',
|
|
128
|
-
schema: undefined,
|
|
129
|
-
columns: [],
|
|
130
|
-
internals: {
|
|
131
|
-
tables: {},
|
|
132
|
-
indexes: {},
|
|
133
|
-
},
|
|
134
|
-
compositePKs: [],
|
|
135
|
-
uniqueConstraints: [],
|
|
136
|
-
compositePkName: '',
|
|
137
|
-
});
|
|
138
|
-
expect(statements[1]).toStrictEqual({
|
|
139
|
-
type: 'create_table',
|
|
140
|
-
tableName: 'posts',
|
|
141
|
-
schema: undefined,
|
|
142
|
-
columns: [],
|
|
143
|
-
compositePKs: [],
|
|
144
|
-
internals: {
|
|
145
|
-
tables: {},
|
|
146
|
-
indexes: {},
|
|
147
|
-
},
|
|
148
|
-
uniqueConstraints: [],
|
|
149
|
-
compositePkName: '',
|
|
150
|
-
});
|
|
151
|
-
});
|
|
152
|
-
|
|
153
|
-
test('add table #5', async () => {
|
|
154
|
-
const schema = singlestoreSchema('folder');
|
|
155
|
-
const from = {
|
|
156
|
-
schema,
|
|
157
|
-
};
|
|
158
|
-
|
|
159
|
-
const to = {
|
|
160
|
-
schema,
|
|
161
|
-
users: schema.table('users', {}),
|
|
162
|
-
};
|
|
163
|
-
|
|
164
|
-
const { statements } = await diffTestSchemasSingleStore(from, to, []);
|
|
165
|
-
|
|
166
|
-
expect(statements.length).toBe(0);
|
|
167
|
-
});
|
|
168
|
-
|
|
169
|
-
test('add table #6', async () => {
|
|
170
|
-
const from = {
|
|
171
|
-
users1: singlestoreTable('users1', {}),
|
|
172
|
-
};
|
|
173
|
-
|
|
174
|
-
const to = {
|
|
175
|
-
users2: singlestoreTable('users2', {}),
|
|
176
|
-
};
|
|
177
|
-
|
|
178
|
-
const { statements } = await diffTestSchemasSingleStore(from, to, []);
|
|
179
|
-
|
|
180
|
-
expect(statements.length).toBe(2);
|
|
181
|
-
expect(statements[0]).toStrictEqual({
|
|
182
|
-
type: 'create_table',
|
|
183
|
-
tableName: 'users2',
|
|
184
|
-
schema: undefined,
|
|
185
|
-
columns: [],
|
|
186
|
-
internals: {
|
|
187
|
-
tables: {},
|
|
188
|
-
indexes: {},
|
|
189
|
-
},
|
|
190
|
-
compositePKs: [],
|
|
191
|
-
uniqueConstraints: [],
|
|
192
|
-
compositePkName: '',
|
|
193
|
-
});
|
|
194
|
-
expect(statements[1]).toStrictEqual({
|
|
195
|
-
policies: [],
|
|
196
|
-
type: 'drop_table',
|
|
197
|
-
tableName: 'users1',
|
|
198
|
-
schema: undefined,
|
|
199
|
-
});
|
|
200
|
-
});
|
|
201
|
-
|
|
202
|
-
test('add table #7', async () => {
|
|
203
|
-
const from = {
|
|
204
|
-
users1: singlestoreTable('users1', {}),
|
|
205
|
-
};
|
|
206
|
-
|
|
207
|
-
const to = {
|
|
208
|
-
users: singlestoreTable('users', {}),
|
|
209
|
-
users2: singlestoreTable('users2', {}),
|
|
210
|
-
};
|
|
211
|
-
|
|
212
|
-
const { statements } = await diffTestSchemasSingleStore(from, to, [
|
|
213
|
-
'public.users1->public.users2',
|
|
214
|
-
]);
|
|
215
|
-
|
|
216
|
-
expect(statements.length).toBe(2);
|
|
217
|
-
expect(statements[0]).toStrictEqual({
|
|
218
|
-
type: 'rename_table',
|
|
219
|
-
tableNameFrom: 'users1',
|
|
220
|
-
tableNameTo: 'users2',
|
|
221
|
-
fromSchema: undefined,
|
|
222
|
-
toSchema: undefined,
|
|
223
|
-
});
|
|
224
|
-
expect(statements[1]).toStrictEqual({
|
|
225
|
-
type: 'create_table',
|
|
226
|
-
tableName: 'users',
|
|
227
|
-
schema: undefined,
|
|
228
|
-
columns: [],
|
|
229
|
-
compositePKs: [],
|
|
230
|
-
uniqueConstraints: [],
|
|
231
|
-
internals: {
|
|
232
|
-
tables: {},
|
|
233
|
-
indexes: {},
|
|
234
|
-
},
|
|
235
|
-
compositePkName: '',
|
|
236
|
-
});
|
|
237
|
-
});
|
|
238
|
-
|
|
239
|
-
test('add schema + table #1', async () => {
|
|
240
|
-
const schema = singlestoreSchema('folder');
|
|
241
|
-
|
|
242
|
-
const to = {
|
|
243
|
-
schema,
|
|
244
|
-
users: schema.table('users', {}),
|
|
245
|
-
};
|
|
246
|
-
|
|
247
|
-
const { statements } = await diffTestSchemasSingleStore({}, to, []);
|
|
248
|
-
|
|
249
|
-
expect(statements.length).toBe(0);
|
|
250
|
-
});
|
|
251
|
-
|
|
252
|
-
test('change schema with tables #1', async () => {
|
|
253
|
-
const schema = singlestoreSchema('folder');
|
|
254
|
-
const schema2 = singlestoreSchema('folder2');
|
|
255
|
-
const from = {
|
|
256
|
-
schema,
|
|
257
|
-
users: schema.table('users', {}),
|
|
258
|
-
};
|
|
259
|
-
const to = {
|
|
260
|
-
schema2,
|
|
261
|
-
users: schema2.table('users', {}),
|
|
262
|
-
};
|
|
263
|
-
|
|
264
|
-
const { statements } = await diffTestSchemasSingleStore(from, to, [
|
|
265
|
-
'folder->folder2',
|
|
266
|
-
]);
|
|
267
|
-
|
|
268
|
-
expect(statements.length).toBe(0);
|
|
269
|
-
});
|
|
270
|
-
|
|
271
|
-
test('change table schema #1', async () => {
|
|
272
|
-
const schema = singlestoreSchema('folder');
|
|
273
|
-
const from = {
|
|
274
|
-
schema,
|
|
275
|
-
users: singlestoreTable('users', {}),
|
|
276
|
-
};
|
|
277
|
-
const to = {
|
|
278
|
-
schema,
|
|
279
|
-
users: schema.table('users', {}),
|
|
280
|
-
};
|
|
281
|
-
|
|
282
|
-
const { statements } = await diffTestSchemasSingleStore(from, to, [
|
|
283
|
-
'public.users->folder.users',
|
|
284
|
-
]);
|
|
285
|
-
|
|
286
|
-
expect(statements.length).toBe(1);
|
|
287
|
-
expect(statements[0]).toStrictEqual({
|
|
288
|
-
policies: [],
|
|
289
|
-
type: 'drop_table',
|
|
290
|
-
tableName: 'users',
|
|
291
|
-
schema: undefined,
|
|
292
|
-
});
|
|
293
|
-
});
|
|
294
|
-
|
|
295
|
-
test('change table schema #2', async () => {
|
|
296
|
-
const schema = singlestoreSchema('folder');
|
|
297
|
-
const from = {
|
|
298
|
-
schema,
|
|
299
|
-
users: schema.table('users', {}),
|
|
300
|
-
};
|
|
301
|
-
const to = {
|
|
302
|
-
schema,
|
|
303
|
-
users: singlestoreTable('users', {}),
|
|
304
|
-
};
|
|
305
|
-
|
|
306
|
-
const { statements } = await diffTestSchemasSingleStore(from, to, [
|
|
307
|
-
'folder.users->public.users',
|
|
308
|
-
]);
|
|
309
|
-
|
|
310
|
-
expect(statements.length).toBe(1);
|
|
311
|
-
expect(statements[0]).toStrictEqual({
|
|
312
|
-
type: 'create_table',
|
|
313
|
-
tableName: 'users',
|
|
314
|
-
schema: undefined,
|
|
315
|
-
columns: [],
|
|
316
|
-
uniqueConstraints: [],
|
|
317
|
-
compositePkName: '',
|
|
318
|
-
compositePKs: [],
|
|
319
|
-
internals: {
|
|
320
|
-
tables: {},
|
|
321
|
-
indexes: {},
|
|
322
|
-
},
|
|
323
|
-
});
|
|
324
|
-
});
|
|
325
|
-
|
|
326
|
-
test('change table schema #3', async () => {
|
|
327
|
-
const schema1 = singlestoreSchema('folder1');
|
|
328
|
-
const schema2 = singlestoreSchema('folder2');
|
|
329
|
-
const from = {
|
|
330
|
-
schema1,
|
|
331
|
-
schema2,
|
|
332
|
-
users: schema1.table('users', {}),
|
|
333
|
-
};
|
|
334
|
-
const to = {
|
|
335
|
-
schema1,
|
|
336
|
-
schema2,
|
|
337
|
-
users: schema2.table('users', {}),
|
|
338
|
-
};
|
|
339
|
-
|
|
340
|
-
const { statements } = await diffTestSchemasSingleStore(from, to, [
|
|
341
|
-
'folder1.users->folder2.users',
|
|
342
|
-
]);
|
|
343
|
-
|
|
344
|
-
expect(statements.length).toBe(0);
|
|
345
|
-
});
|
|
346
|
-
|
|
347
|
-
test('change table schema #4', async () => {
|
|
348
|
-
const schema1 = singlestoreSchema('folder1');
|
|
349
|
-
const schema2 = singlestoreSchema('folder2');
|
|
350
|
-
const from = {
|
|
351
|
-
schema1,
|
|
352
|
-
users: schema1.table('users', {}),
|
|
353
|
-
};
|
|
354
|
-
const to = {
|
|
355
|
-
schema1,
|
|
356
|
-
schema2, // add schema
|
|
357
|
-
users: schema2.table('users', {}), // move table
|
|
358
|
-
};
|
|
359
|
-
|
|
360
|
-
const { statements } = await diffTestSchemasSingleStore(from, to, [
|
|
361
|
-
'folder1.users->folder2.users',
|
|
362
|
-
]);
|
|
363
|
-
|
|
364
|
-
expect(statements.length).toBe(0);
|
|
365
|
-
});
|
|
366
|
-
|
|
367
|
-
test('change table schema #5', async () => {
|
|
368
|
-
const schema1 = singlestoreSchema('folder1');
|
|
369
|
-
const schema2 = singlestoreSchema('folder2');
|
|
370
|
-
const from = {
|
|
371
|
-
schema1, // remove schema
|
|
372
|
-
users: schema1.table('users', {}),
|
|
373
|
-
};
|
|
374
|
-
const to = {
|
|
375
|
-
schema2, // add schema
|
|
376
|
-
users: schema2.table('users', {}), // move table
|
|
377
|
-
};
|
|
378
|
-
|
|
379
|
-
const { statements } = await diffTestSchemasSingleStore(from, to, [
|
|
380
|
-
'folder1.users->folder2.users',
|
|
381
|
-
]);
|
|
382
|
-
|
|
383
|
-
expect(statements.length).toBe(0);
|
|
384
|
-
});
|
|
385
|
-
|
|
386
|
-
test('change table schema #5', async () => {
|
|
387
|
-
const schema1 = singlestoreSchema('folder1');
|
|
388
|
-
const schema2 = singlestoreSchema('folder2');
|
|
389
|
-
const from = {
|
|
390
|
-
schema1,
|
|
391
|
-
schema2,
|
|
392
|
-
users: schema1.table('users', {}),
|
|
393
|
-
};
|
|
394
|
-
const to = {
|
|
395
|
-
schema1,
|
|
396
|
-
schema2,
|
|
397
|
-
users: schema2.table('users2', {}), // rename and move table
|
|
398
|
-
};
|
|
399
|
-
|
|
400
|
-
const { statements } = await diffTestSchemasSingleStore(from, to, [
|
|
401
|
-
'folder1.users->folder2.users2',
|
|
402
|
-
]);
|
|
403
|
-
|
|
404
|
-
expect(statements.length).toBe(0);
|
|
405
|
-
});
|
|
406
|
-
|
|
407
|
-
test('change table schema #6', async () => {
|
|
408
|
-
const schema1 = singlestoreSchema('folder1');
|
|
409
|
-
const schema2 = singlestoreSchema('folder2');
|
|
410
|
-
const from = {
|
|
411
|
-
schema1,
|
|
412
|
-
users: schema1.table('users', {}),
|
|
413
|
-
};
|
|
414
|
-
const to = {
|
|
415
|
-
schema2, // rename schema
|
|
416
|
-
users: schema2.table('users2', {}), // rename table
|
|
417
|
-
};
|
|
418
|
-
|
|
419
|
-
const { statements } = await diffTestSchemasSingleStore(from, to, [
|
|
420
|
-
'folder1->folder2',
|
|
421
|
-
'folder2.users->folder2.users2',
|
|
422
|
-
]);
|
|
423
|
-
|
|
424
|
-
expect(statements.length).toBe(0);
|
|
425
|
-
});
|
|
426
|
-
|
|
427
|
-
test('add table #10', async () => {
|
|
428
|
-
const to = {
|
|
429
|
-
users: singlestoreTable('table', {
|
|
430
|
-
json: json('json').default({}),
|
|
431
|
-
}),
|
|
432
|
-
};
|
|
433
|
-
|
|
434
|
-
const { sqlStatements } = await diffTestSchemasSingleStore({}, to, []);
|
|
435
|
-
expect(sqlStatements.length).toBe(1);
|
|
436
|
-
expect(sqlStatements[0]).toBe(
|
|
437
|
-
"CREATE TABLE `table` (\n\t`json` json DEFAULT '{}'\n);\n",
|
|
438
|
-
);
|
|
439
|
-
});
|
|
440
|
-
|
|
441
|
-
test('add table #11', async () => {
|
|
442
|
-
const to = {
|
|
443
|
-
users: singlestoreTable('table', {
|
|
444
|
-
json: json('json').default([]),
|
|
445
|
-
}),
|
|
446
|
-
};
|
|
447
|
-
|
|
448
|
-
const { sqlStatements } = await diffTestSchemasSingleStore({}, to, []);
|
|
449
|
-
expect(sqlStatements.length).toBe(1);
|
|
450
|
-
expect(sqlStatements[0]).toBe(
|
|
451
|
-
"CREATE TABLE `table` (\n\t`json` json DEFAULT '[]'\n);\n",
|
|
452
|
-
);
|
|
453
|
-
});
|
|
454
|
-
|
|
455
|
-
test('add table #12', async () => {
|
|
456
|
-
const to = {
|
|
457
|
-
users: singlestoreTable('table', {
|
|
458
|
-
json: json('json').default([1, 2, 3]),
|
|
459
|
-
}),
|
|
460
|
-
};
|
|
461
|
-
|
|
462
|
-
const { sqlStatements } = await diffTestSchemasSingleStore({}, to, []);
|
|
463
|
-
expect(sqlStatements.length).toBe(1);
|
|
464
|
-
expect(sqlStatements[0]).toBe(
|
|
465
|
-
"CREATE TABLE `table` (\n\t`json` json DEFAULT '[1,2,3]'\n);\n",
|
|
466
|
-
);
|
|
467
|
-
});
|
|
468
|
-
|
|
469
|
-
test('add table #13', async () => {
|
|
470
|
-
const to = {
|
|
471
|
-
users: singlestoreTable('table', {
|
|
472
|
-
json: json('json').default({ key: 'value' }),
|
|
473
|
-
}),
|
|
474
|
-
};
|
|
475
|
-
|
|
476
|
-
const { sqlStatements } = await diffTestSchemasSingleStore({}, to, []);
|
|
477
|
-
expect(sqlStatements.length).toBe(1);
|
|
478
|
-
expect(sqlStatements[0]).toBe(
|
|
479
|
-
'CREATE TABLE `table` (\n\t`json` json DEFAULT \'{"key":"value"}\'\n);\n',
|
|
480
|
-
);
|
|
481
|
-
});
|
|
482
|
-
|
|
483
|
-
test('add table #14', async () => {
|
|
484
|
-
const to = {
|
|
485
|
-
users: singlestoreTable('table', {
|
|
486
|
-
json: json('json').default({
|
|
487
|
-
key: 'value',
|
|
488
|
-
arr: [1, 2, 3],
|
|
489
|
-
}),
|
|
490
|
-
}),
|
|
491
|
-
};
|
|
492
|
-
|
|
493
|
-
const { sqlStatements } = await diffTestSchemasSingleStore({}, to, []);
|
|
494
|
-
expect(sqlStatements.length).toBe(1);
|
|
495
|
-
expect(sqlStatements[0]).toBe(
|
|
496
|
-
'CREATE TABLE `table` (\n\t`json` json DEFAULT \'{"key":"value","arr":[1,2,3]}\'\n);\n',
|
|
497
|
-
);
|
|
498
|
-
});
|
|
499
|
-
|
|
500
|
-
// TODO: add bson type tests
|
|
501
|
-
|
|
502
|
-
// TODO: add blob type tests
|
|
503
|
-
|
|
504
|
-
// TODO: add uuid type tests
|
|
505
|
-
|
|
506
|
-
// TODO: add guid type tests
|
|
507
|
-
|
|
508
|
-
// TODO: add vector type tests
|
|
509
|
-
|
|
510
|
-
// TODO: add geopoint type tests
|
|
511
|
-
|
|
512
|
-
test('drop index', async () => {
|
|
513
|
-
const from = {
|
|
514
|
-
users: singlestoreTable(
|
|
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: singlestoreTable('table', {
|
|
529
|
-
name: text('name'),
|
|
530
|
-
}),
|
|
531
|
-
};
|
|
532
|
-
|
|
533
|
-
const { sqlStatements } = await diffTestSchemasSingleStore(from, to, []);
|
|
534
|
-
expect(sqlStatements.length).toBe(1);
|
|
535
|
-
expect(sqlStatements[0]).toBe('DROP INDEX `name_idx` ON `table`;');
|
|
536
|
-
});
|
|
537
|
-
|
|
538
|
-
test('add table with indexes', async () => {
|
|
539
|
-
const from = {};
|
|
540
|
-
|
|
541
|
-
const to = {
|
|
542
|
-
users: singlestoreTable(
|
|
543
|
-
'users',
|
|
544
|
-
{
|
|
545
|
-
id: serial('id').primaryKey(),
|
|
546
|
-
name: text('name'),
|
|
547
|
-
email: text('email'),
|
|
548
|
-
},
|
|
549
|
-
(t) => ({
|
|
550
|
-
uniqueExpr: uniqueIndex('uniqueExpr').on(sql`(lower(${t.email}))`),
|
|
551
|
-
indexExpr: index('indexExpr').on(sql`(lower(${t.email}))`),
|
|
552
|
-
indexExprMultiple: index('indexExprMultiple').on(
|
|
553
|
-
sql`(lower(${t.email}))`,
|
|
554
|
-
sql`(lower(${t.email}))`,
|
|
555
|
-
),
|
|
556
|
-
|
|
557
|
-
uniqueCol: uniqueIndex('uniqueCol').on(t.email),
|
|
558
|
-
indexCol: index('indexCol').on(t.email),
|
|
559
|
-
indexColMultiple: index('indexColMultiple').on(t.email, t.email),
|
|
560
|
-
|
|
561
|
-
indexColExpr: index('indexColExpr').on(
|
|
562
|
-
sql`(lower(${t.email}))`,
|
|
563
|
-
t.email,
|
|
564
|
-
),
|
|
565
|
-
}),
|
|
566
|
-
),
|
|
567
|
-
};
|
|
568
|
-
|
|
569
|
-
const { sqlStatements } = await diffTestSchemasSingleStore(from, to, []);
|
|
570
|
-
expect(sqlStatements.length).toBe(6);
|
|
571
|
-
expect(sqlStatements).toStrictEqual([
|
|
572
|
-
`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\`)
|
|
573
|
-
);
|
|
574
|
-
`,
|
|
575
|
-
'CREATE INDEX `indexExpr` ON `users` ((lower(`email`)));',
|
|
576
|
-
'CREATE INDEX `indexExprMultiple` ON `users` ((lower(`email`)),(lower(`email`)));',
|
|
577
|
-
'CREATE INDEX `indexCol` ON `users` (`email`);',
|
|
578
|
-
'CREATE INDEX `indexColMultiple` ON `users` (`email`,`email`);',
|
|
579
|
-
'CREATE INDEX `indexColExpr` ON `users` ((lower(`email`)),`email`);',
|
|
580
|
-
]);
|
|
581
|
-
});
|
|
582
|
-
|
|
583
|
-
test('rename table', async () => {
|
|
584
|
-
const from = {
|
|
585
|
-
table: singlestoreTable('table', {
|
|
586
|
-
json: json('json').default([]),
|
|
587
|
-
}),
|
|
588
|
-
};
|
|
589
|
-
|
|
590
|
-
const to = {
|
|
591
|
-
table1: singlestoreTable('table1', {
|
|
592
|
-
json1: json('json').default([]),
|
|
593
|
-
}),
|
|
594
|
-
};
|
|
595
|
-
|
|
596
|
-
const { sqlStatements } = await diffTestSchemasSingleStore(from, to, [`public.table->public.table1`]);
|
|
597
|
-
expect(sqlStatements.length).toBe(1);
|
|
598
|
-
expect(sqlStatements[0]).toBe(
|
|
599
|
-
'ALTER TABLE `table` RENAME TO `table1`;',
|
|
600
|
-
);
|
|
601
|
-
});
|
|
602
|
-
|
|
603
|
-
test('rename column', async () => {
|
|
604
|
-
const from = {
|
|
605
|
-
users: singlestoreTable('table', {
|
|
606
|
-
json: json('json').default([]),
|
|
607
|
-
}),
|
|
608
|
-
};
|
|
609
|
-
|
|
610
|
-
const to = {
|
|
611
|
-
users: singlestoreTable('table', {
|
|
612
|
-
json1: json('json1').default([]),
|
|
613
|
-
}),
|
|
614
|
-
};
|
|
615
|
-
|
|
616
|
-
const { sqlStatements } = await diffTestSchemasSingleStore(from, to, [`public.table.json->public.table.json1`]);
|
|
617
|
-
expect(sqlStatements.length).toBe(1);
|
|
618
|
-
expect(sqlStatements[0]).toBe(
|
|
619
|
-
'ALTER TABLE `table` CHANGE `json` `json1`;',
|
|
620
|
-
);
|
|
621
|
-
});
|
|
622
|
-
|
|
623
|
-
test('change data type', async () => {
|
|
624
|
-
const from = {
|
|
625
|
-
table: singlestoreTable('table', {
|
|
626
|
-
id: int(),
|
|
627
|
-
age: text(),
|
|
628
|
-
}),
|
|
629
|
-
};
|
|
630
|
-
|
|
631
|
-
const to = {
|
|
632
|
-
table: singlestoreTable('table', {
|
|
633
|
-
id: int(),
|
|
634
|
-
age: int(),
|
|
635
|
-
}),
|
|
636
|
-
};
|
|
637
|
-
|
|
638
|
-
const { sqlStatements } = await diffTestSchemasSingleStore(from, to, []);
|
|
639
|
-
expect(sqlStatements.length).toBe(4);
|
|
640
|
-
expect(sqlStatements[0]).toBe(
|
|
641
|
-
`CREATE TABLE \`__new_table\` (
|
|
642
|
-
\t\`id\` int,
|
|
643
|
-
\t\`age\` int
|
|
644
|
-
);\n`,
|
|
645
|
-
);
|
|
646
|
-
expect(sqlStatements[1]).toBe(
|
|
647
|
-
'INSERT INTO `__new_table`(`id`, `age`) SELECT `id`, `age` FROM `table`;',
|
|
648
|
-
);
|
|
649
|
-
expect(sqlStatements[2]).toBe(
|
|
650
|
-
'DROP TABLE `table`;',
|
|
651
|
-
);
|
|
652
|
-
expect(sqlStatements[3]).toBe(
|
|
653
|
-
'ALTER TABLE `__new_table` RENAME TO `table`;',
|
|
654
|
-
);
|
|
655
|
-
});
|
|
656
|
-
|
|
657
|
-
test('drop not null', async () => {
|
|
658
|
-
const from = {
|
|
659
|
-
table: singlestoreTable('table', {
|
|
660
|
-
id: int().notNull(),
|
|
661
|
-
age: int(),
|
|
662
|
-
}),
|
|
663
|
-
};
|
|
664
|
-
|
|
665
|
-
const to = {
|
|
666
|
-
table: singlestoreTable('table', {
|
|
667
|
-
id: int(),
|
|
668
|
-
age: int(),
|
|
669
|
-
}),
|
|
670
|
-
};
|
|
671
|
-
|
|
672
|
-
const { sqlStatements } = await diffTestSchemasSingleStore(from, to, []);
|
|
673
|
-
expect(sqlStatements.length).toBe(4);
|
|
674
|
-
expect(sqlStatements[0]).toBe(
|
|
675
|
-
`CREATE TABLE \`__new_table\` (
|
|
676
|
-
\t\`id\` int,
|
|
677
|
-
\t\`age\` int
|
|
678
|
-
);\n`,
|
|
679
|
-
);
|
|
680
|
-
expect(sqlStatements[1]).toBe(
|
|
681
|
-
'INSERT INTO `__new_table`(`id`, `age`) SELECT `id`, `age` FROM `table`;',
|
|
682
|
-
);
|
|
683
|
-
expect(sqlStatements[2]).toBe(
|
|
684
|
-
'DROP TABLE `table`;',
|
|
685
|
-
);
|
|
686
|
-
expect(sqlStatements[3]).toBe(
|
|
687
|
-
'ALTER TABLE `__new_table` RENAME TO `table`;',
|
|
688
|
-
);
|
|
689
|
-
});
|
|
690
|
-
|
|
691
|
-
test('set not null', async () => {
|
|
692
|
-
const from = {
|
|
693
|
-
table: singlestoreTable('table', {
|
|
694
|
-
id: int(),
|
|
695
|
-
age: int(),
|
|
696
|
-
}),
|
|
697
|
-
};
|
|
698
|
-
|
|
699
|
-
const to = {
|
|
700
|
-
table: singlestoreTable('table', {
|
|
701
|
-
id: int().notNull(),
|
|
702
|
-
age: int(),
|
|
703
|
-
}),
|
|
704
|
-
};
|
|
705
|
-
|
|
706
|
-
const { sqlStatements } = await diffTestSchemasSingleStore(from, to, []);
|
|
707
|
-
expect(sqlStatements.length).toBe(4);
|
|
708
|
-
expect(sqlStatements[0]).toBe(
|
|
709
|
-
`CREATE TABLE \`__new_table\` (
|
|
710
|
-
\t\`id\` int NOT NULL,
|
|
711
|
-
\t\`age\` int
|
|
712
|
-
);\n`,
|
|
713
|
-
);
|
|
714
|
-
expect(sqlStatements[1]).toBe(
|
|
715
|
-
'INSERT INTO `__new_table`(`id`, `age`) SELECT `id`, `age` FROM `table`;',
|
|
716
|
-
);
|
|
717
|
-
expect(sqlStatements[2]).toBe(
|
|
718
|
-
'DROP TABLE `table`;',
|
|
719
|
-
);
|
|
720
|
-
expect(sqlStatements[3]).toBe(
|
|
721
|
-
'ALTER TABLE `__new_table` RENAME TO `table`;',
|
|
722
|
-
);
|
|
723
|
-
});
|
|
724
|
-
|
|
725
|
-
test('set default with not null column', async () => {
|
|
726
|
-
const from = {
|
|
727
|
-
table: singlestoreTable('table', {
|
|
728
|
-
id: int().notNull(),
|
|
729
|
-
age: int(),
|
|
730
|
-
}),
|
|
731
|
-
};
|
|
732
|
-
|
|
733
|
-
const to = {
|
|
734
|
-
table: singlestoreTable('table', {
|
|
735
|
-
id: int().notNull().default(1),
|
|
736
|
-
age: int(),
|
|
737
|
-
}),
|
|
738
|
-
};
|
|
739
|
-
|
|
740
|
-
const { sqlStatements } = await diffTestSchemasSingleStore(from, to, []);
|
|
741
|
-
expect(sqlStatements.length).toBe(4);
|
|
742
|
-
expect(sqlStatements[0]).toBe(
|
|
743
|
-
`CREATE TABLE \`__new_table\` (
|
|
744
|
-
\t\`id\` int NOT NULL DEFAULT 1,
|
|
745
|
-
\t\`age\` int
|
|
746
|
-
);\n`,
|
|
747
|
-
);
|
|
748
|
-
expect(sqlStatements[1]).toBe(
|
|
749
|
-
'INSERT INTO `__new_table`(`id`, `age`) SELECT `id`, `age` FROM `table`;',
|
|
750
|
-
);
|
|
751
|
-
expect(sqlStatements[2]).toBe(
|
|
752
|
-
'DROP TABLE `table`;',
|
|
753
|
-
);
|
|
754
|
-
expect(sqlStatements[3]).toBe(
|
|
755
|
-
'ALTER TABLE `__new_table` RENAME TO `table`;',
|
|
756
|
-
);
|
|
757
|
-
});
|
|
758
|
-
|
|
759
|
-
test('drop default with not null column', async () => {
|
|
760
|
-
const from = {
|
|
761
|
-
table: singlestoreTable('table', {
|
|
762
|
-
id: int().notNull().default(1),
|
|
763
|
-
age: int(),
|
|
764
|
-
}),
|
|
765
|
-
};
|
|
766
|
-
|
|
767
|
-
const to = {
|
|
768
|
-
table: singlestoreTable('table', {
|
|
769
|
-
id: int().notNull(),
|
|
770
|
-
age: int(),
|
|
771
|
-
}),
|
|
772
|
-
};
|
|
773
|
-
|
|
774
|
-
const { sqlStatements } = await diffTestSchemasSingleStore(from, to, []);
|
|
775
|
-
expect(sqlStatements.length).toBe(4);
|
|
776
|
-
expect(sqlStatements[0]).toBe(
|
|
777
|
-
`CREATE TABLE \`__new_table\` (
|
|
778
|
-
\t\`id\` int NOT NULL,
|
|
779
|
-
\t\`age\` int
|
|
780
|
-
);\n`,
|
|
781
|
-
);
|
|
782
|
-
expect(sqlStatements[1]).toBe(
|
|
783
|
-
'INSERT INTO `__new_table`(`id`, `age`) SELECT `id`, `age` FROM `table`;',
|
|
784
|
-
);
|
|
785
|
-
expect(sqlStatements[2]).toBe(
|
|
786
|
-
'DROP TABLE `table`;',
|
|
787
|
-
);
|
|
788
|
-
expect(sqlStatements[3]).toBe(
|
|
789
|
-
'ALTER TABLE `__new_table` RENAME TO `table`;',
|
|
790
|
-
);
|
|
791
|
-
});
|
|
792
|
-
|
|
793
|
-
test('set default', async () => {
|
|
794
|
-
const from = {
|
|
795
|
-
table: singlestoreTable('table', {
|
|
796
|
-
id: int(),
|
|
797
|
-
age: int(),
|
|
798
|
-
}),
|
|
799
|
-
};
|
|
800
|
-
|
|
801
|
-
const to = {
|
|
802
|
-
table: singlestoreTable('table', {
|
|
803
|
-
id: int().default(1),
|
|
804
|
-
age: int(),
|
|
805
|
-
}),
|
|
806
|
-
};
|
|
807
|
-
|
|
808
|
-
const { sqlStatements } = await diffTestSchemasSingleStore(from, to, []);
|
|
809
|
-
expect(sqlStatements.length).toBe(1);
|
|
810
|
-
expect(sqlStatements[0]).toBe(
|
|
811
|
-
'ALTER TABLE `table` MODIFY COLUMN `id` int DEFAULT 1;',
|
|
812
|
-
);
|
|
813
|
-
});
|
|
814
|
-
|
|
815
|
-
test('drop default', async () => {
|
|
816
|
-
const from = {
|
|
817
|
-
table: singlestoreTable('table', {
|
|
818
|
-
id: int().default(1),
|
|
819
|
-
age: int(),
|
|
820
|
-
}),
|
|
821
|
-
};
|
|
822
|
-
|
|
823
|
-
const to = {
|
|
824
|
-
table: singlestoreTable('table', {
|
|
825
|
-
id: int(),
|
|
826
|
-
age: int(),
|
|
827
|
-
}),
|
|
828
|
-
};
|
|
829
|
-
|
|
830
|
-
const { sqlStatements } = await diffTestSchemasSingleStore(from, to, []);
|
|
831
|
-
expect(sqlStatements.length).toBe(1);
|
|
832
|
-
expect(sqlStatements[0]).toBe(
|
|
833
|
-
'ALTER TABLE `table` MODIFY COLUMN `id` int;',
|
|
834
|
-
);
|
|
835
|
-
});
|
|
836
|
-
|
|
837
|
-
test('set pk', async () => {
|
|
838
|
-
const from = {
|
|
839
|
-
table: singlestoreTable('table', {
|
|
840
|
-
id: int(),
|
|
841
|
-
age: int(),
|
|
842
|
-
}),
|
|
843
|
-
};
|
|
844
|
-
|
|
845
|
-
const to = {
|
|
846
|
-
table: singlestoreTable('table', {
|
|
847
|
-
id: int().primaryKey(),
|
|
848
|
-
age: int(),
|
|
849
|
-
}),
|
|
850
|
-
};
|
|
851
|
-
|
|
852
|
-
const { sqlStatements } = await diffTestSchemasSingleStore(from, to, []);
|
|
853
|
-
expect(sqlStatements.length).toBe(4);
|
|
854
|
-
expect(sqlStatements[0]).toBe(
|
|
855
|
-
`CREATE TABLE \`__new_table\` (
|
|
856
|
-
\t\`id\` int NOT NULL,
|
|
857
|
-
\t\`age\` int,
|
|
858
|
-
\tCONSTRAINT \`table_id\` PRIMARY KEY(\`id\`)
|
|
859
|
-
);\n`,
|
|
860
|
-
);
|
|
861
|
-
expect(sqlStatements[1]).toBe(
|
|
862
|
-
'INSERT INTO `__new_table`(`id`, `age`) SELECT `id`, `age` FROM `table`;',
|
|
863
|
-
);
|
|
864
|
-
expect(sqlStatements[2]).toBe(
|
|
865
|
-
'DROP TABLE `table`;',
|
|
866
|
-
);
|
|
867
|
-
expect(sqlStatements[3]).toBe(
|
|
868
|
-
'ALTER TABLE `__new_table` RENAME TO `table`;',
|
|
869
|
-
);
|
|
870
|
-
});
|
|
871
|
-
|
|
872
|
-
test('drop pk', async () => {
|
|
873
|
-
const from = {
|
|
874
|
-
table: singlestoreTable('table', {
|
|
875
|
-
id: int().primaryKey(),
|
|
876
|
-
age: int(),
|
|
877
|
-
}),
|
|
878
|
-
};
|
|
879
|
-
|
|
880
|
-
const to = {
|
|
881
|
-
table: singlestoreTable('table', {
|
|
882
|
-
id: int(),
|
|
883
|
-
age: int(),
|
|
884
|
-
}),
|
|
885
|
-
};
|
|
886
|
-
|
|
887
|
-
const { sqlStatements } = await diffTestSchemasSingleStore(from, to, []);
|
|
888
|
-
expect(sqlStatements.length).toBe(4);
|
|
889
|
-
expect(sqlStatements[0]).toBe(
|
|
890
|
-
`CREATE TABLE \`__new_table\` (
|
|
891
|
-
\t\`id\` int,
|
|
892
|
-
\t\`age\` int
|
|
893
|
-
);\n`,
|
|
894
|
-
);
|
|
895
|
-
expect(sqlStatements[1]).toBe(
|
|
896
|
-
'INSERT INTO `__new_table`(`id`, `age`) SELECT `id`, `age` FROM `table`;',
|
|
897
|
-
);
|
|
898
|
-
expect(sqlStatements[2]).toBe(
|
|
899
|
-
'DROP TABLE `table`;',
|
|
900
|
-
);
|
|
901
|
-
expect(sqlStatements[3]).toBe(
|
|
902
|
-
'ALTER TABLE `__new_table` RENAME TO `table`;',
|
|
903
|
-
);
|
|
904
|
-
});
|
|
905
|
-
|
|
906
|
-
test('set not null + rename column on table with indexes', async () => {
|
|
907
|
-
const from = {
|
|
908
|
-
table: singlestoreTable('table', {
|
|
909
|
-
id: int('id').default(1),
|
|
910
|
-
age: int(),
|
|
911
|
-
}),
|
|
912
|
-
};
|
|
913
|
-
|
|
914
|
-
const to = {
|
|
915
|
-
table: singlestoreTable('table', {
|
|
916
|
-
id3: int('id3').notNull().default(1),
|
|
917
|
-
age: int(),
|
|
918
|
-
}),
|
|
919
|
-
};
|
|
920
|
-
|
|
921
|
-
const { sqlStatements } = await diffTestSchemasSingleStore(from, to, [`public.table.id->public.table.id3`]);
|
|
922
|
-
expect(sqlStatements.length).toBe(5);
|
|
923
|
-
expect(sqlStatements[0]).toBe(
|
|
924
|
-
'ALTER TABLE \`table\` CHANGE `id` `id3`;',
|
|
925
|
-
);
|
|
926
|
-
expect(sqlStatements[1]).toBe(
|
|
927
|
-
`CREATE TABLE \`__new_table\` (
|
|
928
|
-
\t\`id3\` int NOT NULL DEFAULT 1,
|
|
929
|
-
\t\`age\` int
|
|
930
|
-
);\n`,
|
|
931
|
-
);
|
|
932
|
-
expect(sqlStatements[2]).toBe(
|
|
933
|
-
'INSERT INTO `__new_table`(`id3`, `age`) SELECT `id3`, `age` FROM `table`;',
|
|
934
|
-
);
|
|
935
|
-
expect(sqlStatements[3]).toBe(
|
|
936
|
-
'DROP TABLE `table`;',
|
|
937
|
-
);
|
|
938
|
-
expect(sqlStatements[4]).toBe(
|
|
939
|
-
'ALTER TABLE `__new_table` RENAME TO `table`;',
|
|
940
|
-
);
|
|
941
|
-
});
|
|
942
|
-
|
|
943
|
-
test('set not null + rename table on table with indexes', async () => {
|
|
944
|
-
const from = {
|
|
945
|
-
table: singlestoreTable('table', {
|
|
946
|
-
id: int('id').default(1),
|
|
947
|
-
age: int(),
|
|
948
|
-
}),
|
|
949
|
-
};
|
|
950
|
-
|
|
951
|
-
const to = {
|
|
952
|
-
table1: singlestoreTable('table1', {
|
|
953
|
-
id: int('id').notNull().default(1),
|
|
954
|
-
age: int(),
|
|
955
|
-
}),
|
|
956
|
-
};
|
|
957
|
-
|
|
958
|
-
const { sqlStatements } = await diffTestSchemasSingleStore(from, to, [`public.table->public.table1`]);
|
|
959
|
-
expect(sqlStatements.length).toBe(5);
|
|
960
|
-
expect(sqlStatements[0]).toBe(
|
|
961
|
-
'ALTER TABLE `table` RENAME TO `table1`;',
|
|
962
|
-
);
|
|
963
|
-
expect(sqlStatements[1]).toBe(
|
|
964
|
-
`CREATE TABLE \`__new_table1\` (
|
|
965
|
-
\t\`id\` int NOT NULL DEFAULT 1,
|
|
966
|
-
\t\`age\` int
|
|
967
|
-
);\n`,
|
|
968
|
-
);
|
|
969
|
-
expect(sqlStatements[2]).toBe(
|
|
970
|
-
'INSERT INTO `__new_table1`(\`id\`, \`age\`) SELECT \`id\`, \`age\` FROM `table1`;',
|
|
971
|
-
);
|
|
972
|
-
expect(sqlStatements[3]).toBe(
|
|
973
|
-
'DROP TABLE `table1`;',
|
|
974
|
-
);
|
|
975
|
-
expect(sqlStatements[4]).toBe(
|
|
976
|
-
'ALTER TABLE `__new_table1` RENAME TO `table1`;',
|
|
977
|
-
);
|
|
978
|
-
});
|