@anthonyalayo/drizzle-kit 1.0.1 → 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 +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,423 +0,0 @@
|
|
|
1
|
-
import { any, boolean, enum as enumType, literal, object, record, string, TypeOf, union } from 'zod';
|
|
2
|
-
import { mapValues, originUUID } from '../global';
|
|
3
|
-
|
|
4
|
-
// ------- V3 --------
|
|
5
|
-
const index = object({
|
|
6
|
-
name: string(),
|
|
7
|
-
columns: string().array(),
|
|
8
|
-
isUnique: boolean(),
|
|
9
|
-
using: enumType(['btree', 'hash']).optional(),
|
|
10
|
-
algorithm: enumType(['default', 'inplace', 'copy']).optional(),
|
|
11
|
-
lock: enumType(['default', 'none', 'shared', 'exclusive']).optional(),
|
|
12
|
-
}).strict();
|
|
13
|
-
|
|
14
|
-
const fk = object({
|
|
15
|
-
name: string(),
|
|
16
|
-
tableFrom: string(),
|
|
17
|
-
columnsFrom: string().array(),
|
|
18
|
-
tableTo: string(),
|
|
19
|
-
columnsTo: string().array(),
|
|
20
|
-
onUpdate: string().optional(),
|
|
21
|
-
onDelete: string().optional(),
|
|
22
|
-
}).strict();
|
|
23
|
-
|
|
24
|
-
const column = object({
|
|
25
|
-
name: string(),
|
|
26
|
-
type: string(),
|
|
27
|
-
primaryKey: boolean(),
|
|
28
|
-
notNull: boolean(),
|
|
29
|
-
autoincrement: boolean().optional(),
|
|
30
|
-
default: any().optional(),
|
|
31
|
-
onUpdate: any().optional(),
|
|
32
|
-
generated: object({
|
|
33
|
-
type: enumType(['stored', 'virtual']),
|
|
34
|
-
as: string(),
|
|
35
|
-
}).optional(),
|
|
36
|
-
}).strict();
|
|
37
|
-
|
|
38
|
-
const tableV3 = object({
|
|
39
|
-
name: string(),
|
|
40
|
-
columns: record(string(), column),
|
|
41
|
-
indexes: record(string(), index),
|
|
42
|
-
foreignKeys: record(string(), fk),
|
|
43
|
-
}).strict();
|
|
44
|
-
|
|
45
|
-
const compositePK = object({
|
|
46
|
-
name: string(),
|
|
47
|
-
columns: string().array(),
|
|
48
|
-
}).strict();
|
|
49
|
-
|
|
50
|
-
const uniqueConstraint = object({
|
|
51
|
-
name: string(),
|
|
52
|
-
columns: string().array(),
|
|
53
|
-
}).strict();
|
|
54
|
-
|
|
55
|
-
const checkConstraint = object({
|
|
56
|
-
name: string(),
|
|
57
|
-
value: string(),
|
|
58
|
-
}).strict();
|
|
59
|
-
|
|
60
|
-
const tableV4 = object({
|
|
61
|
-
name: string(),
|
|
62
|
-
schema: string().optional(),
|
|
63
|
-
columns: record(string(), column),
|
|
64
|
-
indexes: record(string(), index),
|
|
65
|
-
foreignKeys: record(string(), fk),
|
|
66
|
-
}).strict();
|
|
67
|
-
|
|
68
|
-
const table = object({
|
|
69
|
-
name: string(),
|
|
70
|
-
columns: record(string(), column),
|
|
71
|
-
indexes: record(string(), index),
|
|
72
|
-
foreignKeys: record(string(), fk),
|
|
73
|
-
compositePrimaryKeys: record(string(), compositePK),
|
|
74
|
-
uniqueConstraints: record(string(), uniqueConstraint).default({}),
|
|
75
|
-
checkConstraint: record(string(), checkConstraint).default({}),
|
|
76
|
-
}).strict();
|
|
77
|
-
|
|
78
|
-
const viewMeta = object({
|
|
79
|
-
algorithm: enumType(['undefined', 'merge', 'temptable']),
|
|
80
|
-
sqlSecurity: enumType(['definer', 'invoker']),
|
|
81
|
-
withCheckOption: enumType(['local', 'cascaded']).optional(),
|
|
82
|
-
}).strict();
|
|
83
|
-
|
|
84
|
-
export const view = object({
|
|
85
|
-
name: string(),
|
|
86
|
-
columns: record(string(), column),
|
|
87
|
-
definition: string().optional(),
|
|
88
|
-
isExisting: boolean(),
|
|
89
|
-
}).strict().merge(viewMeta);
|
|
90
|
-
type SquasherViewMeta = Omit<TypeOf<typeof viewMeta>, 'definer'>;
|
|
91
|
-
|
|
92
|
-
export const kitInternals = object({
|
|
93
|
-
tables: record(
|
|
94
|
-
string(),
|
|
95
|
-
object({
|
|
96
|
-
columns: record(
|
|
97
|
-
string(),
|
|
98
|
-
object({ isDefaultAnExpression: boolean().optional() }).optional(),
|
|
99
|
-
),
|
|
100
|
-
}).optional(),
|
|
101
|
-
).optional(),
|
|
102
|
-
indexes: record(
|
|
103
|
-
string(),
|
|
104
|
-
object({
|
|
105
|
-
columns: record(
|
|
106
|
-
string(),
|
|
107
|
-
object({ isExpression: boolean().optional() }).optional(),
|
|
108
|
-
),
|
|
109
|
-
}).optional(),
|
|
110
|
-
).optional(),
|
|
111
|
-
}).optional();
|
|
112
|
-
|
|
113
|
-
// use main dialect
|
|
114
|
-
const dialect = literal('mysql');
|
|
115
|
-
|
|
116
|
-
const schemaHash = object({
|
|
117
|
-
id: string(),
|
|
118
|
-
prevId: string(),
|
|
119
|
-
});
|
|
120
|
-
|
|
121
|
-
export const schemaInternalV3 = object({
|
|
122
|
-
version: literal('3'),
|
|
123
|
-
dialect: dialect,
|
|
124
|
-
tables: record(string(), tableV3),
|
|
125
|
-
}).strict();
|
|
126
|
-
|
|
127
|
-
export const schemaInternalV4 = object({
|
|
128
|
-
version: literal('4'),
|
|
129
|
-
dialect: dialect,
|
|
130
|
-
tables: record(string(), tableV4),
|
|
131
|
-
schemas: record(string(), string()),
|
|
132
|
-
}).strict();
|
|
133
|
-
|
|
134
|
-
export const schemaInternalV5 = object({
|
|
135
|
-
version: literal('5'),
|
|
136
|
-
dialect: dialect,
|
|
137
|
-
tables: record(string(), table),
|
|
138
|
-
schemas: record(string(), string()),
|
|
139
|
-
_meta: object({
|
|
140
|
-
schemas: record(string(), string()),
|
|
141
|
-
tables: record(string(), string()),
|
|
142
|
-
columns: record(string(), string()),
|
|
143
|
-
}),
|
|
144
|
-
internal: kitInternals,
|
|
145
|
-
}).strict();
|
|
146
|
-
|
|
147
|
-
export const schemaInternal = object({
|
|
148
|
-
version: literal('5'),
|
|
149
|
-
dialect: dialect,
|
|
150
|
-
tables: record(string(), table),
|
|
151
|
-
views: record(string(), view).default({}),
|
|
152
|
-
_meta: object({
|
|
153
|
-
tables: record(string(), string()),
|
|
154
|
-
columns: record(string(), string()),
|
|
155
|
-
}),
|
|
156
|
-
internal: kitInternals,
|
|
157
|
-
}).strict();
|
|
158
|
-
|
|
159
|
-
export const schemaV3 = schemaInternalV3.merge(schemaHash);
|
|
160
|
-
export const schemaV4 = schemaInternalV4.merge(schemaHash);
|
|
161
|
-
export const schemaV5 = schemaInternalV5.merge(schemaHash);
|
|
162
|
-
export const schema = schemaInternal.merge(schemaHash);
|
|
163
|
-
|
|
164
|
-
const tableSquashedV4 = object({
|
|
165
|
-
name: string(),
|
|
166
|
-
schema: string().optional(),
|
|
167
|
-
columns: record(string(), column),
|
|
168
|
-
indexes: record(string(), string()),
|
|
169
|
-
foreignKeys: record(string(), string()),
|
|
170
|
-
}).strict();
|
|
171
|
-
|
|
172
|
-
const tableSquashed = object({
|
|
173
|
-
name: string(),
|
|
174
|
-
columns: record(string(), column),
|
|
175
|
-
indexes: record(string(), string()),
|
|
176
|
-
foreignKeys: record(string(), string()),
|
|
177
|
-
compositePrimaryKeys: record(string(), string()),
|
|
178
|
-
uniqueConstraints: record(string(), string()).default({}),
|
|
179
|
-
checkConstraints: record(string(), string()).default({}),
|
|
180
|
-
}).strict();
|
|
181
|
-
|
|
182
|
-
const viewSquashed = view.omit({
|
|
183
|
-
algorithm: true,
|
|
184
|
-
sqlSecurity: true,
|
|
185
|
-
withCheckOption: true,
|
|
186
|
-
}).extend({ meta: string() });
|
|
187
|
-
|
|
188
|
-
export const schemaSquashed = object({
|
|
189
|
-
version: literal('5'),
|
|
190
|
-
dialect: dialect,
|
|
191
|
-
tables: record(string(), tableSquashed),
|
|
192
|
-
views: record(string(), viewSquashed),
|
|
193
|
-
}).strict();
|
|
194
|
-
|
|
195
|
-
export const schemaSquashedV4 = object({
|
|
196
|
-
version: literal('4'),
|
|
197
|
-
dialect: dialect,
|
|
198
|
-
tables: record(string(), tableSquashedV4),
|
|
199
|
-
schemas: record(string(), string()),
|
|
200
|
-
}).strict();
|
|
201
|
-
|
|
202
|
-
export type Dialect = TypeOf<typeof dialect>;
|
|
203
|
-
export type Column = TypeOf<typeof column>;
|
|
204
|
-
export type Table = TypeOf<typeof table>;
|
|
205
|
-
export type TableV4 = TypeOf<typeof tableV4>;
|
|
206
|
-
export type MySqlSchema = TypeOf<typeof schema>;
|
|
207
|
-
export type MySqlSchemaV3 = TypeOf<typeof schemaV3>;
|
|
208
|
-
export type MySqlSchemaV4 = TypeOf<typeof schemaV4>;
|
|
209
|
-
export type MySqlSchemaV5 = TypeOf<typeof schemaV5>;
|
|
210
|
-
export type MySqlSchemaInternal = TypeOf<typeof schemaInternal>;
|
|
211
|
-
export type MySqlKitInternals = TypeOf<typeof kitInternals>;
|
|
212
|
-
export type MySqlSchemaSquashed = TypeOf<typeof schemaSquashed>;
|
|
213
|
-
export type MySqlSchemaSquashedV4 = TypeOf<typeof schemaSquashedV4>;
|
|
214
|
-
export type Index = TypeOf<typeof index>;
|
|
215
|
-
export type ForeignKey = TypeOf<typeof fk>;
|
|
216
|
-
export type PrimaryKey = TypeOf<typeof compositePK>;
|
|
217
|
-
export type UniqueConstraint = TypeOf<typeof uniqueConstraint>;
|
|
218
|
-
export type CheckConstraint = TypeOf<typeof checkConstraint>;
|
|
219
|
-
export type View = TypeOf<typeof view>;
|
|
220
|
-
export type ViewSquashed = TypeOf<typeof viewSquashed>;
|
|
221
|
-
|
|
222
|
-
export const MySqlSquasher = {
|
|
223
|
-
squashIdx: (idx: Index) => {
|
|
224
|
-
index.parse(idx);
|
|
225
|
-
return `${idx.name};${idx.columns.join(',')};${idx.isUnique};${idx.using ?? ''};${idx.algorithm ?? ''};${
|
|
226
|
-
idx.lock ?? ''
|
|
227
|
-
}`;
|
|
228
|
-
},
|
|
229
|
-
unsquashIdx: (input: string): Index => {
|
|
230
|
-
const [name, columnsString, isUnique, using, algorithm, lock] = input.split(';');
|
|
231
|
-
const destructed = {
|
|
232
|
-
name,
|
|
233
|
-
columns: columnsString.split(','),
|
|
234
|
-
isUnique: isUnique === 'true',
|
|
235
|
-
using: using ? using : undefined,
|
|
236
|
-
algorithm: algorithm ? algorithm : undefined,
|
|
237
|
-
lock: lock ? lock : undefined,
|
|
238
|
-
};
|
|
239
|
-
return index.parse(destructed);
|
|
240
|
-
},
|
|
241
|
-
squashPK: (pk: PrimaryKey) => {
|
|
242
|
-
return `${pk.name};${pk.columns.join(',')}`;
|
|
243
|
-
},
|
|
244
|
-
unsquashPK: (pk: string): PrimaryKey => {
|
|
245
|
-
const splitted = pk.split(';');
|
|
246
|
-
return { name: splitted[0], columns: splitted[1].split(',') };
|
|
247
|
-
},
|
|
248
|
-
squashUnique: (unq: UniqueConstraint) => {
|
|
249
|
-
return `${unq.name};${unq.columns.join(',')}`;
|
|
250
|
-
},
|
|
251
|
-
unsquashUnique: (unq: string): UniqueConstraint => {
|
|
252
|
-
const [name, columns] = unq.split(';');
|
|
253
|
-
return { name, columns: columns.split(',') };
|
|
254
|
-
},
|
|
255
|
-
squashFK: (fk: ForeignKey) => {
|
|
256
|
-
return `${fk.name};${fk.tableFrom};${fk.columnsFrom.join(',')};${fk.tableTo};${fk.columnsTo.join(',')};${
|
|
257
|
-
fk.onUpdate ?? ''
|
|
258
|
-
};${fk.onDelete ?? ''}`;
|
|
259
|
-
},
|
|
260
|
-
unsquashFK: (input: string): ForeignKey => {
|
|
261
|
-
const [
|
|
262
|
-
name,
|
|
263
|
-
tableFrom,
|
|
264
|
-
columnsFromStr,
|
|
265
|
-
tableTo,
|
|
266
|
-
columnsToStr,
|
|
267
|
-
onUpdate,
|
|
268
|
-
onDelete,
|
|
269
|
-
] = input.split(';');
|
|
270
|
-
|
|
271
|
-
const result: ForeignKey = fk.parse({
|
|
272
|
-
name,
|
|
273
|
-
tableFrom,
|
|
274
|
-
columnsFrom: columnsFromStr.split(','),
|
|
275
|
-
tableTo,
|
|
276
|
-
columnsTo: columnsToStr.split(','),
|
|
277
|
-
onUpdate,
|
|
278
|
-
onDelete,
|
|
279
|
-
});
|
|
280
|
-
return result;
|
|
281
|
-
},
|
|
282
|
-
squashCheck: (input: CheckConstraint): string => {
|
|
283
|
-
return `${input.name};${input.value}`;
|
|
284
|
-
},
|
|
285
|
-
unsquashCheck: (input: string): CheckConstraint => {
|
|
286
|
-
const [name, value] = input.split(';');
|
|
287
|
-
|
|
288
|
-
return { name, value };
|
|
289
|
-
},
|
|
290
|
-
squashView: (view: View): string => {
|
|
291
|
-
return `${view.algorithm};${view.sqlSecurity};${view.withCheckOption}`;
|
|
292
|
-
},
|
|
293
|
-
unsquashView: (meta: string): SquasherViewMeta => {
|
|
294
|
-
const [algorithm, sqlSecurity, withCheckOption] = meta.split(';');
|
|
295
|
-
const toReturn = {
|
|
296
|
-
algorithm: algorithm,
|
|
297
|
-
sqlSecurity: sqlSecurity,
|
|
298
|
-
withCheckOption: withCheckOption !== 'undefined' ? withCheckOption : undefined,
|
|
299
|
-
};
|
|
300
|
-
|
|
301
|
-
return viewMeta.parse(toReturn);
|
|
302
|
-
},
|
|
303
|
-
};
|
|
304
|
-
|
|
305
|
-
export const squashMysqlSchemeV4 = (
|
|
306
|
-
json: MySqlSchemaV4,
|
|
307
|
-
): MySqlSchemaSquashedV4 => {
|
|
308
|
-
const mappedTables = Object.fromEntries(
|
|
309
|
-
Object.entries(json.tables).map((it) => {
|
|
310
|
-
const squashedIndexes = mapValues(it[1].indexes, (index) => {
|
|
311
|
-
return MySqlSquasher.squashIdx(index);
|
|
312
|
-
});
|
|
313
|
-
|
|
314
|
-
const squashedFKs = mapValues(it[1].foreignKeys, (fk) => {
|
|
315
|
-
return MySqlSquasher.squashFK(fk);
|
|
316
|
-
});
|
|
317
|
-
|
|
318
|
-
return [
|
|
319
|
-
it[0],
|
|
320
|
-
{
|
|
321
|
-
name: it[1].name,
|
|
322
|
-
schema: it[1].schema,
|
|
323
|
-
columns: it[1].columns,
|
|
324
|
-
indexes: squashedIndexes,
|
|
325
|
-
foreignKeys: squashedFKs,
|
|
326
|
-
},
|
|
327
|
-
];
|
|
328
|
-
}),
|
|
329
|
-
);
|
|
330
|
-
return {
|
|
331
|
-
version: '4',
|
|
332
|
-
dialect: json.dialect,
|
|
333
|
-
tables: mappedTables,
|
|
334
|
-
schemas: json.schemas,
|
|
335
|
-
};
|
|
336
|
-
};
|
|
337
|
-
|
|
338
|
-
export const squashMysqlScheme = (json: MySqlSchema): MySqlSchemaSquashed => {
|
|
339
|
-
const mappedTables = Object.fromEntries(
|
|
340
|
-
Object.entries(json.tables).map((it) => {
|
|
341
|
-
const squashedIndexes = mapValues(it[1].indexes, (index) => {
|
|
342
|
-
return MySqlSquasher.squashIdx(index);
|
|
343
|
-
});
|
|
344
|
-
|
|
345
|
-
const squashedFKs = mapValues(it[1].foreignKeys, (fk) => {
|
|
346
|
-
return MySqlSquasher.squashFK(fk);
|
|
347
|
-
});
|
|
348
|
-
|
|
349
|
-
const squashedPKs = mapValues(it[1].compositePrimaryKeys, (pk) => {
|
|
350
|
-
return MySqlSquasher.squashPK(pk);
|
|
351
|
-
});
|
|
352
|
-
|
|
353
|
-
const squashedUniqueConstraints = mapValues(
|
|
354
|
-
it[1].uniqueConstraints,
|
|
355
|
-
(unq) => {
|
|
356
|
-
return MySqlSquasher.squashUnique(unq);
|
|
357
|
-
},
|
|
358
|
-
);
|
|
359
|
-
|
|
360
|
-
const squashedCheckConstraints = mapValues(it[1].checkConstraint, (check) => {
|
|
361
|
-
return MySqlSquasher.squashCheck(check);
|
|
362
|
-
});
|
|
363
|
-
|
|
364
|
-
return [
|
|
365
|
-
it[0],
|
|
366
|
-
{
|
|
367
|
-
name: it[1].name,
|
|
368
|
-
columns: it[1].columns,
|
|
369
|
-
indexes: squashedIndexes,
|
|
370
|
-
foreignKeys: squashedFKs,
|
|
371
|
-
compositePrimaryKeys: squashedPKs,
|
|
372
|
-
uniqueConstraints: squashedUniqueConstraints,
|
|
373
|
-
checkConstraints: squashedCheckConstraints,
|
|
374
|
-
},
|
|
375
|
-
];
|
|
376
|
-
}),
|
|
377
|
-
);
|
|
378
|
-
|
|
379
|
-
const mappedViews = Object.fromEntries(
|
|
380
|
-
Object.entries(json.views).map(([key, value]) => {
|
|
381
|
-
const meta = MySqlSquasher.squashView(value);
|
|
382
|
-
|
|
383
|
-
return [key, {
|
|
384
|
-
name: value.name,
|
|
385
|
-
isExisting: value.isExisting,
|
|
386
|
-
columns: value.columns,
|
|
387
|
-
definition: value.definition,
|
|
388
|
-
meta,
|
|
389
|
-
}];
|
|
390
|
-
}),
|
|
391
|
-
);
|
|
392
|
-
|
|
393
|
-
return {
|
|
394
|
-
version: '5',
|
|
395
|
-
dialect: json.dialect,
|
|
396
|
-
tables: mappedTables,
|
|
397
|
-
views: mappedViews,
|
|
398
|
-
};
|
|
399
|
-
};
|
|
400
|
-
|
|
401
|
-
export const mysqlSchema = schema;
|
|
402
|
-
export const mysqlSchemaV3 = schemaV3;
|
|
403
|
-
export const mysqlSchemaV4 = schemaV4;
|
|
404
|
-
export const mysqlSchemaV5 = schemaV5;
|
|
405
|
-
export const mysqlSchemaSquashed = schemaSquashed;
|
|
406
|
-
|
|
407
|
-
// no prev version
|
|
408
|
-
export const backwardCompatibleMysqlSchema = union([mysqlSchemaV5, schema]);
|
|
409
|
-
|
|
410
|
-
export const dryMySql = mysqlSchema.parse({
|
|
411
|
-
version: '5',
|
|
412
|
-
dialect: 'mysql',
|
|
413
|
-
id: originUUID,
|
|
414
|
-
prevId: '',
|
|
415
|
-
tables: {},
|
|
416
|
-
schemas: {},
|
|
417
|
-
views: {},
|
|
418
|
-
_meta: {
|
|
419
|
-
schemas: {},
|
|
420
|
-
tables: {},
|
|
421
|
-
columns: {},
|
|
422
|
-
},
|
|
423
|
-
});
|