@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
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
import { is } from 'drizzle-orm';
|
|
2
|
-
import { AnySQLiteTable, SQLiteTable, SQLiteView } from 'drizzle-orm/sqlite-core';
|
|
3
|
-
import { safeRegister } from '../cli/commands/utils';
|
|
4
|
-
|
|
5
|
-
export const prepareFromExports = (exports: Record<string, unknown>) => {
|
|
6
|
-
const tables: AnySQLiteTable[] = [];
|
|
7
|
-
const views: SQLiteView[] = [];
|
|
8
|
-
|
|
9
|
-
const i0values = Object.values(exports);
|
|
10
|
-
i0values.forEach((t) => {
|
|
11
|
-
if (is(t, SQLiteTable)) {
|
|
12
|
-
tables.push(t);
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
if (is(t, SQLiteView)) {
|
|
16
|
-
views.push(t);
|
|
17
|
-
}
|
|
18
|
-
});
|
|
19
|
-
|
|
20
|
-
return { tables, views };
|
|
21
|
-
};
|
|
22
|
-
|
|
23
|
-
export const prepareFromSqliteImports = async (imports: string[]) => {
|
|
24
|
-
const tables: AnySQLiteTable[] = [];
|
|
25
|
-
const views: SQLiteView[] = [];
|
|
26
|
-
|
|
27
|
-
const { unregister } = await safeRegister();
|
|
28
|
-
for (let i = 0; i < imports.length; i++) {
|
|
29
|
-
const it = imports[i];
|
|
30
|
-
|
|
31
|
-
const i0: Record<string, unknown> = require(`${it}`);
|
|
32
|
-
const prepared = prepareFromExports(i0);
|
|
33
|
-
|
|
34
|
-
tables.push(...prepared.tables);
|
|
35
|
-
views.push(...prepared.views);
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
unregister();
|
|
39
|
-
|
|
40
|
-
return { tables: Array.from(new Set(tables)), views };
|
|
41
|
-
};
|
|
@@ -1,352 +0,0 @@
|
|
|
1
|
-
import { any, boolean, enum as enumType, literal, object, record, string, TypeOf, union } from 'zod';
|
|
2
|
-
import { customMapEntries, mapValues, originUUID } from '../global';
|
|
3
|
-
|
|
4
|
-
// ------- V3 --------
|
|
5
|
-
const index = object({
|
|
6
|
-
name: string(),
|
|
7
|
-
columns: string().array(),
|
|
8
|
-
where: string().optional(),
|
|
9
|
-
isUnique: boolean(),
|
|
10
|
-
}).strict();
|
|
11
|
-
|
|
12
|
-
const fk = object({
|
|
13
|
-
name: string(),
|
|
14
|
-
tableFrom: string(),
|
|
15
|
-
columnsFrom: string().array(),
|
|
16
|
-
tableTo: string(),
|
|
17
|
-
columnsTo: string().array(),
|
|
18
|
-
onUpdate: string().optional(),
|
|
19
|
-
onDelete: string().optional(),
|
|
20
|
-
}).strict();
|
|
21
|
-
|
|
22
|
-
const compositePK = object({
|
|
23
|
-
columns: string().array(),
|
|
24
|
-
name: string().optional(),
|
|
25
|
-
}).strict();
|
|
26
|
-
|
|
27
|
-
const column = object({
|
|
28
|
-
name: string(),
|
|
29
|
-
type: string(),
|
|
30
|
-
primaryKey: boolean(),
|
|
31
|
-
notNull: boolean(),
|
|
32
|
-
autoincrement: boolean().optional(),
|
|
33
|
-
default: any().optional(),
|
|
34
|
-
generated: object({
|
|
35
|
-
type: enumType(['stored', 'virtual']),
|
|
36
|
-
as: string(),
|
|
37
|
-
}).optional(),
|
|
38
|
-
}).strict();
|
|
39
|
-
|
|
40
|
-
const tableV3 = object({
|
|
41
|
-
name: string(),
|
|
42
|
-
columns: record(string(), column),
|
|
43
|
-
indexes: record(string(), index),
|
|
44
|
-
foreignKeys: record(string(), fk),
|
|
45
|
-
}).strict();
|
|
46
|
-
|
|
47
|
-
const uniqueConstraint = object({
|
|
48
|
-
name: string(),
|
|
49
|
-
columns: string().array(),
|
|
50
|
-
}).strict();
|
|
51
|
-
|
|
52
|
-
const checkConstraint = object({
|
|
53
|
-
name: string(),
|
|
54
|
-
value: string(),
|
|
55
|
-
}).strict();
|
|
56
|
-
|
|
57
|
-
const table = object({
|
|
58
|
-
name: string(),
|
|
59
|
-
columns: record(string(), column),
|
|
60
|
-
indexes: record(string(), index),
|
|
61
|
-
foreignKeys: record(string(), fk),
|
|
62
|
-
compositePrimaryKeys: record(string(), compositePK),
|
|
63
|
-
uniqueConstraints: record(string(), uniqueConstraint).default({}),
|
|
64
|
-
checkConstraints: record(string(), checkConstraint).default({}),
|
|
65
|
-
}).strict();
|
|
66
|
-
|
|
67
|
-
export const view = object({
|
|
68
|
-
name: string(),
|
|
69
|
-
columns: record(string(), column),
|
|
70
|
-
definition: string().optional(),
|
|
71
|
-
isExisting: boolean(),
|
|
72
|
-
}).strict();
|
|
73
|
-
|
|
74
|
-
// use main dialect
|
|
75
|
-
const dialect = enumType(['sqlite']);
|
|
76
|
-
|
|
77
|
-
const schemaHash = object({
|
|
78
|
-
id: string(),
|
|
79
|
-
prevId: string(),
|
|
80
|
-
}).strict();
|
|
81
|
-
|
|
82
|
-
export const schemaInternalV3 = object({
|
|
83
|
-
version: literal('3'),
|
|
84
|
-
dialect: dialect,
|
|
85
|
-
tables: record(string(), tableV3),
|
|
86
|
-
enums: object({}),
|
|
87
|
-
}).strict();
|
|
88
|
-
|
|
89
|
-
export const schemaInternalV4 = object({
|
|
90
|
-
version: literal('4'),
|
|
91
|
-
dialect: dialect,
|
|
92
|
-
tables: record(string(), table),
|
|
93
|
-
views: record(string(), view).default({}),
|
|
94
|
-
enums: object({}),
|
|
95
|
-
}).strict();
|
|
96
|
-
|
|
97
|
-
export const schemaInternalV5 = object({
|
|
98
|
-
version: literal('5'),
|
|
99
|
-
dialect: dialect,
|
|
100
|
-
tables: record(string(), table),
|
|
101
|
-
enums: object({}),
|
|
102
|
-
_meta: object({
|
|
103
|
-
tables: record(string(), string()),
|
|
104
|
-
columns: record(string(), string()),
|
|
105
|
-
}),
|
|
106
|
-
}).strict();
|
|
107
|
-
|
|
108
|
-
export const kitInternals = object({
|
|
109
|
-
indexes: record(
|
|
110
|
-
string(),
|
|
111
|
-
object({
|
|
112
|
-
columns: record(
|
|
113
|
-
string(),
|
|
114
|
-
object({ isExpression: boolean().optional() }).optional(),
|
|
115
|
-
),
|
|
116
|
-
}).optional(),
|
|
117
|
-
).optional(),
|
|
118
|
-
}).optional();
|
|
119
|
-
|
|
120
|
-
const latestVersion = literal('6');
|
|
121
|
-
export const schemaInternal = object({
|
|
122
|
-
version: latestVersion,
|
|
123
|
-
dialect: dialect,
|
|
124
|
-
tables: record(string(), table),
|
|
125
|
-
views: record(string(), view).default({}),
|
|
126
|
-
enums: object({}),
|
|
127
|
-
_meta: object({
|
|
128
|
-
tables: record(string(), string()),
|
|
129
|
-
columns: record(string(), string()),
|
|
130
|
-
}),
|
|
131
|
-
internal: kitInternals,
|
|
132
|
-
}).strict();
|
|
133
|
-
|
|
134
|
-
export const schemaV3 = schemaInternalV3.merge(schemaHash).strict();
|
|
135
|
-
export const schemaV4 = schemaInternalV4.merge(schemaHash).strict();
|
|
136
|
-
export const schemaV5 = schemaInternalV5.merge(schemaHash).strict();
|
|
137
|
-
export const schema = schemaInternal.merge(schemaHash).strict();
|
|
138
|
-
|
|
139
|
-
const tableSquashed = object({
|
|
140
|
-
name: string(),
|
|
141
|
-
columns: record(string(), column),
|
|
142
|
-
indexes: record(string(), string()),
|
|
143
|
-
foreignKeys: record(string(), string()),
|
|
144
|
-
compositePrimaryKeys: record(string(), string()),
|
|
145
|
-
uniqueConstraints: record(string(), string()).default({}),
|
|
146
|
-
checkConstraints: record(string(), string()).default({}),
|
|
147
|
-
}).strict();
|
|
148
|
-
|
|
149
|
-
export const schemaSquashed = object({
|
|
150
|
-
version: latestVersion,
|
|
151
|
-
dialect: dialect,
|
|
152
|
-
tables: record(string(), tableSquashed),
|
|
153
|
-
views: record(string(), view),
|
|
154
|
-
enums: any(),
|
|
155
|
-
}).strict();
|
|
156
|
-
|
|
157
|
-
export type Dialect = TypeOf<typeof dialect>;
|
|
158
|
-
export type Column = TypeOf<typeof column>;
|
|
159
|
-
export type Table = TypeOf<typeof table>;
|
|
160
|
-
export type SQLiteSchema = TypeOf<typeof schema>;
|
|
161
|
-
export type SQLiteSchemaV3 = TypeOf<typeof schemaV3>;
|
|
162
|
-
export type SQLiteSchemaV4 = TypeOf<typeof schemaV4>;
|
|
163
|
-
export type SQLiteSchemaInternal = TypeOf<typeof schemaInternal>;
|
|
164
|
-
export type SQLiteSchemaSquashed = TypeOf<typeof schemaSquashed>;
|
|
165
|
-
export type SQLiteKitInternals = TypeOf<typeof kitInternals>;
|
|
166
|
-
export type Index = TypeOf<typeof index>;
|
|
167
|
-
export type ForeignKey = TypeOf<typeof fk>;
|
|
168
|
-
export type PrimaryKey = TypeOf<typeof compositePK>;
|
|
169
|
-
export type UniqueConstraint = TypeOf<typeof uniqueConstraint>;
|
|
170
|
-
export type CheckConstraint = TypeOf<typeof checkConstraint>;
|
|
171
|
-
export type View = TypeOf<typeof view>;
|
|
172
|
-
|
|
173
|
-
export const SQLiteSquasher = {
|
|
174
|
-
squashIdx: (idx: Index) => {
|
|
175
|
-
index.parse(idx);
|
|
176
|
-
return `${idx.name};${idx.columns.join(',')};${idx.isUnique};${idx.where ?? ''}`;
|
|
177
|
-
},
|
|
178
|
-
unsquashIdx: (input: string): Index => {
|
|
179
|
-
const [name, columnsString, isUnique, where] = input.split(';');
|
|
180
|
-
|
|
181
|
-
const result: Index = index.parse({
|
|
182
|
-
name,
|
|
183
|
-
columns: columnsString.split(','),
|
|
184
|
-
isUnique: isUnique === 'true',
|
|
185
|
-
where: where ?? undefined,
|
|
186
|
-
});
|
|
187
|
-
return result;
|
|
188
|
-
},
|
|
189
|
-
squashUnique: (unq: UniqueConstraint) => {
|
|
190
|
-
return `${unq.name};${unq.columns.join(',')}`;
|
|
191
|
-
},
|
|
192
|
-
unsquashUnique: (unq: string): UniqueConstraint => {
|
|
193
|
-
const [name, columns] = unq.split(';');
|
|
194
|
-
return { name, columns: columns.split(',') };
|
|
195
|
-
},
|
|
196
|
-
squashFK: (fk: ForeignKey) => {
|
|
197
|
-
return `${fk.name};${fk.tableFrom};${fk.columnsFrom.join(',')};${fk.tableTo};${fk.columnsTo.join(',')};${
|
|
198
|
-
fk.onUpdate ?? ''
|
|
199
|
-
};${fk.onDelete ?? ''}`;
|
|
200
|
-
},
|
|
201
|
-
unsquashFK: (input: string): ForeignKey => {
|
|
202
|
-
const [
|
|
203
|
-
name,
|
|
204
|
-
tableFrom,
|
|
205
|
-
columnsFromStr,
|
|
206
|
-
tableTo,
|
|
207
|
-
columnsToStr,
|
|
208
|
-
onUpdate,
|
|
209
|
-
onDelete,
|
|
210
|
-
] = input.split(';');
|
|
211
|
-
|
|
212
|
-
const result: ForeignKey = fk.parse({
|
|
213
|
-
name,
|
|
214
|
-
tableFrom,
|
|
215
|
-
columnsFrom: columnsFromStr.split(','),
|
|
216
|
-
tableTo,
|
|
217
|
-
columnsTo: columnsToStr.split(','),
|
|
218
|
-
onUpdate,
|
|
219
|
-
onDelete,
|
|
220
|
-
});
|
|
221
|
-
return result;
|
|
222
|
-
},
|
|
223
|
-
squashPushFK: (fk: ForeignKey) => {
|
|
224
|
-
return `${fk.tableFrom};${fk.columnsFrom.join(',')};${fk.tableTo};${fk.columnsTo.join(',')};${fk.onUpdate ?? ''};${
|
|
225
|
-
fk.onDelete ?? ''
|
|
226
|
-
}`;
|
|
227
|
-
},
|
|
228
|
-
unsquashPushFK: (input: string): ForeignKey => {
|
|
229
|
-
const [
|
|
230
|
-
tableFrom,
|
|
231
|
-
columnsFromStr,
|
|
232
|
-
tableTo,
|
|
233
|
-
columnsToStr,
|
|
234
|
-
onUpdate,
|
|
235
|
-
onDelete,
|
|
236
|
-
] = input.split(';');
|
|
237
|
-
|
|
238
|
-
const result: ForeignKey = fk.parse({
|
|
239
|
-
name: '',
|
|
240
|
-
tableFrom,
|
|
241
|
-
columnsFrom: columnsFromStr.split(','),
|
|
242
|
-
tableTo,
|
|
243
|
-
columnsTo: columnsToStr.split(','),
|
|
244
|
-
onUpdate,
|
|
245
|
-
onDelete,
|
|
246
|
-
});
|
|
247
|
-
return result;
|
|
248
|
-
},
|
|
249
|
-
squashPK: (pk: PrimaryKey) => {
|
|
250
|
-
return pk.columns.join(',');
|
|
251
|
-
},
|
|
252
|
-
unsquashPK: (pk: string) => {
|
|
253
|
-
return pk.split(',');
|
|
254
|
-
},
|
|
255
|
-
squashCheck: (check: CheckConstraint) => {
|
|
256
|
-
return `${check.name};${check.value}`;
|
|
257
|
-
},
|
|
258
|
-
unsquashCheck: (input: string): CheckConstraint => {
|
|
259
|
-
const [
|
|
260
|
-
name,
|
|
261
|
-
value,
|
|
262
|
-
] = input.split(';');
|
|
263
|
-
|
|
264
|
-
return { name, value };
|
|
265
|
-
},
|
|
266
|
-
};
|
|
267
|
-
|
|
268
|
-
export const squashSqliteScheme = (
|
|
269
|
-
json: SQLiteSchema | SQLiteSchemaV4,
|
|
270
|
-
action?: 'push' | undefined,
|
|
271
|
-
): SQLiteSchemaSquashed => {
|
|
272
|
-
const mappedTables = Object.fromEntries(
|
|
273
|
-
Object.entries(json.tables).map((it) => {
|
|
274
|
-
const squashedIndexes = mapValues(it[1].indexes, (index: Index) => {
|
|
275
|
-
return SQLiteSquasher.squashIdx(index);
|
|
276
|
-
});
|
|
277
|
-
|
|
278
|
-
const squashedFKs = customMapEntries<string, ForeignKey>(
|
|
279
|
-
it[1].foreignKeys,
|
|
280
|
-
(key, value) => {
|
|
281
|
-
return action === 'push'
|
|
282
|
-
? [
|
|
283
|
-
SQLiteSquasher.squashPushFK(value),
|
|
284
|
-
SQLiteSquasher.squashPushFK(value),
|
|
285
|
-
]
|
|
286
|
-
: [key, SQLiteSquasher.squashFK(value)];
|
|
287
|
-
},
|
|
288
|
-
);
|
|
289
|
-
|
|
290
|
-
const squashedPKs = mapValues(it[1].compositePrimaryKeys, (pk) => {
|
|
291
|
-
return SQLiteSquasher.squashPK(pk);
|
|
292
|
-
});
|
|
293
|
-
|
|
294
|
-
const squashedUniqueConstraints = mapValues(
|
|
295
|
-
it[1].uniqueConstraints,
|
|
296
|
-
(unq) => {
|
|
297
|
-
return SQLiteSquasher.squashUnique(unq);
|
|
298
|
-
},
|
|
299
|
-
);
|
|
300
|
-
|
|
301
|
-
const squashedCheckConstraints = mapValues(
|
|
302
|
-
it[1].checkConstraints,
|
|
303
|
-
(check) => {
|
|
304
|
-
return SQLiteSquasher.squashCheck(check);
|
|
305
|
-
},
|
|
306
|
-
);
|
|
307
|
-
|
|
308
|
-
return [
|
|
309
|
-
it[0],
|
|
310
|
-
{
|
|
311
|
-
name: it[1].name,
|
|
312
|
-
columns: it[1].columns,
|
|
313
|
-
indexes: squashedIndexes,
|
|
314
|
-
foreignKeys: squashedFKs,
|
|
315
|
-
compositePrimaryKeys: squashedPKs,
|
|
316
|
-
uniqueConstraints: squashedUniqueConstraints,
|
|
317
|
-
checkConstraints: squashedCheckConstraints,
|
|
318
|
-
},
|
|
319
|
-
];
|
|
320
|
-
}),
|
|
321
|
-
);
|
|
322
|
-
|
|
323
|
-
return {
|
|
324
|
-
version: '6',
|
|
325
|
-
dialect: json.dialect,
|
|
326
|
-
tables: mappedTables,
|
|
327
|
-
views: json.views,
|
|
328
|
-
enums: json.enums,
|
|
329
|
-
};
|
|
330
|
-
};
|
|
331
|
-
|
|
332
|
-
export const drySQLite = schema.parse({
|
|
333
|
-
version: '6',
|
|
334
|
-
dialect: 'sqlite',
|
|
335
|
-
id: originUUID,
|
|
336
|
-
prevId: '',
|
|
337
|
-
tables: {},
|
|
338
|
-
views: {},
|
|
339
|
-
enums: {},
|
|
340
|
-
_meta: {
|
|
341
|
-
tables: {},
|
|
342
|
-
columns: {},
|
|
343
|
-
},
|
|
344
|
-
});
|
|
345
|
-
|
|
346
|
-
export const sqliteSchemaV3 = schemaV3;
|
|
347
|
-
export const sqliteSchemaV4 = schemaV4;
|
|
348
|
-
export const sqliteSchemaV5 = schemaV5;
|
|
349
|
-
export const sqliteSchema = schema;
|
|
350
|
-
export const SQLiteSchemaSquashed = schemaSquashed;
|
|
351
|
-
|
|
352
|
-
export const backwardCompatibleSqliteSchema = union([sqliteSchemaV5, schema]);
|