@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
package/src/loader.mjs
DELETED
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
import esbuild from 'esbuild';
|
|
2
|
-
import { readFileSync } from 'fs';
|
|
3
|
-
import * as path from 'path';
|
|
4
|
-
|
|
5
|
-
const parse = (it) => {
|
|
6
|
-
if (!it) return { drizzle: false };
|
|
7
|
-
|
|
8
|
-
if (it.endsWith('__drizzle__')) {
|
|
9
|
-
const offset = it.startsWith('file://') ? 'file://'.length : 0;
|
|
10
|
-
const clean = it.slice(offset, -'__drizzle__'.length);
|
|
11
|
-
return { drizzle: true, clean, original: it };
|
|
12
|
-
}
|
|
13
|
-
return { drizzle: false, clean: it };
|
|
14
|
-
};
|
|
15
|
-
|
|
16
|
-
export function resolve(specifier, context, nextResolve) {
|
|
17
|
-
const { drizzle, clean } = parse(specifier);
|
|
18
|
-
if (drizzle && !clean.endsWith('.ts') && !clean.endsWith('.mts')) {
|
|
19
|
-
return nextResolve(clean);
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
if (drizzle) {
|
|
23
|
-
return {
|
|
24
|
-
shortCircuit: true,
|
|
25
|
-
url: `file://${specifier}`,
|
|
26
|
-
};
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
const parsedParent = parse(context.parentURL);
|
|
30
|
-
const parentURL = parsedParent.drizzle
|
|
31
|
-
? new URL(`file://${path.resolve(parsedParent.clean)}`)
|
|
32
|
-
: context.parentURL;
|
|
33
|
-
|
|
34
|
-
// Let Node.js handle all other specifiers.
|
|
35
|
-
return nextResolve(specifier, { ...context, parentURL });
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
export async function load(url, context, defaultLoad) {
|
|
39
|
-
const { drizzle, clean } = parse(url);
|
|
40
|
-
if (drizzle) {
|
|
41
|
-
const file = readFileSync(clean, 'utf-8');
|
|
42
|
-
if (clean.endsWith('.ts') || clean.endsWith('.mts')) {
|
|
43
|
-
const source = esbuild.transformSync(file, {
|
|
44
|
-
loader: 'ts',
|
|
45
|
-
format: 'esm',
|
|
46
|
-
});
|
|
47
|
-
return {
|
|
48
|
-
format: 'module',
|
|
49
|
-
shortCircuit: true,
|
|
50
|
-
source: source.code,
|
|
51
|
-
};
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
// let Node.js handle all other URLs
|
|
56
|
-
return defaultLoad(url, context, defaultLoad);
|
|
57
|
-
}
|
|
@@ -1,217 +0,0 @@
|
|
|
1
|
-
import { randomUUID } from 'crypto';
|
|
2
|
-
import fs from 'fs';
|
|
3
|
-
import { CasingType } from './cli/validations/common';
|
|
4
|
-
import { serializeMySql, serializePg, serializeSingleStore, serializeSQLite } from './serializer';
|
|
5
|
-
import { dryMySql, MySqlSchema, mysqlSchema } from './serializer/mysqlSchema';
|
|
6
|
-
import { dryPg, PgSchema, pgSchema, PgSchemaInternal } from './serializer/pgSchema';
|
|
7
|
-
import { drySingleStore, SingleStoreSchema, singlestoreSchema } from './serializer/singlestoreSchema';
|
|
8
|
-
import { drySQLite, SQLiteSchema, sqliteSchema } from './serializer/sqliteSchema';
|
|
9
|
-
|
|
10
|
-
export const prepareMySqlDbPushSnapshot = async (
|
|
11
|
-
prev: MySqlSchema,
|
|
12
|
-
schemaPath: string | string[],
|
|
13
|
-
casing: CasingType | undefined,
|
|
14
|
-
): Promise<{ prev: MySqlSchema; cur: MySqlSchema }> => {
|
|
15
|
-
const serialized = await serializeMySql(schemaPath, casing);
|
|
16
|
-
|
|
17
|
-
const id = randomUUID();
|
|
18
|
-
const idPrev = prev.id;
|
|
19
|
-
|
|
20
|
-
const { version, dialect, ...rest } = serialized;
|
|
21
|
-
const result: MySqlSchema = { version, dialect, id, prevId: idPrev, ...rest };
|
|
22
|
-
|
|
23
|
-
return { prev, cur: result };
|
|
24
|
-
};
|
|
25
|
-
|
|
26
|
-
export const prepareSingleStoreDbPushSnapshot = async (
|
|
27
|
-
prev: SingleStoreSchema,
|
|
28
|
-
schemaPath: string | string[],
|
|
29
|
-
casing: CasingType | undefined,
|
|
30
|
-
): Promise<{ prev: SingleStoreSchema; cur: SingleStoreSchema }> => {
|
|
31
|
-
const serialized = await serializeSingleStore(schemaPath, casing);
|
|
32
|
-
|
|
33
|
-
const id = randomUUID();
|
|
34
|
-
const idPrev = prev.id;
|
|
35
|
-
|
|
36
|
-
const { version, dialect, ...rest } = serialized;
|
|
37
|
-
const result: SingleStoreSchema = { version, dialect, id, prevId: idPrev, ...rest };
|
|
38
|
-
|
|
39
|
-
return { prev, cur: result };
|
|
40
|
-
};
|
|
41
|
-
|
|
42
|
-
export const prepareSQLiteDbPushSnapshot = async (
|
|
43
|
-
prev: SQLiteSchema,
|
|
44
|
-
schemaPath: string | string[],
|
|
45
|
-
casing: CasingType | undefined,
|
|
46
|
-
): Promise<{ prev: SQLiteSchema; cur: SQLiteSchema }> => {
|
|
47
|
-
const serialized = await serializeSQLite(schemaPath, casing);
|
|
48
|
-
|
|
49
|
-
const id = randomUUID();
|
|
50
|
-
const idPrev = prev.id;
|
|
51
|
-
|
|
52
|
-
const { version, dialect, ...rest } = serialized;
|
|
53
|
-
const result: SQLiteSchema = {
|
|
54
|
-
version,
|
|
55
|
-
dialect,
|
|
56
|
-
id,
|
|
57
|
-
prevId: idPrev,
|
|
58
|
-
...rest,
|
|
59
|
-
};
|
|
60
|
-
|
|
61
|
-
return { prev, cur: result };
|
|
62
|
-
};
|
|
63
|
-
|
|
64
|
-
export const preparePgDbPushSnapshot = async (
|
|
65
|
-
prev: PgSchema,
|
|
66
|
-
schemaPath: string | string[],
|
|
67
|
-
casing: CasingType | undefined,
|
|
68
|
-
schemaFilter: string[] = ['public'],
|
|
69
|
-
): Promise<{ prev: PgSchema; cur: PgSchema }> => {
|
|
70
|
-
const serialized = await serializePg(schemaPath, casing, schemaFilter);
|
|
71
|
-
|
|
72
|
-
const id = randomUUID();
|
|
73
|
-
const idPrev = prev.id;
|
|
74
|
-
|
|
75
|
-
const { version, dialect, ...rest } = serialized;
|
|
76
|
-
const result: PgSchema = { version, dialect, id, prevId: idPrev, ...rest };
|
|
77
|
-
|
|
78
|
-
return { prev, cur: result };
|
|
79
|
-
};
|
|
80
|
-
|
|
81
|
-
export const prepareMySqlMigrationSnapshot = async (
|
|
82
|
-
migrationFolders: string[],
|
|
83
|
-
schemaPath: string | string[],
|
|
84
|
-
casing: CasingType | undefined,
|
|
85
|
-
): Promise<{ prev: MySqlSchema; cur: MySqlSchema; custom: MySqlSchema }> => {
|
|
86
|
-
const prevSnapshot = mysqlSchema.parse(
|
|
87
|
-
preparePrevSnapshot(migrationFolders, dryMySql),
|
|
88
|
-
);
|
|
89
|
-
const serialized = await serializeMySql(schemaPath, casing);
|
|
90
|
-
|
|
91
|
-
const id = randomUUID();
|
|
92
|
-
const idPrev = prevSnapshot.id;
|
|
93
|
-
|
|
94
|
-
const { version, dialect, ...rest } = serialized;
|
|
95
|
-
const result: MySqlSchema = { version, dialect, id, prevId: idPrev, ...rest };
|
|
96
|
-
|
|
97
|
-
const { id: _ignoredId, prevId: _ignoredPrevId, ...prevRest } = prevSnapshot;
|
|
98
|
-
|
|
99
|
-
// that's for custom migrations, when we need new IDs, but old snapshot
|
|
100
|
-
const custom: MySqlSchema = {
|
|
101
|
-
id,
|
|
102
|
-
prevId: idPrev,
|
|
103
|
-
...prevRest,
|
|
104
|
-
};
|
|
105
|
-
|
|
106
|
-
return { prev: prevSnapshot, cur: result, custom };
|
|
107
|
-
};
|
|
108
|
-
|
|
109
|
-
export const prepareSingleStoreMigrationSnapshot = async (
|
|
110
|
-
migrationFolders: string[],
|
|
111
|
-
schemaPath: string | string[],
|
|
112
|
-
casing: CasingType | undefined,
|
|
113
|
-
): Promise<{ prev: SingleStoreSchema; cur: SingleStoreSchema; custom: SingleStoreSchema }> => {
|
|
114
|
-
const prevSnapshot = singlestoreSchema.parse(
|
|
115
|
-
preparePrevSnapshot(migrationFolders, drySingleStore),
|
|
116
|
-
);
|
|
117
|
-
const serialized = await serializeSingleStore(schemaPath, casing);
|
|
118
|
-
|
|
119
|
-
const id = randomUUID();
|
|
120
|
-
const idPrev = prevSnapshot.id;
|
|
121
|
-
|
|
122
|
-
const { version, dialect, ...rest } = serialized;
|
|
123
|
-
const result: SingleStoreSchema = { version, dialect, id, prevId: idPrev, ...rest };
|
|
124
|
-
|
|
125
|
-
const { id: _ignoredId, prevId: _ignoredPrevId, ...prevRest } = prevSnapshot;
|
|
126
|
-
|
|
127
|
-
// that's for custom migrations, when we need new IDs, but old snapshot
|
|
128
|
-
const custom: SingleStoreSchema = {
|
|
129
|
-
id,
|
|
130
|
-
prevId: idPrev,
|
|
131
|
-
...prevRest,
|
|
132
|
-
};
|
|
133
|
-
|
|
134
|
-
return { prev: prevSnapshot, cur: result, custom };
|
|
135
|
-
};
|
|
136
|
-
|
|
137
|
-
export const prepareSqliteMigrationSnapshot = async (
|
|
138
|
-
snapshots: string[],
|
|
139
|
-
schemaPath: string | string[],
|
|
140
|
-
casing: CasingType | undefined,
|
|
141
|
-
): Promise<{ prev: SQLiteSchema; cur: SQLiteSchema; custom: SQLiteSchema }> => {
|
|
142
|
-
const prevSnapshot = sqliteSchema.parse(
|
|
143
|
-
preparePrevSnapshot(snapshots, drySQLite),
|
|
144
|
-
);
|
|
145
|
-
const serialized = await serializeSQLite(schemaPath, casing);
|
|
146
|
-
|
|
147
|
-
const id = randomUUID();
|
|
148
|
-
const idPrev = prevSnapshot.id;
|
|
149
|
-
|
|
150
|
-
const { version, dialect, ...rest } = serialized;
|
|
151
|
-
const result: SQLiteSchema = {
|
|
152
|
-
version,
|
|
153
|
-
dialect,
|
|
154
|
-
id,
|
|
155
|
-
prevId: idPrev,
|
|
156
|
-
...rest,
|
|
157
|
-
};
|
|
158
|
-
|
|
159
|
-
const { id: _ignoredId, prevId: _ignoredPrevId, ...prevRest } = prevSnapshot;
|
|
160
|
-
|
|
161
|
-
// that's for custom migrations, when we need new IDs, but old snapshot
|
|
162
|
-
const custom: SQLiteSchema = {
|
|
163
|
-
id,
|
|
164
|
-
prevId: idPrev,
|
|
165
|
-
...prevRest,
|
|
166
|
-
};
|
|
167
|
-
|
|
168
|
-
return { prev: prevSnapshot, cur: result, custom };
|
|
169
|
-
};
|
|
170
|
-
|
|
171
|
-
export const fillPgSnapshot = ({
|
|
172
|
-
serialized,
|
|
173
|
-
id,
|
|
174
|
-
idPrev,
|
|
175
|
-
}: {
|
|
176
|
-
serialized: PgSchemaInternal;
|
|
177
|
-
id: string;
|
|
178
|
-
idPrev: string;
|
|
179
|
-
}): PgSchema => {
|
|
180
|
-
// const id = randomUUID();
|
|
181
|
-
return { id, prevId: idPrev, ...serialized };
|
|
182
|
-
};
|
|
183
|
-
|
|
184
|
-
export const preparePgMigrationSnapshot = async (
|
|
185
|
-
snapshots: string[],
|
|
186
|
-
schemaPath: string | string[],
|
|
187
|
-
casing: CasingType | undefined,
|
|
188
|
-
): Promise<{ prev: PgSchema; cur: PgSchema; custom: PgSchema }> => {
|
|
189
|
-
const prevSnapshot = pgSchema.parse(preparePrevSnapshot(snapshots, dryPg));
|
|
190
|
-
const serialized = await serializePg(schemaPath, casing);
|
|
191
|
-
|
|
192
|
-
const id = randomUUID();
|
|
193
|
-
const idPrev = prevSnapshot.id;
|
|
194
|
-
|
|
195
|
-
// const { version, dialect, ...rest } = serialized;
|
|
196
|
-
|
|
197
|
-
const result: PgSchema = { id, prevId: idPrev, ...serialized };
|
|
198
|
-
|
|
199
|
-
const { id: _ignoredId, prevId: _ignoredPrevId, ...prevRest } = prevSnapshot;
|
|
200
|
-
|
|
201
|
-
// that's for custom migrations, when we need new IDs, but old snapshot
|
|
202
|
-
const custom: PgSchema = fillPgSnapshot({ serialized: prevRest, id, idPrev });
|
|
203
|
-
|
|
204
|
-
return { prev: prevSnapshot, cur: result, custom };
|
|
205
|
-
};
|
|
206
|
-
|
|
207
|
-
const preparePrevSnapshot = (snapshots: string[], defaultPrev: any) => {
|
|
208
|
-
let prevSnapshot: any;
|
|
209
|
-
|
|
210
|
-
if (snapshots.length === 0) {
|
|
211
|
-
prevSnapshot = defaultPrev;
|
|
212
|
-
} else {
|
|
213
|
-
const lastSnapshot = snapshots[snapshots.length - 1];
|
|
214
|
-
prevSnapshot = JSON.parse(fs.readFileSync(lastSnapshot).toString());
|
|
215
|
-
}
|
|
216
|
-
return prevSnapshot;
|
|
217
|
-
};
|
package/src/schemaValidator.ts
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import { enum as enumType, TypeOf, union } from 'zod';
|
|
2
|
-
import { mysqlSchema, mysqlSchemaSquashed } from './serializer/mysqlSchema';
|
|
3
|
-
import { pgSchema, pgSchemaSquashed } from './serializer/pgSchema';
|
|
4
|
-
import { singlestoreSchema, singlestoreSchemaSquashed } from './serializer/singlestoreSchema';
|
|
5
|
-
import { sqliteSchema, SQLiteSchemaSquashed } from './serializer/sqliteSchema';
|
|
6
|
-
|
|
7
|
-
export const dialects = ['postgresql', 'mysql', 'sqlite', 'turso', 'singlestore'] as const;
|
|
8
|
-
export const dialect = enumType(dialects);
|
|
9
|
-
|
|
10
|
-
export type Dialect = (typeof dialects)[number];
|
|
11
|
-
const _: Dialect = '' as TypeOf<typeof dialect>;
|
|
12
|
-
|
|
13
|
-
const commonSquashedSchema = union([
|
|
14
|
-
pgSchemaSquashed,
|
|
15
|
-
mysqlSchemaSquashed,
|
|
16
|
-
SQLiteSchemaSquashed,
|
|
17
|
-
singlestoreSchemaSquashed,
|
|
18
|
-
]);
|
|
19
|
-
|
|
20
|
-
const commonSchema = union([pgSchema, mysqlSchema, sqliteSchema, singlestoreSchema]);
|
|
21
|
-
|
|
22
|
-
export type CommonSquashedSchema = TypeOf<typeof commonSquashedSchema>;
|
|
23
|
-
export type CommonSchema = TypeOf<typeof commonSchema>;
|
package/src/serializer/index.ts
DELETED
|
@@ -1,142 +0,0 @@
|
|
|
1
|
-
import chalk from 'chalk';
|
|
2
|
-
import fs from 'fs';
|
|
3
|
-
import * as glob from 'glob';
|
|
4
|
-
import Path from 'path';
|
|
5
|
-
import { CasingType } from 'src/cli/validations/common';
|
|
6
|
-
import { error } from '../cli/views';
|
|
7
|
-
import type { MySqlSchemaInternal } from './mysqlSchema';
|
|
8
|
-
import type { PgSchemaInternal } from './pgSchema';
|
|
9
|
-
import { SingleStoreSchemaInternal } from './singlestoreSchema';
|
|
10
|
-
import type { SQLiteSchemaInternal } from './sqliteSchema';
|
|
11
|
-
|
|
12
|
-
export const serializeMySql = async (
|
|
13
|
-
path: string | string[],
|
|
14
|
-
casing: CasingType | undefined,
|
|
15
|
-
): Promise<MySqlSchemaInternal> => {
|
|
16
|
-
const filenames = prepareFilenames(path);
|
|
17
|
-
|
|
18
|
-
console.log(chalk.gray(`Reading schema files:\n${filenames.join('\n')}\n`));
|
|
19
|
-
|
|
20
|
-
const { prepareFromMySqlImports } = await import('./mysqlImports');
|
|
21
|
-
const { generateMySqlSnapshot } = await import('./mysqlSerializer');
|
|
22
|
-
|
|
23
|
-
const { tables, views } = await prepareFromMySqlImports(filenames);
|
|
24
|
-
|
|
25
|
-
return generateMySqlSnapshot(tables, views, casing);
|
|
26
|
-
};
|
|
27
|
-
|
|
28
|
-
export const serializePg = async (
|
|
29
|
-
path: string | string[],
|
|
30
|
-
casing: CasingType | undefined,
|
|
31
|
-
schemaFilter?: string[],
|
|
32
|
-
): Promise<PgSchemaInternal> => {
|
|
33
|
-
const filenames = prepareFilenames(path);
|
|
34
|
-
|
|
35
|
-
const { prepareFromPgImports } = await import('./pgImports');
|
|
36
|
-
const { generatePgSnapshot } = await import('./pgSerializer');
|
|
37
|
-
|
|
38
|
-
const { tables, domains, enums, schemas, sequences, views, matViews, roles, policies } = await prepareFromPgImports(
|
|
39
|
-
filenames,
|
|
40
|
-
);
|
|
41
|
-
|
|
42
|
-
return generatePgSnapshot(
|
|
43
|
-
tables,
|
|
44
|
-
domains,
|
|
45
|
-
enums,
|
|
46
|
-
schemas,
|
|
47
|
-
sequences,
|
|
48
|
-
roles,
|
|
49
|
-
policies,
|
|
50
|
-
views,
|
|
51
|
-
matViews,
|
|
52
|
-
casing,
|
|
53
|
-
schemaFilter,
|
|
54
|
-
);
|
|
55
|
-
};
|
|
56
|
-
|
|
57
|
-
export const serializeSQLite = async (
|
|
58
|
-
path: string | string[],
|
|
59
|
-
casing: CasingType | undefined,
|
|
60
|
-
): Promise<SQLiteSchemaInternal> => {
|
|
61
|
-
const filenames = prepareFilenames(path);
|
|
62
|
-
|
|
63
|
-
const { prepareFromSqliteImports } = await import('./sqliteImports');
|
|
64
|
-
const { generateSqliteSnapshot } = await import('./sqliteSerializer');
|
|
65
|
-
const { tables, views } = await prepareFromSqliteImports(filenames);
|
|
66
|
-
return generateSqliteSnapshot(tables, views, casing);
|
|
67
|
-
};
|
|
68
|
-
|
|
69
|
-
export const serializeSingleStore = async (
|
|
70
|
-
path: string | string[],
|
|
71
|
-
casing: CasingType | undefined,
|
|
72
|
-
): Promise<SingleStoreSchemaInternal> => {
|
|
73
|
-
const filenames = prepareFilenames(path);
|
|
74
|
-
|
|
75
|
-
console.log(chalk.gray(`Reading schema files:\n${filenames.join('\n')}\n`));
|
|
76
|
-
|
|
77
|
-
const { prepareFromSingleStoreImports } = await import('./singlestoreImports');
|
|
78
|
-
const { generateSingleStoreSnapshot } = await import('./singlestoreSerializer');
|
|
79
|
-
|
|
80
|
-
const { tables /* views */ } = await prepareFromSingleStoreImports(filenames);
|
|
81
|
-
|
|
82
|
-
return generateSingleStoreSnapshot(tables, /* views, */ casing);
|
|
83
|
-
};
|
|
84
|
-
|
|
85
|
-
export const prepareFilenames = (path: string | string[]) => {
|
|
86
|
-
if (typeof path === 'string') {
|
|
87
|
-
path = [path];
|
|
88
|
-
}
|
|
89
|
-
const prefix = process.env.TEST_CONFIG_PATH_PREFIX || '';
|
|
90
|
-
|
|
91
|
-
const result = path.reduce((result, cur) => {
|
|
92
|
-
const globbed = glob.sync(`${prefix}${cur}`);
|
|
93
|
-
|
|
94
|
-
globbed.forEach((it) => {
|
|
95
|
-
const fileName = fs.lstatSync(it).isDirectory() ? null : Path.resolve(it);
|
|
96
|
-
|
|
97
|
-
const filenames = fileName
|
|
98
|
-
? [fileName!]
|
|
99
|
-
: fs.readdirSync(it).map((file) => Path.join(Path.resolve(it), file));
|
|
100
|
-
|
|
101
|
-
filenames
|
|
102
|
-
.filter((file) => !fs.lstatSync(file).isDirectory())
|
|
103
|
-
.forEach((file) => result.add(file));
|
|
104
|
-
});
|
|
105
|
-
|
|
106
|
-
return result;
|
|
107
|
-
}, new Set<string>());
|
|
108
|
-
const res = [...result];
|
|
109
|
-
|
|
110
|
-
// TODO: properly handle and test
|
|
111
|
-
const errors = res.filter((it) => {
|
|
112
|
-
return !(
|
|
113
|
-
it.endsWith('.ts')
|
|
114
|
-
|| it.endsWith('.js')
|
|
115
|
-
|| it.endsWith('.cjs')
|
|
116
|
-
|| it.endsWith('.mjs')
|
|
117
|
-
|| it.endsWith('.mts')
|
|
118
|
-
|| it.endsWith('.cts')
|
|
119
|
-
);
|
|
120
|
-
});
|
|
121
|
-
|
|
122
|
-
// when schema: "./schema" and not "./schema.ts"
|
|
123
|
-
if (res.length === 0) {
|
|
124
|
-
console.log(
|
|
125
|
-
error(
|
|
126
|
-
`No schema files found for path config [${
|
|
127
|
-
path
|
|
128
|
-
.map((it) => `'${it}'`)
|
|
129
|
-
.join(', ')
|
|
130
|
-
}]`,
|
|
131
|
-
),
|
|
132
|
-
);
|
|
133
|
-
console.log(
|
|
134
|
-
error(
|
|
135
|
-
`If path represents a file - please make sure to use .ts or other extension in the path`,
|
|
136
|
-
),
|
|
137
|
-
);
|
|
138
|
-
process.exit(1);
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
return res;
|
|
142
|
-
};
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
import { is } from 'drizzle-orm';
|
|
2
|
-
import { AnyMySqlTable, MySqlTable, MySqlView } from 'drizzle-orm/mysql-core';
|
|
3
|
-
import { safeRegister } from '../cli/commands/utils';
|
|
4
|
-
|
|
5
|
-
export const prepareFromExports = (exports: Record<string, unknown>) => {
|
|
6
|
-
const tables: AnyMySqlTable[] = [];
|
|
7
|
-
const views: MySqlView[] = [];
|
|
8
|
-
|
|
9
|
-
const i0values = Object.values(exports);
|
|
10
|
-
i0values.forEach((t) => {
|
|
11
|
-
if (is(t, MySqlTable)) {
|
|
12
|
-
tables.push(t);
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
if (is(t, MySqlView)) {
|
|
16
|
-
views.push(t);
|
|
17
|
-
}
|
|
18
|
-
});
|
|
19
|
-
|
|
20
|
-
return { tables, views };
|
|
21
|
-
};
|
|
22
|
-
|
|
23
|
-
export const prepareFromMySqlImports = async (imports: string[]) => {
|
|
24
|
-
const tables: AnyMySqlTable[] = [];
|
|
25
|
-
const views: MySqlView[] = [];
|
|
26
|
-
|
|
27
|
-
const { unregister } = await safeRegister();
|
|
28
|
-
for (let i = 0; i < imports.length; i++) {
|
|
29
|
-
const it = imports[i];
|
|
30
|
-
const i0: Record<string, unknown> = require(`${it}`);
|
|
31
|
-
const prepared = prepareFromExports(i0);
|
|
32
|
-
|
|
33
|
-
tables.push(...prepared.tables);
|
|
34
|
-
views.push(...prepared.views);
|
|
35
|
-
}
|
|
36
|
-
unregister();
|
|
37
|
-
return { tables: Array.from(new Set(tables)), views };
|
|
38
|
-
};
|