@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,322 +0,0 @@
|
|
|
1
|
-
import chalk from 'chalk';
|
|
2
|
-
|
|
3
|
-
import { SQLiteSchemaInternal, SQLiteSchemaSquashed, SQLiteSquasher } from '../../serializer/sqliteSchema';
|
|
4
|
-
import {
|
|
5
|
-
CreateSqliteIndexConvertor,
|
|
6
|
-
fromJson,
|
|
7
|
-
SQLiteCreateTableConvertor,
|
|
8
|
-
SQLiteDropTableConvertor,
|
|
9
|
-
SqliteRenameTableConvertor,
|
|
10
|
-
} from '../../sqlgenerator';
|
|
11
|
-
|
|
12
|
-
import type { JsonStatement } from '../../jsonStatements';
|
|
13
|
-
import { findAddedAndRemoved, type SQLiteDB } from '../../utils';
|
|
14
|
-
|
|
15
|
-
export const _moveDataStatements = (
|
|
16
|
-
tableName: string,
|
|
17
|
-
json: SQLiteSchemaSquashed,
|
|
18
|
-
dataLoss: boolean = false,
|
|
19
|
-
) => {
|
|
20
|
-
const statements: string[] = [];
|
|
21
|
-
|
|
22
|
-
const newTableName = `__new_${tableName}`;
|
|
23
|
-
|
|
24
|
-
// create table statement from a new json2 with proper name
|
|
25
|
-
const tableColumns = Object.values(json.tables[tableName].columns);
|
|
26
|
-
const referenceData = Object.values(json.tables[tableName].foreignKeys);
|
|
27
|
-
const compositePKs = Object.values(
|
|
28
|
-
json.tables[tableName].compositePrimaryKeys,
|
|
29
|
-
).map((it) => SQLiteSquasher.unsquashPK(it));
|
|
30
|
-
const checkConstraints = Object.values(json.tables[tableName].checkConstraints);
|
|
31
|
-
|
|
32
|
-
const mappedCheckConstraints: string[] = checkConstraints.map((it) =>
|
|
33
|
-
it.replaceAll(`"${tableName}".`, `"${newTableName}".`)
|
|
34
|
-
.replaceAll(`\`${tableName}\`.`, `\`${newTableName}\`.`)
|
|
35
|
-
.replaceAll(`${tableName}.`, `${newTableName}.`)
|
|
36
|
-
.replaceAll(`'${tableName}'.`, `\`${newTableName}\`.`)
|
|
37
|
-
);
|
|
38
|
-
|
|
39
|
-
const fks = referenceData.map((it) => SQLiteSquasher.unsquashPushFK(it));
|
|
40
|
-
|
|
41
|
-
// create new table
|
|
42
|
-
statements.push(
|
|
43
|
-
new SQLiteCreateTableConvertor().convert({
|
|
44
|
-
type: 'sqlite_create_table',
|
|
45
|
-
tableName: newTableName,
|
|
46
|
-
columns: tableColumns,
|
|
47
|
-
referenceData: fks,
|
|
48
|
-
compositePKs,
|
|
49
|
-
checkConstraints: mappedCheckConstraints,
|
|
50
|
-
}),
|
|
51
|
-
);
|
|
52
|
-
|
|
53
|
-
// move data
|
|
54
|
-
if (!dataLoss) {
|
|
55
|
-
const columns = Object.keys(json.tables[tableName].columns).map(
|
|
56
|
-
(c) => `"${c}"`,
|
|
57
|
-
);
|
|
58
|
-
|
|
59
|
-
statements.push(
|
|
60
|
-
`INSERT INTO \`${newTableName}\`(${
|
|
61
|
-
columns.join(
|
|
62
|
-
', ',
|
|
63
|
-
)
|
|
64
|
-
}) SELECT ${columns.join(', ')} FROM \`${tableName}\`;`,
|
|
65
|
-
);
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
statements.push(
|
|
69
|
-
new SQLiteDropTableConvertor().convert({
|
|
70
|
-
type: 'drop_table',
|
|
71
|
-
tableName: tableName,
|
|
72
|
-
schema: '',
|
|
73
|
-
}),
|
|
74
|
-
);
|
|
75
|
-
|
|
76
|
-
// rename table
|
|
77
|
-
statements.push(
|
|
78
|
-
new SqliteRenameTableConvertor().convert({
|
|
79
|
-
fromSchema: '',
|
|
80
|
-
tableNameFrom: newTableName,
|
|
81
|
-
tableNameTo: tableName,
|
|
82
|
-
toSchema: '',
|
|
83
|
-
type: 'rename_table',
|
|
84
|
-
}),
|
|
85
|
-
);
|
|
86
|
-
|
|
87
|
-
for (const idx of Object.values(json.tables[tableName].indexes)) {
|
|
88
|
-
statements.push(
|
|
89
|
-
new CreateSqliteIndexConvertor().convert({
|
|
90
|
-
type: 'create_index',
|
|
91
|
-
tableName: tableName,
|
|
92
|
-
schema: '',
|
|
93
|
-
data: idx,
|
|
94
|
-
}),
|
|
95
|
-
);
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
return statements;
|
|
99
|
-
};
|
|
100
|
-
|
|
101
|
-
export const getOldTableName = (
|
|
102
|
-
tableName: string,
|
|
103
|
-
meta: SQLiteSchemaInternal['_meta'],
|
|
104
|
-
) => {
|
|
105
|
-
for (const key of Object.keys(meta.tables)) {
|
|
106
|
-
const value = meta.tables[key];
|
|
107
|
-
if (`"${tableName}"` === value) {
|
|
108
|
-
return key.substring(1, key.length - 1);
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
return tableName;
|
|
112
|
-
};
|
|
113
|
-
|
|
114
|
-
export const getNewTableName = (
|
|
115
|
-
tableName: string,
|
|
116
|
-
meta: SQLiteSchemaInternal['_meta'],
|
|
117
|
-
) => {
|
|
118
|
-
if (typeof meta.tables[`"${tableName}"`] !== 'undefined') {
|
|
119
|
-
return meta.tables[`"${tableName}"`].substring(
|
|
120
|
-
1,
|
|
121
|
-
meta.tables[`"${tableName}"`].length - 1,
|
|
122
|
-
);
|
|
123
|
-
}
|
|
124
|
-
return tableName;
|
|
125
|
-
};
|
|
126
|
-
|
|
127
|
-
export const logSuggestionsAndReturn = async (
|
|
128
|
-
connection: SQLiteDB,
|
|
129
|
-
statements: JsonStatement[],
|
|
130
|
-
json1: SQLiteSchemaSquashed,
|
|
131
|
-
json2: SQLiteSchemaSquashed,
|
|
132
|
-
meta: SQLiteSchemaInternal['_meta'],
|
|
133
|
-
) => {
|
|
134
|
-
let shouldAskForApprove = false;
|
|
135
|
-
const statementsToExecute: string[] = [];
|
|
136
|
-
const infoToPrint: string[] = [];
|
|
137
|
-
|
|
138
|
-
const tablesToRemove: string[] = [];
|
|
139
|
-
const columnsToRemove: string[] = [];
|
|
140
|
-
const schemasToRemove: string[] = [];
|
|
141
|
-
const tablesToTruncate: string[] = [];
|
|
142
|
-
|
|
143
|
-
for (const statement of statements) {
|
|
144
|
-
if (statement.type === 'drop_table') {
|
|
145
|
-
const res = await connection.query<{ count: string }>(
|
|
146
|
-
`select count(*) as count from \`${statement.tableName}\``,
|
|
147
|
-
);
|
|
148
|
-
const count = Number(res[0].count);
|
|
149
|
-
if (count > 0) {
|
|
150
|
-
infoToPrint.push(
|
|
151
|
-
`· You're about to delete ${
|
|
152
|
-
chalk.underline(
|
|
153
|
-
statement.tableName,
|
|
154
|
-
)
|
|
155
|
-
} table with ${count} items`,
|
|
156
|
-
);
|
|
157
|
-
tablesToRemove.push(statement.tableName);
|
|
158
|
-
shouldAskForApprove = true;
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
const fromJsonStatement = fromJson([statement], 'sqlite', 'push');
|
|
162
|
-
statementsToExecute.push(
|
|
163
|
-
...(Array.isArray(fromJsonStatement) ? fromJsonStatement : [fromJsonStatement]),
|
|
164
|
-
);
|
|
165
|
-
} else if (statement.type === 'alter_table_drop_column') {
|
|
166
|
-
const tableName = statement.tableName;
|
|
167
|
-
const columnName = statement.columnName;
|
|
168
|
-
|
|
169
|
-
const res = await connection.query<{ count: string }>(
|
|
170
|
-
`select count(\`${tableName}\`.\`${columnName}\`) as count from \`${tableName}\``,
|
|
171
|
-
);
|
|
172
|
-
const count = Number(res[0].count);
|
|
173
|
-
if (count > 0) {
|
|
174
|
-
infoToPrint.push(
|
|
175
|
-
`· You're about to delete ${
|
|
176
|
-
chalk.underline(
|
|
177
|
-
columnName,
|
|
178
|
-
)
|
|
179
|
-
} column in ${tableName} table with ${count} items`,
|
|
180
|
-
);
|
|
181
|
-
columnsToRemove.push(`${tableName}_${statement.columnName}`);
|
|
182
|
-
shouldAskForApprove = true;
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
const fromJsonStatement = fromJson([statement], 'sqlite', 'push');
|
|
186
|
-
statementsToExecute.push(
|
|
187
|
-
...(Array.isArray(fromJsonStatement) ? fromJsonStatement : [fromJsonStatement]),
|
|
188
|
-
);
|
|
189
|
-
} else if (
|
|
190
|
-
statement.type === 'sqlite_alter_table_add_column'
|
|
191
|
-
&& (statement.column.notNull && !statement.column.default)
|
|
192
|
-
) {
|
|
193
|
-
const tableName = statement.tableName;
|
|
194
|
-
const columnName = statement.column.name;
|
|
195
|
-
const res = await connection.query<{ count: string }>(
|
|
196
|
-
`select count(*) as count from \`${tableName}\``,
|
|
197
|
-
);
|
|
198
|
-
const count = Number(res[0].count);
|
|
199
|
-
if (count > 0) {
|
|
200
|
-
infoToPrint.push(
|
|
201
|
-
`· You're about to add not-null ${
|
|
202
|
-
chalk.underline(
|
|
203
|
-
columnName,
|
|
204
|
-
)
|
|
205
|
-
} column without default value, which contains ${count} items`,
|
|
206
|
-
);
|
|
207
|
-
|
|
208
|
-
tablesToTruncate.push(tableName);
|
|
209
|
-
statementsToExecute.push(`delete from ${tableName};`);
|
|
210
|
-
|
|
211
|
-
shouldAskForApprove = true;
|
|
212
|
-
}
|
|
213
|
-
|
|
214
|
-
const fromJsonStatement = fromJson([statement], 'sqlite', 'push');
|
|
215
|
-
statementsToExecute.push(
|
|
216
|
-
...(Array.isArray(fromJsonStatement) ? fromJsonStatement : [fromJsonStatement]),
|
|
217
|
-
);
|
|
218
|
-
} else if (statement.type === 'recreate_table') {
|
|
219
|
-
const tableName = statement.tableName;
|
|
220
|
-
const oldTableName = getOldTableName(tableName, meta);
|
|
221
|
-
|
|
222
|
-
let dataLoss = false;
|
|
223
|
-
|
|
224
|
-
const prevColumnNames = Object.keys(json1.tables[oldTableName].columns);
|
|
225
|
-
const currentColumnNames = Object.keys(json2.tables[tableName].columns);
|
|
226
|
-
const { removedColumns, addedColumns } = findAddedAndRemoved(
|
|
227
|
-
prevColumnNames,
|
|
228
|
-
currentColumnNames,
|
|
229
|
-
);
|
|
230
|
-
|
|
231
|
-
if (removedColumns.length) {
|
|
232
|
-
for (const removedColumn of removedColumns) {
|
|
233
|
-
const res = await connection.query<{ count: string }>(
|
|
234
|
-
`select count(\`${tableName}\`.\`${removedColumn}\`) as count from \`${tableName}\``,
|
|
235
|
-
);
|
|
236
|
-
|
|
237
|
-
const count = Number(res[0].count);
|
|
238
|
-
if (count > 0) {
|
|
239
|
-
infoToPrint.push(
|
|
240
|
-
`· You're about to delete ${
|
|
241
|
-
chalk.underline(
|
|
242
|
-
removedColumn,
|
|
243
|
-
)
|
|
244
|
-
} column in ${tableName} table with ${count} items`,
|
|
245
|
-
);
|
|
246
|
-
columnsToRemove.push(removedColumn);
|
|
247
|
-
shouldAskForApprove = true;
|
|
248
|
-
}
|
|
249
|
-
}
|
|
250
|
-
}
|
|
251
|
-
|
|
252
|
-
if (addedColumns.length) {
|
|
253
|
-
for (const addedColumn of addedColumns) {
|
|
254
|
-
const [res] = await connection.query<{ count: string }>(
|
|
255
|
-
`select count(*) as count from \`${tableName}\``,
|
|
256
|
-
);
|
|
257
|
-
|
|
258
|
-
const columnConf = json2.tables[tableName].columns[addedColumn];
|
|
259
|
-
|
|
260
|
-
const count = Number(res.count);
|
|
261
|
-
if (count > 0 && columnConf.notNull && !columnConf.default) {
|
|
262
|
-
dataLoss = true;
|
|
263
|
-
infoToPrint.push(
|
|
264
|
-
`· You're about to add not-null ${
|
|
265
|
-
chalk.underline(
|
|
266
|
-
addedColumn,
|
|
267
|
-
)
|
|
268
|
-
} column without default value to table, which contains ${count} items`,
|
|
269
|
-
);
|
|
270
|
-
shouldAskForApprove = true;
|
|
271
|
-
tablesToTruncate.push(tableName);
|
|
272
|
-
|
|
273
|
-
statementsToExecute.push(`DELETE FROM \`${tableName}\`;`);
|
|
274
|
-
}
|
|
275
|
-
}
|
|
276
|
-
}
|
|
277
|
-
|
|
278
|
-
// check if some tables referencing current for pragma
|
|
279
|
-
const tablesReferencingCurrent: string[] = [];
|
|
280
|
-
|
|
281
|
-
for (const table of Object.values(json2.tables)) {
|
|
282
|
-
const tablesRefs = Object.values(json2.tables[table.name].foreignKeys)
|
|
283
|
-
.filter((t) => SQLiteSquasher.unsquashPushFK(t).tableTo === tableName)
|
|
284
|
-
.map((it) => SQLiteSquasher.unsquashPushFK(it).tableFrom);
|
|
285
|
-
|
|
286
|
-
tablesReferencingCurrent.push(...tablesRefs);
|
|
287
|
-
}
|
|
288
|
-
|
|
289
|
-
if (!tablesReferencingCurrent.length) {
|
|
290
|
-
statementsToExecute.push(..._moveDataStatements(tableName, json2, dataLoss));
|
|
291
|
-
continue;
|
|
292
|
-
}
|
|
293
|
-
|
|
294
|
-
const [{ foreign_keys: pragmaState }] = await connection.query<{
|
|
295
|
-
foreign_keys: number;
|
|
296
|
-
}>(`PRAGMA foreign_keys;`);
|
|
297
|
-
|
|
298
|
-
if (pragmaState) {
|
|
299
|
-
statementsToExecute.push(`PRAGMA foreign_keys=OFF;`);
|
|
300
|
-
}
|
|
301
|
-
statementsToExecute.push(..._moveDataStatements(tableName, json2, dataLoss));
|
|
302
|
-
if (pragmaState) {
|
|
303
|
-
statementsToExecute.push(`PRAGMA foreign_keys=ON;`);
|
|
304
|
-
}
|
|
305
|
-
} else {
|
|
306
|
-
const fromJsonStatement = fromJson([statement], 'sqlite', 'push');
|
|
307
|
-
statementsToExecute.push(
|
|
308
|
-
...(Array.isArray(fromJsonStatement) ? fromJsonStatement : [fromJsonStatement]),
|
|
309
|
-
);
|
|
310
|
-
}
|
|
311
|
-
}
|
|
312
|
-
|
|
313
|
-
return {
|
|
314
|
-
statementsToExecute,
|
|
315
|
-
shouldAskForApprove,
|
|
316
|
-
infoToPrint,
|
|
317
|
-
columnsToRemove: [...new Set(columnsToRemove)],
|
|
318
|
-
schemasToRemove: [...new Set(schemasToRemove)],
|
|
319
|
-
tablesToTruncate: [...new Set(tablesToTruncate)],
|
|
320
|
-
tablesToRemove: [...new Set(tablesToRemove)],
|
|
321
|
-
};
|
|
322
|
-
};
|
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
import chalk from 'chalk';
|
|
2
|
-
import { writeFileSync } from 'fs';
|
|
3
|
-
import { mapEntries } from 'src/global';
|
|
4
|
-
import { SQLiteSchema, sqliteSchemaV5 } from 'src/serializer/sqliteSchema';
|
|
5
|
-
import { prepareOutFolder, validateWithReport } from 'src/utils';
|
|
6
|
-
|
|
7
|
-
export const upSqliteHandler = (out: string) => {
|
|
8
|
-
const { snapshots } = prepareOutFolder(out, 'sqlite');
|
|
9
|
-
const report = validateWithReport(snapshots, 'sqlite');
|
|
10
|
-
|
|
11
|
-
report.nonLatest
|
|
12
|
-
.map((it) => ({
|
|
13
|
-
path: it,
|
|
14
|
-
raw: report.rawMap[it]!! as Record<string, any>,
|
|
15
|
-
}))
|
|
16
|
-
.forEach((it) => {
|
|
17
|
-
const path = it.path;
|
|
18
|
-
const result = updateUpToV6(it.raw);
|
|
19
|
-
|
|
20
|
-
console.log(`[${chalk.green('✓')}] ${path}`);
|
|
21
|
-
|
|
22
|
-
writeFileSync(path, JSON.stringify(result, null, 2));
|
|
23
|
-
});
|
|
24
|
-
|
|
25
|
-
console.log("Everything's fine 🐶🔥");
|
|
26
|
-
};
|
|
27
|
-
|
|
28
|
-
const updateUpToV6 = (json: Record<string, any>): SQLiteSchema => {
|
|
29
|
-
const schema = sqliteSchemaV5.parse(json);
|
|
30
|
-
|
|
31
|
-
const tables = mapEntries(schema.tables, (tableKey, table) => {
|
|
32
|
-
const columns = mapEntries(table.columns, (key, value) => {
|
|
33
|
-
if (
|
|
34
|
-
value.default
|
|
35
|
-
&& (typeof value.default === 'object' || Array.isArray(value.default))
|
|
36
|
-
) {
|
|
37
|
-
value.default = `'${JSON.stringify(value.default)}'`;
|
|
38
|
-
}
|
|
39
|
-
return [key, value];
|
|
40
|
-
});
|
|
41
|
-
table.columns = columns;
|
|
42
|
-
return [tableKey, table];
|
|
43
|
-
});
|
|
44
|
-
|
|
45
|
-
return {
|
|
46
|
-
...schema,
|
|
47
|
-
version: '6',
|
|
48
|
-
dialect: 'sqlite',
|
|
49
|
-
tables: tables,
|
|
50
|
-
views: {},
|
|
51
|
-
};
|
|
52
|
-
};
|