@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,637 +0,0 @@
|
|
|
1
|
-
import { sql } from 'drizzle-orm';
|
|
2
|
-
import {
|
|
3
|
-
AnySQLiteColumn,
|
|
4
|
-
foreignKey,
|
|
5
|
-
index,
|
|
6
|
-
int,
|
|
7
|
-
primaryKey,
|
|
8
|
-
sqliteTable,
|
|
9
|
-
text,
|
|
10
|
-
unique,
|
|
11
|
-
uniqueIndex,
|
|
12
|
-
} from 'drizzle-orm/sqlite-core';
|
|
13
|
-
import { expect, test } from 'vitest';
|
|
14
|
-
import { diffTestSchemasSqlite } from './schemaDiffer';
|
|
15
|
-
|
|
16
|
-
test('add table #1', async () => {
|
|
17
|
-
const to = {
|
|
18
|
-
users: sqliteTable('users', {}),
|
|
19
|
-
};
|
|
20
|
-
|
|
21
|
-
const { statements } = await diffTestSchemasSqlite({}, to, []);
|
|
22
|
-
|
|
23
|
-
expect(statements.length).toBe(1);
|
|
24
|
-
expect(statements[0]).toStrictEqual({
|
|
25
|
-
type: 'sqlite_create_table',
|
|
26
|
-
tableName: 'users',
|
|
27
|
-
columns: [],
|
|
28
|
-
compositePKs: [],
|
|
29
|
-
uniqueConstraints: [],
|
|
30
|
-
referenceData: [],
|
|
31
|
-
checkConstraints: [],
|
|
32
|
-
});
|
|
33
|
-
});
|
|
34
|
-
|
|
35
|
-
test('add table #2', async () => {
|
|
36
|
-
const to = {
|
|
37
|
-
users: sqliteTable('users', {
|
|
38
|
-
id: int('id').primaryKey({ autoIncrement: true }),
|
|
39
|
-
}),
|
|
40
|
-
};
|
|
41
|
-
|
|
42
|
-
const { statements } = await diffTestSchemasSqlite({}, to, []);
|
|
43
|
-
|
|
44
|
-
expect(statements.length).toBe(1);
|
|
45
|
-
expect(statements[0]).toStrictEqual({
|
|
46
|
-
type: 'sqlite_create_table',
|
|
47
|
-
tableName: 'users',
|
|
48
|
-
columns: [
|
|
49
|
-
{
|
|
50
|
-
name: 'id',
|
|
51
|
-
notNull: true,
|
|
52
|
-
primaryKey: true,
|
|
53
|
-
type: 'integer',
|
|
54
|
-
autoincrement: true,
|
|
55
|
-
},
|
|
56
|
-
],
|
|
57
|
-
compositePKs: [],
|
|
58
|
-
referenceData: [],
|
|
59
|
-
uniqueConstraints: [],
|
|
60
|
-
checkConstraints: [],
|
|
61
|
-
});
|
|
62
|
-
});
|
|
63
|
-
|
|
64
|
-
test('add table #3', async () => {
|
|
65
|
-
const to = {
|
|
66
|
-
users: sqliteTable(
|
|
67
|
-
'users',
|
|
68
|
-
{
|
|
69
|
-
id: int('id'),
|
|
70
|
-
},
|
|
71
|
-
(t) => {
|
|
72
|
-
return {
|
|
73
|
-
pk: primaryKey({
|
|
74
|
-
name: 'users_pk',
|
|
75
|
-
columns: [t.id],
|
|
76
|
-
}),
|
|
77
|
-
};
|
|
78
|
-
},
|
|
79
|
-
),
|
|
80
|
-
};
|
|
81
|
-
|
|
82
|
-
const { statements } = await diffTestSchemasSqlite({}, to, []);
|
|
83
|
-
|
|
84
|
-
expect(statements.length).toBe(1);
|
|
85
|
-
expect(statements[0]).toStrictEqual({
|
|
86
|
-
type: 'sqlite_create_table',
|
|
87
|
-
tableName: 'users',
|
|
88
|
-
columns: [
|
|
89
|
-
{
|
|
90
|
-
name: 'id',
|
|
91
|
-
notNull: false,
|
|
92
|
-
primaryKey: true,
|
|
93
|
-
type: 'integer',
|
|
94
|
-
autoincrement: false,
|
|
95
|
-
},
|
|
96
|
-
],
|
|
97
|
-
compositePKs: [],
|
|
98
|
-
uniqueConstraints: [],
|
|
99
|
-
referenceData: [],
|
|
100
|
-
checkConstraints: [],
|
|
101
|
-
});
|
|
102
|
-
});
|
|
103
|
-
|
|
104
|
-
test('add table #4', async () => {
|
|
105
|
-
const to = {
|
|
106
|
-
users: sqliteTable('users', {}),
|
|
107
|
-
posts: sqliteTable('posts', {}),
|
|
108
|
-
};
|
|
109
|
-
|
|
110
|
-
const { statements } = await diffTestSchemasSqlite({}, to, []);
|
|
111
|
-
|
|
112
|
-
expect(statements.length).toBe(2);
|
|
113
|
-
expect(statements[0]).toStrictEqual({
|
|
114
|
-
type: 'sqlite_create_table',
|
|
115
|
-
tableName: 'users',
|
|
116
|
-
columns: [],
|
|
117
|
-
compositePKs: [],
|
|
118
|
-
uniqueConstraints: [],
|
|
119
|
-
referenceData: [],
|
|
120
|
-
checkConstraints: [],
|
|
121
|
-
});
|
|
122
|
-
expect(statements[1]).toStrictEqual({
|
|
123
|
-
type: 'sqlite_create_table',
|
|
124
|
-
tableName: 'posts',
|
|
125
|
-
columns: [],
|
|
126
|
-
compositePKs: [],
|
|
127
|
-
uniqueConstraints: [],
|
|
128
|
-
referenceData: [],
|
|
129
|
-
checkConstraints: [],
|
|
130
|
-
});
|
|
131
|
-
});
|
|
132
|
-
|
|
133
|
-
test('add table #5', async () => {
|
|
134
|
-
// no schemas in sqlite
|
|
135
|
-
});
|
|
136
|
-
|
|
137
|
-
test('add table #6', async () => {
|
|
138
|
-
const from = {
|
|
139
|
-
users1: sqliteTable('users1', {}),
|
|
140
|
-
};
|
|
141
|
-
|
|
142
|
-
const to = {
|
|
143
|
-
users2: sqliteTable('users2', {}),
|
|
144
|
-
};
|
|
145
|
-
|
|
146
|
-
const { statements } = await diffTestSchemasSqlite(from, to, []);
|
|
147
|
-
|
|
148
|
-
expect(statements.length).toBe(2);
|
|
149
|
-
expect(statements[0]).toStrictEqual({
|
|
150
|
-
type: 'sqlite_create_table',
|
|
151
|
-
tableName: 'users2',
|
|
152
|
-
columns: [],
|
|
153
|
-
compositePKs: [],
|
|
154
|
-
uniqueConstraints: [],
|
|
155
|
-
referenceData: [],
|
|
156
|
-
checkConstraints: [],
|
|
157
|
-
});
|
|
158
|
-
expect(statements[1]).toStrictEqual({
|
|
159
|
-
type: 'drop_table',
|
|
160
|
-
tableName: 'users1',
|
|
161
|
-
schema: undefined,
|
|
162
|
-
policies: [],
|
|
163
|
-
});
|
|
164
|
-
});
|
|
165
|
-
|
|
166
|
-
test('add table #7', async () => {
|
|
167
|
-
const from = {
|
|
168
|
-
users1: sqliteTable('users1', {}),
|
|
169
|
-
};
|
|
170
|
-
|
|
171
|
-
const to = {
|
|
172
|
-
users: sqliteTable('users', {}),
|
|
173
|
-
users2: sqliteTable('users2', {}),
|
|
174
|
-
};
|
|
175
|
-
|
|
176
|
-
const { statements } = await diffTestSchemasSqlite(from, to, [
|
|
177
|
-
'public.users1->public.users2',
|
|
178
|
-
]);
|
|
179
|
-
|
|
180
|
-
expect(statements.length).toBe(2);
|
|
181
|
-
expect(statements[0]).toStrictEqual({
|
|
182
|
-
type: 'rename_table',
|
|
183
|
-
tableNameFrom: 'users1',
|
|
184
|
-
tableNameTo: 'users2',
|
|
185
|
-
fromSchema: undefined,
|
|
186
|
-
toSchema: undefined,
|
|
187
|
-
});
|
|
188
|
-
expect(statements[1]).toStrictEqual({
|
|
189
|
-
type: 'sqlite_create_table',
|
|
190
|
-
tableName: 'users',
|
|
191
|
-
columns: [],
|
|
192
|
-
compositePKs: [],
|
|
193
|
-
uniqueConstraints: [],
|
|
194
|
-
referenceData: [],
|
|
195
|
-
checkConstraints: [],
|
|
196
|
-
});
|
|
197
|
-
});
|
|
198
|
-
|
|
199
|
-
test('add table #8', async () => {
|
|
200
|
-
const users = sqliteTable('users', {
|
|
201
|
-
id: int('id').primaryKey({ autoIncrement: true }),
|
|
202
|
-
reporteeId: int('reportee_id').references((): AnySQLiteColumn => users.id),
|
|
203
|
-
});
|
|
204
|
-
|
|
205
|
-
const to = {
|
|
206
|
-
users,
|
|
207
|
-
};
|
|
208
|
-
|
|
209
|
-
const { statements } = await diffTestSchemasSqlite({}, to, []);
|
|
210
|
-
|
|
211
|
-
expect(statements.length).toBe(1);
|
|
212
|
-
expect(statements[0]).toStrictEqual({
|
|
213
|
-
type: 'sqlite_create_table',
|
|
214
|
-
tableName: 'users',
|
|
215
|
-
columns: [
|
|
216
|
-
{
|
|
217
|
-
autoincrement: true,
|
|
218
|
-
name: 'id',
|
|
219
|
-
notNull: true,
|
|
220
|
-
primaryKey: true,
|
|
221
|
-
type: 'integer',
|
|
222
|
-
},
|
|
223
|
-
{
|
|
224
|
-
autoincrement: false,
|
|
225
|
-
name: 'reportee_id',
|
|
226
|
-
notNull: false,
|
|
227
|
-
primaryKey: false,
|
|
228
|
-
type: 'integer',
|
|
229
|
-
},
|
|
230
|
-
],
|
|
231
|
-
compositePKs: [],
|
|
232
|
-
uniqueConstraints: [],
|
|
233
|
-
checkConstraints: [],
|
|
234
|
-
referenceData: [
|
|
235
|
-
{
|
|
236
|
-
columnsFrom: ['reportee_id'],
|
|
237
|
-
columnsTo: ['id'],
|
|
238
|
-
name: 'users_reportee_id_users_id_fk',
|
|
239
|
-
onDelete: 'no action',
|
|
240
|
-
onUpdate: 'no action',
|
|
241
|
-
tableFrom: 'users',
|
|
242
|
-
tableTo: 'users',
|
|
243
|
-
},
|
|
244
|
-
],
|
|
245
|
-
});
|
|
246
|
-
});
|
|
247
|
-
|
|
248
|
-
test('add table #9', async () => {
|
|
249
|
-
const to = {
|
|
250
|
-
users: sqliteTable(
|
|
251
|
-
'users',
|
|
252
|
-
{
|
|
253
|
-
id: int('id').primaryKey({ autoIncrement: true }),
|
|
254
|
-
reporteeId: int('reportee_id'),
|
|
255
|
-
},
|
|
256
|
-
(t) => {
|
|
257
|
-
return {
|
|
258
|
-
reporteeIdx: index('reportee_idx').on(t.reporteeId),
|
|
259
|
-
};
|
|
260
|
-
},
|
|
261
|
-
),
|
|
262
|
-
};
|
|
263
|
-
|
|
264
|
-
const { statements } = await diffTestSchemasSqlite({}, to, []);
|
|
265
|
-
|
|
266
|
-
expect(statements.length).toBe(2);
|
|
267
|
-
expect(statements[0]).toStrictEqual({
|
|
268
|
-
type: 'sqlite_create_table',
|
|
269
|
-
tableName: 'users',
|
|
270
|
-
columns: [
|
|
271
|
-
{
|
|
272
|
-
autoincrement: true,
|
|
273
|
-
name: 'id',
|
|
274
|
-
notNull: true,
|
|
275
|
-
primaryKey: true,
|
|
276
|
-
type: 'integer',
|
|
277
|
-
},
|
|
278
|
-
{
|
|
279
|
-
autoincrement: false,
|
|
280
|
-
name: 'reportee_id',
|
|
281
|
-
notNull: false,
|
|
282
|
-
primaryKey: false,
|
|
283
|
-
type: 'integer',
|
|
284
|
-
},
|
|
285
|
-
],
|
|
286
|
-
compositePKs: [],
|
|
287
|
-
uniqueConstraints: [],
|
|
288
|
-
referenceData: [],
|
|
289
|
-
checkConstraints: [],
|
|
290
|
-
});
|
|
291
|
-
|
|
292
|
-
expect(statements[1]).toStrictEqual({
|
|
293
|
-
type: 'create_index',
|
|
294
|
-
tableName: 'users',
|
|
295
|
-
internal: {
|
|
296
|
-
indexes: {},
|
|
297
|
-
},
|
|
298
|
-
schema: undefined,
|
|
299
|
-
data: 'reportee_idx;reportee_id;false;',
|
|
300
|
-
});
|
|
301
|
-
});
|
|
302
|
-
|
|
303
|
-
test('add table #10', async () => {
|
|
304
|
-
const to = {
|
|
305
|
-
users: sqliteTable('table', {
|
|
306
|
-
json: text('json', { mode: 'json' }).default({}),
|
|
307
|
-
}),
|
|
308
|
-
};
|
|
309
|
-
|
|
310
|
-
const { sqlStatements } = await diffTestSchemasSqlite({}, to, []);
|
|
311
|
-
expect(sqlStatements.length).toBe(1);
|
|
312
|
-
expect(sqlStatements[0]).toBe(
|
|
313
|
-
"CREATE TABLE `table` (\n\t`json` text DEFAULT '{}'\n);\n",
|
|
314
|
-
);
|
|
315
|
-
});
|
|
316
|
-
|
|
317
|
-
test('add table #11', async () => {
|
|
318
|
-
const to = {
|
|
319
|
-
users: sqliteTable('table', {
|
|
320
|
-
json: text('json', { mode: 'json' }).default([]),
|
|
321
|
-
}),
|
|
322
|
-
};
|
|
323
|
-
|
|
324
|
-
const { sqlStatements } = await diffTestSchemasSqlite({}, to, []);
|
|
325
|
-
expect(sqlStatements.length).toBe(1);
|
|
326
|
-
expect(sqlStatements[0]).toBe(
|
|
327
|
-
"CREATE TABLE `table` (\n\t`json` text DEFAULT '[]'\n);\n",
|
|
328
|
-
);
|
|
329
|
-
});
|
|
330
|
-
|
|
331
|
-
test('add table #12', async () => {
|
|
332
|
-
const to = {
|
|
333
|
-
users: sqliteTable('table', {
|
|
334
|
-
json: text('json', { mode: 'json' }).default([1, 2, 3]),
|
|
335
|
-
}),
|
|
336
|
-
};
|
|
337
|
-
|
|
338
|
-
const { sqlStatements } = await diffTestSchemasSqlite({}, to, []);
|
|
339
|
-
expect(sqlStatements.length).toBe(1);
|
|
340
|
-
expect(sqlStatements[0]).toBe(
|
|
341
|
-
"CREATE TABLE `table` (\n\t`json` text DEFAULT '[1,2,3]'\n);\n",
|
|
342
|
-
);
|
|
343
|
-
});
|
|
344
|
-
|
|
345
|
-
test('add table #13', async () => {
|
|
346
|
-
const to = {
|
|
347
|
-
users: sqliteTable('table', {
|
|
348
|
-
json: text('json', { mode: 'json' }).default({ key: 'value' }),
|
|
349
|
-
}),
|
|
350
|
-
};
|
|
351
|
-
|
|
352
|
-
const { sqlStatements } = await diffTestSchemasSqlite({}, to, []);
|
|
353
|
-
expect(sqlStatements.length).toBe(1);
|
|
354
|
-
expect(sqlStatements[0]).toBe(
|
|
355
|
-
'CREATE TABLE `table` (\n\t`json` text DEFAULT \'{"key":"value"}\'\n);\n',
|
|
356
|
-
);
|
|
357
|
-
});
|
|
358
|
-
|
|
359
|
-
test('add table #14', async () => {
|
|
360
|
-
const to = {
|
|
361
|
-
users: sqliteTable('table', {
|
|
362
|
-
json: text('json', { mode: 'json' }).default({
|
|
363
|
-
key: 'value',
|
|
364
|
-
arr: [1, 2, 3],
|
|
365
|
-
}),
|
|
366
|
-
}),
|
|
367
|
-
};
|
|
368
|
-
|
|
369
|
-
const { sqlStatements } = await diffTestSchemasSqlite({}, to, []);
|
|
370
|
-
expect(sqlStatements.length).toBe(1);
|
|
371
|
-
expect(sqlStatements[0]).toBe(
|
|
372
|
-
'CREATE TABLE `table` (\n\t`json` text DEFAULT \'{"key":"value","arr":[1,2,3]}\'\n);\n',
|
|
373
|
-
);
|
|
374
|
-
});
|
|
375
|
-
|
|
376
|
-
test('add table with indexes', async () => {
|
|
377
|
-
const from = {};
|
|
378
|
-
|
|
379
|
-
const to = {
|
|
380
|
-
users: sqliteTable(
|
|
381
|
-
'users',
|
|
382
|
-
{
|
|
383
|
-
id: int('id').primaryKey(),
|
|
384
|
-
name: text('name'),
|
|
385
|
-
email: text('email'),
|
|
386
|
-
},
|
|
387
|
-
(t) => ({
|
|
388
|
-
uniqueExpr: uniqueIndex('uniqueExpr').on(sql`(lower(${t.email}))`),
|
|
389
|
-
indexExpr: index('indexExpr').on(sql`(lower(${t.email}))`),
|
|
390
|
-
indexExprMultiple: index('indexExprMultiple').on(
|
|
391
|
-
sql`(lower(${t.email}))`,
|
|
392
|
-
sql`(lower(${t.email}))`,
|
|
393
|
-
),
|
|
394
|
-
|
|
395
|
-
uniqueCol: uniqueIndex('uniqueCol').on(t.email),
|
|
396
|
-
indexCol: index('indexCol').on(t.email),
|
|
397
|
-
indexColMultiple: index('indexColMultiple').on(t.email, t.email),
|
|
398
|
-
|
|
399
|
-
indexColExpr: index('indexColExpr').on(
|
|
400
|
-
sql`(lower(${t.email}))`,
|
|
401
|
-
t.email,
|
|
402
|
-
),
|
|
403
|
-
}),
|
|
404
|
-
),
|
|
405
|
-
};
|
|
406
|
-
|
|
407
|
-
const { sqlStatements } = await diffTestSchemasSqlite(from, to, []);
|
|
408
|
-
expect(sqlStatements.length).toBe(8);
|
|
409
|
-
expect(sqlStatements).toStrictEqual([
|
|
410
|
-
'CREATE TABLE `users` (\n\t`id` integer PRIMARY KEY NOT NULL,\n\t`name` text,\n\t`email` text\n);\n',
|
|
411
|
-
'CREATE UNIQUE INDEX `uniqueExpr` ON `users` ((lower("email")));',
|
|
412
|
-
'CREATE INDEX `indexExpr` ON `users` ((lower("email")));',
|
|
413
|
-
'CREATE INDEX `indexExprMultiple` ON `users` ((lower("email")),(lower("email")));',
|
|
414
|
-
'CREATE UNIQUE INDEX `uniqueCol` ON `users` (`email`);',
|
|
415
|
-
'CREATE INDEX `indexCol` ON `users` (`email`);',
|
|
416
|
-
'CREATE INDEX `indexColMultiple` ON `users` (`email`,`email`);',
|
|
417
|
-
'CREATE INDEX `indexColExpr` ON `users` ((lower("email")),`email`);',
|
|
418
|
-
]);
|
|
419
|
-
});
|
|
420
|
-
|
|
421
|
-
test('composite primary key', async () => {
|
|
422
|
-
const from = {};
|
|
423
|
-
const to = {
|
|
424
|
-
table: sqliteTable('works_to_creators', {
|
|
425
|
-
workId: int('work_id').notNull(),
|
|
426
|
-
creatorId: int('creator_id').notNull(),
|
|
427
|
-
classification: text('classification').notNull(),
|
|
428
|
-
}, (t) => ({
|
|
429
|
-
pk: primaryKey({
|
|
430
|
-
columns: [t.workId, t.creatorId, t.classification],
|
|
431
|
-
}),
|
|
432
|
-
})),
|
|
433
|
-
};
|
|
434
|
-
|
|
435
|
-
const { sqlStatements } = await diffTestSchemasSqlite(from, to, []);
|
|
436
|
-
|
|
437
|
-
expect(sqlStatements).toStrictEqual([
|
|
438
|
-
'CREATE TABLE `works_to_creators` (\n\t`work_id` integer NOT NULL,\n\t`creator_id` integer NOT NULL,\n\t`classification` text NOT NULL,\n\tPRIMARY KEY(`work_id`, `creator_id`, `classification`)\n);\n',
|
|
439
|
-
]);
|
|
440
|
-
});
|
|
441
|
-
|
|
442
|
-
test('add column before creating unique constraint', async () => {
|
|
443
|
-
const from = {
|
|
444
|
-
table: sqliteTable('table', {
|
|
445
|
-
id: int('id').primaryKey(),
|
|
446
|
-
}),
|
|
447
|
-
};
|
|
448
|
-
const to = {
|
|
449
|
-
table: sqliteTable('table', {
|
|
450
|
-
id: int('id').primaryKey(),
|
|
451
|
-
name: text('name').notNull(),
|
|
452
|
-
}, (t) => ({
|
|
453
|
-
uq: unique('uq').on(t.name),
|
|
454
|
-
})),
|
|
455
|
-
};
|
|
456
|
-
|
|
457
|
-
const { sqlStatements } = await diffTestSchemasSqlite(from, to, []);
|
|
458
|
-
|
|
459
|
-
expect(sqlStatements).toStrictEqual([
|
|
460
|
-
'ALTER TABLE `table` ADD `name` text NOT NULL;',
|
|
461
|
-
'CREATE UNIQUE INDEX `uq` ON `table` (`name`);',
|
|
462
|
-
]);
|
|
463
|
-
});
|
|
464
|
-
|
|
465
|
-
test('optional db aliases (snake case)', async () => {
|
|
466
|
-
const from = {};
|
|
467
|
-
|
|
468
|
-
const t1 = sqliteTable(
|
|
469
|
-
't1',
|
|
470
|
-
{
|
|
471
|
-
t1Id1: int().notNull().primaryKey(),
|
|
472
|
-
t1Col2: int().notNull(),
|
|
473
|
-
t1Col3: int().notNull(),
|
|
474
|
-
t2Ref: int().notNull().references(() => t2.t2Id),
|
|
475
|
-
t1Uni: int().notNull(),
|
|
476
|
-
t1UniIdx: int().notNull(),
|
|
477
|
-
t1Idx: int().notNull(),
|
|
478
|
-
},
|
|
479
|
-
(table) => ({
|
|
480
|
-
uni: unique('t1_uni').on(table.t1Uni),
|
|
481
|
-
uniIdx: uniqueIndex('t1_uni_idx').on(table.t1UniIdx),
|
|
482
|
-
idx: index('t1_idx').on(table.t1Idx),
|
|
483
|
-
fk: foreignKey({
|
|
484
|
-
columns: [table.t1Col2, table.t1Col3],
|
|
485
|
-
foreignColumns: [t3.t3Id1, t3.t3Id2],
|
|
486
|
-
}),
|
|
487
|
-
}),
|
|
488
|
-
);
|
|
489
|
-
|
|
490
|
-
const t2 = sqliteTable(
|
|
491
|
-
't2',
|
|
492
|
-
{
|
|
493
|
-
t2Id: int().primaryKey({ autoIncrement: true }),
|
|
494
|
-
},
|
|
495
|
-
);
|
|
496
|
-
|
|
497
|
-
const t3 = sqliteTable(
|
|
498
|
-
't3',
|
|
499
|
-
{
|
|
500
|
-
t3Id1: int(),
|
|
501
|
-
t3Id2: int(),
|
|
502
|
-
},
|
|
503
|
-
(table) => ({
|
|
504
|
-
pk: primaryKey({
|
|
505
|
-
columns: [table.t3Id1, table.t3Id2],
|
|
506
|
-
}),
|
|
507
|
-
}),
|
|
508
|
-
);
|
|
509
|
-
|
|
510
|
-
const to = {
|
|
511
|
-
t1,
|
|
512
|
-
t2,
|
|
513
|
-
t3,
|
|
514
|
-
};
|
|
515
|
-
|
|
516
|
-
const { sqlStatements } = await diffTestSchemasSqlite(from, to, [], false, 'snake_case');
|
|
517
|
-
|
|
518
|
-
const st1 = `CREATE TABLE \`t1\` (
|
|
519
|
-
\`t1_id1\` integer PRIMARY KEY NOT NULL,
|
|
520
|
-
\`t1_col2\` integer NOT NULL,
|
|
521
|
-
\`t1_col3\` integer NOT NULL,
|
|
522
|
-
\`t2_ref\` integer NOT NULL,
|
|
523
|
-
\`t1_uni\` integer NOT NULL,
|
|
524
|
-
\`t1_uni_idx\` integer NOT NULL,
|
|
525
|
-
\`t1_idx\` integer NOT NULL,
|
|
526
|
-
FOREIGN KEY (\`t2_ref\`) REFERENCES \`t2\`(\`t2_id\`) ON UPDATE no action ON DELETE no action,
|
|
527
|
-
FOREIGN KEY (\`t1_col2\`,\`t1_col3\`) REFERENCES \`t3\`(\`t3_id1\`,\`t3_id2\`) ON UPDATE no action ON DELETE no action
|
|
528
|
-
);
|
|
529
|
-
`;
|
|
530
|
-
|
|
531
|
-
const st2 = `CREATE UNIQUE INDEX \`t1_uni_idx\` ON \`t1\` (\`t1_uni_idx\`);`;
|
|
532
|
-
|
|
533
|
-
const st3 = `CREATE INDEX \`t1_idx\` ON \`t1\` (\`t1_idx\`);`;
|
|
534
|
-
|
|
535
|
-
const st4 = `CREATE UNIQUE INDEX \`t1_uni\` ON \`t1\` (\`t1_uni\`);`;
|
|
536
|
-
|
|
537
|
-
const st5 = `CREATE TABLE \`t2\` (
|
|
538
|
-
\`t2_id\` integer PRIMARY KEY AUTOINCREMENT NOT NULL
|
|
539
|
-
);
|
|
540
|
-
`;
|
|
541
|
-
|
|
542
|
-
const st6 = `CREATE TABLE \`t3\` (
|
|
543
|
-
\`t3_id1\` integer,
|
|
544
|
-
\`t3_id2\` integer,
|
|
545
|
-
PRIMARY KEY(\`t3_id1\`, \`t3_id2\`)
|
|
546
|
-
);
|
|
547
|
-
`;
|
|
548
|
-
|
|
549
|
-
expect(sqlStatements).toStrictEqual([st1, st2, st3, st4, st5, st6]);
|
|
550
|
-
});
|
|
551
|
-
|
|
552
|
-
test('optional db aliases (camel case)', async () => {
|
|
553
|
-
const from = {};
|
|
554
|
-
|
|
555
|
-
const t1 = sqliteTable(
|
|
556
|
-
't1',
|
|
557
|
-
{
|
|
558
|
-
t1_id1: int().notNull().primaryKey(),
|
|
559
|
-
t1_col2: int().notNull(),
|
|
560
|
-
t1_col3: int().notNull(),
|
|
561
|
-
t2_ref: int().notNull().references(() => t2.t2_id),
|
|
562
|
-
t1_uni: int().notNull(),
|
|
563
|
-
t1_uni_idx: int().notNull(),
|
|
564
|
-
t1_idx: int().notNull(),
|
|
565
|
-
},
|
|
566
|
-
(table) => ({
|
|
567
|
-
uni: unique('t1Uni').on(table.t1_uni),
|
|
568
|
-
uni_idx: uniqueIndex('t1UniIdx').on(table.t1_uni_idx),
|
|
569
|
-
idx: index('t1Idx').on(table.t1_idx),
|
|
570
|
-
fk: foreignKey({
|
|
571
|
-
columns: [table.t1_col2, table.t1_col3],
|
|
572
|
-
foreignColumns: [t3.t3_id1, t3.t3_id2],
|
|
573
|
-
}),
|
|
574
|
-
}),
|
|
575
|
-
);
|
|
576
|
-
|
|
577
|
-
const t2 = sqliteTable(
|
|
578
|
-
't2',
|
|
579
|
-
{
|
|
580
|
-
t2_id: int().primaryKey({ autoIncrement: true }),
|
|
581
|
-
},
|
|
582
|
-
);
|
|
583
|
-
|
|
584
|
-
const t3 = sqliteTable(
|
|
585
|
-
't3',
|
|
586
|
-
{
|
|
587
|
-
t3_id1: int(),
|
|
588
|
-
t3_id2: int(),
|
|
589
|
-
},
|
|
590
|
-
(table) => ({
|
|
591
|
-
pk: primaryKey({
|
|
592
|
-
columns: [table.t3_id1, table.t3_id2],
|
|
593
|
-
}),
|
|
594
|
-
}),
|
|
595
|
-
);
|
|
596
|
-
|
|
597
|
-
const to = {
|
|
598
|
-
t1,
|
|
599
|
-
t2,
|
|
600
|
-
t3,
|
|
601
|
-
};
|
|
602
|
-
|
|
603
|
-
const { sqlStatements } = await diffTestSchemasSqlite(from, to, [], false, 'camelCase');
|
|
604
|
-
|
|
605
|
-
const st1 = `CREATE TABLE \`t1\` (
|
|
606
|
-
\`t1Id1\` integer PRIMARY KEY NOT NULL,
|
|
607
|
-
\`t1Col2\` integer NOT NULL,
|
|
608
|
-
\`t1Col3\` integer NOT NULL,
|
|
609
|
-
\`t2Ref\` integer NOT NULL,
|
|
610
|
-
\`t1Uni\` integer NOT NULL,
|
|
611
|
-
\`t1UniIdx\` integer NOT NULL,
|
|
612
|
-
\`t1Idx\` integer NOT NULL,
|
|
613
|
-
FOREIGN KEY (\`t2Ref\`) REFERENCES \`t2\`(\`t2Id\`) ON UPDATE no action ON DELETE no action,
|
|
614
|
-
FOREIGN KEY (\`t1Col2\`,\`t1Col3\`) REFERENCES \`t3\`(\`t3Id1\`,\`t3Id2\`) ON UPDATE no action ON DELETE no action
|
|
615
|
-
);
|
|
616
|
-
`;
|
|
617
|
-
|
|
618
|
-
const st2 = `CREATE UNIQUE INDEX \`t1UniIdx\` ON \`t1\` (\`t1UniIdx\`);`;
|
|
619
|
-
|
|
620
|
-
const st3 = `CREATE INDEX \`t1Idx\` ON \`t1\` (\`t1Idx\`);`;
|
|
621
|
-
|
|
622
|
-
const st4 = `CREATE UNIQUE INDEX \`t1Uni\` ON \`t1\` (\`t1Uni\`);`;
|
|
623
|
-
|
|
624
|
-
const st5 = `CREATE TABLE \`t2\` (
|
|
625
|
-
\`t2Id\` integer PRIMARY KEY AUTOINCREMENT NOT NULL
|
|
626
|
-
);
|
|
627
|
-
`;
|
|
628
|
-
|
|
629
|
-
const st6 = `CREATE TABLE \`t3\` (
|
|
630
|
-
\`t3Id1\` integer,
|
|
631
|
-
\`t3Id2\` integer,
|
|
632
|
-
PRIMARY KEY(\`t3Id1\`, \`t3Id2\`)
|
|
633
|
-
);
|
|
634
|
-
`;
|
|
635
|
-
|
|
636
|
-
expect(sqlStatements).toStrictEqual([st1, st2, st3, st4, st5, st6]);
|
|
637
|
-
});
|