@anthonyalayo/drizzle-kit 1.0.2 → 1.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/api.d.mts +2891 -0
- package/api.d.ts +2891 -0
- package/api.js +47534 -0
- package/api.mjs +47521 -0
- package/bin.cjs +80043 -0
- package/{src/index.ts → index-Z-1TKnbX.d.mts} +123 -141
- package/index-Z-1TKnbX.d.ts +308 -0
- package/index.d.mts +2 -0
- package/index.d.ts +2 -0
- package/index.js +32 -0
- package/index.mjs +7 -0
- package/package.json +2 -2
- package/utils.js +6056 -0
- package/utils.mjs +6032 -0
- package/.gitignore +0 -25
- package/build.dev.ts +0 -51
- package/build.ts +0 -112
- package/imports-checker/analyze.ts +0 -78
- package/imports-checker/checker.ts +0 -296
- package/imports-checker/grammar/grammar.ohm +0 -121
- package/imports-checker/grammar/grammar.ohm-bundle.d.ts +0 -164
- package/imports-checker/grammar/grammar.ohm-bundle.js +0 -753
- package/imports-checker/index.ts +0 -48
- package/patches/difflib@0.2.4.patch +0 -31
- package/src/@types/utils.ts +0 -58
- package/src/api.ts +0 -504
- package/src/cli/commands/_es5.ts +0 -2
- package/src/cli/commands/check.ts +0 -52
- package/src/cli/commands/drop.ts +0 -60
- package/src/cli/commands/introspect.ts +0 -772
- package/src/cli/commands/libSqlPushUtils.ts +0 -355
- package/src/cli/commands/migrate.ts +0 -1526
- package/src/cli/commands/mysqlIntrospect.ts +0 -53
- package/src/cli/commands/mysqlPushUtils.ts +0 -352
- package/src/cli/commands/mysqlUp.ts +0 -102
- package/src/cli/commands/pgIntrospect.ts +0 -55
- package/src/cli/commands/pgPushUtils.ts +0 -269
- package/src/cli/commands/pgUp.ts +0 -217
- package/src/cli/commands/push.ts +0 -637
- package/src/cli/commands/singlestoreIntrospect.ts +0 -53
- package/src/cli/commands/singlestorePushUtils.ts +0 -456
- package/src/cli/commands/singlestoreUp.ts +0 -1
- package/src/cli/commands/sqliteIntrospect.ts +0 -96
- package/src/cli/commands/sqlitePushUtils.ts +0 -322
- package/src/cli/commands/sqliteUp.ts +0 -52
- package/src/cli/commands/utils.ts +0 -858
- package/src/cli/connections.ts +0 -914
- package/src/cli/index.ts +0 -48
- package/src/cli/schema.ts +0 -794
- package/src/cli/selector-ui.ts +0 -38
- package/src/cli/utils.ts +0 -112
- package/src/cli/validations/cli.ts +0 -79
- package/src/cli/validations/common.ts +0 -193
- package/src/cli/validations/libsql.ts +0 -27
- package/src/cli/validations/mysql.ts +0 -61
- package/src/cli/validations/outputs.ts +0 -91
- package/src/cli/validations/postgres.ts +0 -83
- package/src/cli/validations/singlestore.ts +0 -61
- package/src/cli/validations/sqlite.ts +0 -104
- package/src/cli/validations/studio.ts +0 -24
- package/src/cli/views.ts +0 -658
- package/src/extensions/getTablesFilterByExtensions.ts +0 -16
- package/src/extensions/vector.ts +0 -10
- package/src/global.ts +0 -61
- package/src/introspect-mysql.ts +0 -1030
- package/src/introspect-pg.ts +0 -1435
- package/src/introspect-singlestore.ts +0 -913
- package/src/introspect-sqlite.ts +0 -533
- package/src/jsonDiffer.js +0 -882
- package/src/jsonStatements.ts +0 -3590
- package/src/loader.mjs +0 -57
- package/src/migrationPreparator.ts +0 -217
- package/src/schemaValidator.ts +0 -23
- package/src/serializer/index.ts +0 -142
- package/src/serializer/mysqlImports.ts +0 -38
- package/src/serializer/mysqlSchema.ts +0 -423
- package/src/serializer/mysqlSerializer.ts +0 -999
- package/src/serializer/pgImports.ts +0 -106
- package/src/serializer/pgSchema.ts +0 -937
- package/src/serializer/pgSerializer.ts +0 -2223
- package/src/serializer/singlestoreImports.ts +0 -38
- package/src/serializer/singlestoreSchema.ts +0 -257
- package/src/serializer/singlestoreSerializer.ts +0 -767
- package/src/serializer/sqliteImports.ts +0 -41
- package/src/serializer/sqliteSchema.ts +0 -352
- package/src/serializer/sqliteSerializer.ts +0 -931
- package/src/serializer/studio.ts +0 -694
- package/src/serializer/utils.ts +0 -45
- package/src/simulator.ts +0 -157
- package/src/snapshotsDiffer.ts +0 -4398
- package/src/sqlgenerator.ts +0 -4212
- package/src/statementCombiner.ts +0 -597
- package/src/utils/certs.ts +0 -44
- package/src/utils/words.ts +0 -1333
- package/src/utils.ts +0 -370
- package/tests/bin.test.ts +0 -58
- package/tests/cli/d1http.config.ts +0 -12
- package/tests/cli/drizzle.config.ts +0 -9
- package/tests/cli/durable-sqlite.config.ts +0 -7
- package/tests/cli/expo.config.ts +0 -7
- package/tests/cli/postgres.config.ts +0 -13
- package/tests/cli/postgres2.config.ts +0 -17
- package/tests/cli/schema.ts +0 -1
- package/tests/cli/turso.config.ts +0 -10
- package/tests/cli-export.test.ts +0 -79
- package/tests/cli-generate.test.ts +0 -259
- package/tests/cli-migrate.test.ts +0 -103
- package/tests/cli-push.test.ts +0 -126
- package/tests/common.ts +0 -15
- package/tests/indexes/common.ts +0 -21
- package/tests/indexes/pg.test.ts +0 -245
- package/tests/introspect/libsql.test.ts +0 -35
- package/tests/introspect/mysql.test.ts +0 -319
- package/tests/introspect/pg.test.ts +0 -894
- package/tests/introspect/singlestore.test.ts +0 -275
- package/tests/introspect/sqlite.test.ts +0 -122
- package/tests/libsql-checks.test.ts +0 -308
- package/tests/libsql-statements.test.ts +0 -989
- package/tests/libsql-views.test.ts +0 -218
- package/tests/migrate/libsq-schema.ts +0 -6
- package/tests/migrate/libsql-migrate.test.ts +0 -58
- package/tests/migrate/migrations/0000_little_blizzard.sql +0 -4
- package/tests/migrate/migrations/0001_nebulous_storm.sql +0 -10
- package/tests/migrate/migrations/meta/0000_snapshot.json +0 -40
- package/tests/migrate/migrations/meta/0001_snapshot.json +0 -40
- package/tests/migrate/migrations/meta/_journal.json +0 -20
- package/tests/mysql-checks.test.ts +0 -291
- package/tests/mysql-generated.test.ts +0 -1290
- package/tests/mysql-schemas.test.ts +0 -156
- package/tests/mysql-views.test.ts +0 -553
- package/tests/mysql.test.ts +0 -863
- package/tests/pg-array.test.ts +0 -368
- package/tests/pg-checks.test.ts +0 -329
- package/tests/pg-columns.test.ts +0 -484
- package/tests/pg-domains.test.ts +0 -306
- package/tests/pg-enums.test.ts +0 -751
- package/tests/pg-generated.test.ts +0 -529
- package/tests/pg-identity.test.ts +0 -447
- package/tests/pg-schemas.test.ts +0 -105
- package/tests/pg-sequences.test.ts +0 -298
- package/tests/pg-tables.test.ts +0 -1021
- package/tests/pg-views.test.ts +0 -1929
- package/tests/push/common.ts +0 -58
- package/tests/push/libsql.test.ts +0 -1400
- package/tests/push/mysql-push.test.ts +0 -345
- package/tests/push/mysql.test.ts +0 -788
- package/tests/push/pg.test.ts +0 -4341
- package/tests/push/singlestore-push.test.ts +0 -894
- package/tests/push/singlestore.test.ts +0 -444
- package/tests/push/sqlite.test.ts +0 -1613
- package/tests/rls/pg-policy.test.ts +0 -1656
- package/tests/rls/pg-role.test.ts +0 -234
- package/tests/schemaDiffer.ts +0 -2852
- package/tests/singlestore-generated.test.ts +0 -1290
- package/tests/singlestore-schemas.test.ts +0 -155
- package/tests/singlestore.test.ts +0 -978
- package/tests/sqlite-checks.test.ts +0 -308
- package/tests/sqlite-columns.test.ts +0 -1049
- package/tests/sqlite-generated.test.ts +0 -1726
- package/tests/sqlite-tables.test.ts +0 -637
- package/tests/sqlite-views.test.ts +0 -218
- package/tests/statements-combiner/libsql-statements-combiner.test.ts +0 -1812
- package/tests/statements-combiner/singlestore-statements-combiner.test.ts +0 -882
- package/tests/statements-combiner/sqlite-statements-combiner.test.ts +0 -1211
- package/tests/test/sqlite.test.ts +0 -39
- package/tests/testsinglestore.ts +0 -29
- package/tests/validations.test.ts +0 -869
- package/tests/wrap-param.test.ts +0 -16
- package/tsconfig.build.json +0 -4
- package/tsconfig.cli-types.json +0 -9
- package/tsconfig.json +0 -28
- package/vitest.config.ts +0 -34
|
@@ -1,156 +0,0 @@
|
|
|
1
|
-
import { mysqlSchema, mysqlTable } from 'drizzle-orm/mysql-core';
|
|
2
|
-
import { expect, test } from 'vitest';
|
|
3
|
-
import { diffTestSchemasMysql } from './schemaDiffer';
|
|
4
|
-
|
|
5
|
-
// We don't manage databases(schemas) in MySQL with Drizzle Kit
|
|
6
|
-
test('add schema #1', async () => {
|
|
7
|
-
const to = {
|
|
8
|
-
devSchema: mysqlSchema('dev'),
|
|
9
|
-
};
|
|
10
|
-
|
|
11
|
-
const { statements } = await diffTestSchemasMysql({}, to, []);
|
|
12
|
-
|
|
13
|
-
expect(statements.length).toBe(0);
|
|
14
|
-
});
|
|
15
|
-
|
|
16
|
-
test('add schema #2', async () => {
|
|
17
|
-
const from = {
|
|
18
|
-
devSchema: mysqlSchema('dev'),
|
|
19
|
-
};
|
|
20
|
-
const to = {
|
|
21
|
-
devSchema: mysqlSchema('dev'),
|
|
22
|
-
devSchema2: mysqlSchema('dev2'),
|
|
23
|
-
};
|
|
24
|
-
|
|
25
|
-
const { statements } = await diffTestSchemasMysql(from, to, []);
|
|
26
|
-
|
|
27
|
-
expect(statements.length).toBe(0);
|
|
28
|
-
});
|
|
29
|
-
|
|
30
|
-
test('delete schema #1', async () => {
|
|
31
|
-
const from = {
|
|
32
|
-
devSchema: mysqlSchema('dev'),
|
|
33
|
-
};
|
|
34
|
-
|
|
35
|
-
const { statements } = await diffTestSchemasMysql(from, {}, []);
|
|
36
|
-
|
|
37
|
-
expect(statements.length).toBe(0);
|
|
38
|
-
});
|
|
39
|
-
|
|
40
|
-
test('delete schema #2', async () => {
|
|
41
|
-
const from = {
|
|
42
|
-
devSchema: mysqlSchema('dev'),
|
|
43
|
-
devSchema2: mysqlSchema('dev2'),
|
|
44
|
-
};
|
|
45
|
-
const to = {
|
|
46
|
-
devSchema: mysqlSchema('dev'),
|
|
47
|
-
};
|
|
48
|
-
|
|
49
|
-
const { statements } = await diffTestSchemasMysql(from, to, []);
|
|
50
|
-
|
|
51
|
-
expect(statements.length).toBe(0);
|
|
52
|
-
});
|
|
53
|
-
|
|
54
|
-
test('rename schema #1', async () => {
|
|
55
|
-
const from = {
|
|
56
|
-
devSchema: mysqlSchema('dev'),
|
|
57
|
-
};
|
|
58
|
-
const to = {
|
|
59
|
-
devSchema2: mysqlSchema('dev2'),
|
|
60
|
-
};
|
|
61
|
-
|
|
62
|
-
const { statements } = await diffTestSchemasMysql(from, to, ['dev->dev2']);
|
|
63
|
-
|
|
64
|
-
expect(statements.length).toBe(0);
|
|
65
|
-
});
|
|
66
|
-
|
|
67
|
-
test('rename schema #2', async () => {
|
|
68
|
-
const from = {
|
|
69
|
-
devSchema: mysqlSchema('dev'),
|
|
70
|
-
devSchema1: mysqlSchema('dev1'),
|
|
71
|
-
};
|
|
72
|
-
const to = {
|
|
73
|
-
devSchema: mysqlSchema('dev'),
|
|
74
|
-
devSchema2: mysqlSchema('dev2'),
|
|
75
|
-
};
|
|
76
|
-
|
|
77
|
-
const { statements } = await diffTestSchemasMysql(from, to, ['dev1->dev2']);
|
|
78
|
-
|
|
79
|
-
expect(statements.length).toBe(0);
|
|
80
|
-
});
|
|
81
|
-
|
|
82
|
-
test('add table to schema #1', async () => {
|
|
83
|
-
const dev = mysqlSchema('dev');
|
|
84
|
-
const from = {};
|
|
85
|
-
const to = {
|
|
86
|
-
dev,
|
|
87
|
-
users: dev.table('users', {}),
|
|
88
|
-
};
|
|
89
|
-
|
|
90
|
-
const { statements } = await diffTestSchemasMysql(from, to, ['dev1->dev2']);
|
|
91
|
-
|
|
92
|
-
expect(statements.length).toBe(0);
|
|
93
|
-
});
|
|
94
|
-
|
|
95
|
-
test('add table to schema #2', async () => {
|
|
96
|
-
const dev = mysqlSchema('dev');
|
|
97
|
-
const from = { dev };
|
|
98
|
-
const to = {
|
|
99
|
-
dev,
|
|
100
|
-
users: dev.table('users', {}),
|
|
101
|
-
};
|
|
102
|
-
|
|
103
|
-
const { statements } = await diffTestSchemasMysql(from, to, ['dev1->dev2']);
|
|
104
|
-
|
|
105
|
-
expect(statements.length).toBe(0);
|
|
106
|
-
});
|
|
107
|
-
|
|
108
|
-
test('add table to schema #3', async () => {
|
|
109
|
-
const dev = mysqlSchema('dev');
|
|
110
|
-
const from = { dev };
|
|
111
|
-
const to = {
|
|
112
|
-
dev,
|
|
113
|
-
usersInDev: dev.table('users', {}),
|
|
114
|
-
users: mysqlTable('users', {}),
|
|
115
|
-
};
|
|
116
|
-
|
|
117
|
-
const { statements } = await diffTestSchemasMysql(from, to, ['dev1->dev2']);
|
|
118
|
-
|
|
119
|
-
expect(statements.length).toBe(1);
|
|
120
|
-
expect(statements[0]).toStrictEqual({
|
|
121
|
-
type: 'create_table',
|
|
122
|
-
tableName: 'users',
|
|
123
|
-
schema: undefined,
|
|
124
|
-
columns: [],
|
|
125
|
-
uniqueConstraints: [],
|
|
126
|
-
internals: {
|
|
127
|
-
tables: {},
|
|
128
|
-
indexes: {},
|
|
129
|
-
},
|
|
130
|
-
compositePkName: '',
|
|
131
|
-
compositePKs: [],
|
|
132
|
-
checkConstraints: [],
|
|
133
|
-
});
|
|
134
|
-
});
|
|
135
|
-
|
|
136
|
-
test('remove table from schema #1', async () => {
|
|
137
|
-
const dev = mysqlSchema('dev');
|
|
138
|
-
const from = { dev, users: dev.table('users', {}) };
|
|
139
|
-
const to = {
|
|
140
|
-
dev,
|
|
141
|
-
};
|
|
142
|
-
|
|
143
|
-
const { statements } = await diffTestSchemasMysql(from, to, ['dev1->dev2']);
|
|
144
|
-
|
|
145
|
-
expect(statements.length).toBe(0);
|
|
146
|
-
});
|
|
147
|
-
|
|
148
|
-
test('remove table from schema #2', async () => {
|
|
149
|
-
const dev = mysqlSchema('dev');
|
|
150
|
-
const from = { dev, users: dev.table('users', {}) };
|
|
151
|
-
const to = {};
|
|
152
|
-
|
|
153
|
-
const { statements } = await diffTestSchemasMysql(from, to, ['dev1->dev2']);
|
|
154
|
-
|
|
155
|
-
expect(statements.length).toBe(0);
|
|
156
|
-
});
|
|
@@ -1,553 +0,0 @@
|
|
|
1
|
-
import { sql } from 'drizzle-orm';
|
|
2
|
-
import { int, mysqlTable, mysqlView } from 'drizzle-orm/mysql-core';
|
|
3
|
-
import { expect, test } from 'vitest';
|
|
4
|
-
import { diffTestSchemasMysql } from './schemaDiffer';
|
|
5
|
-
|
|
6
|
-
test('create view #1', async () => {
|
|
7
|
-
const users = mysqlTable('users', {
|
|
8
|
-
id: int('id').primaryKey().notNull(),
|
|
9
|
-
});
|
|
10
|
-
|
|
11
|
-
const from = {
|
|
12
|
-
users: users,
|
|
13
|
-
};
|
|
14
|
-
const to = {
|
|
15
|
-
users: users,
|
|
16
|
-
view: mysqlView('some_view').as((qb) => qb.select().from(users)),
|
|
17
|
-
};
|
|
18
|
-
|
|
19
|
-
const { statements, sqlStatements } = await diffTestSchemasMysql(from, to, []);
|
|
20
|
-
|
|
21
|
-
expect(statements.length).toBe(1);
|
|
22
|
-
expect(statements[0]).toStrictEqual({
|
|
23
|
-
type: 'mysql_create_view',
|
|
24
|
-
name: 'some_view',
|
|
25
|
-
algorithm: 'undefined',
|
|
26
|
-
replace: false,
|
|
27
|
-
definition: 'select `id` from `users`',
|
|
28
|
-
withCheckOption: undefined,
|
|
29
|
-
sqlSecurity: 'definer',
|
|
30
|
-
});
|
|
31
|
-
|
|
32
|
-
expect(sqlStatements.length).toBe(1);
|
|
33
|
-
expect(sqlStatements[0]).toBe(`CREATE ALGORITHM = undefined
|
|
34
|
-
SQL SECURITY definer
|
|
35
|
-
VIEW \`some_view\` AS (select \`id\` from \`users\`);`);
|
|
36
|
-
});
|
|
37
|
-
|
|
38
|
-
test('create view #2', async () => {
|
|
39
|
-
const users = mysqlTable('users', {
|
|
40
|
-
id: int('id').primaryKey().notNull(),
|
|
41
|
-
});
|
|
42
|
-
|
|
43
|
-
const from = {
|
|
44
|
-
users: users,
|
|
45
|
-
};
|
|
46
|
-
const to = {
|
|
47
|
-
users: users,
|
|
48
|
-
view: mysqlView('some_view', {}).algorithm('merge').sqlSecurity('definer')
|
|
49
|
-
.withCheckOption('cascaded').as(sql`SELECT * FROM ${users}`),
|
|
50
|
-
};
|
|
51
|
-
|
|
52
|
-
const { statements, sqlStatements } = await diffTestSchemasMysql(from, to, []);
|
|
53
|
-
|
|
54
|
-
expect(statements.length).toBe(1);
|
|
55
|
-
expect(statements[0]).toStrictEqual({
|
|
56
|
-
type: 'mysql_create_view',
|
|
57
|
-
name: 'some_view',
|
|
58
|
-
algorithm: 'merge',
|
|
59
|
-
replace: false,
|
|
60
|
-
definition: 'SELECT * FROM \`users\`',
|
|
61
|
-
withCheckOption: 'cascaded',
|
|
62
|
-
sqlSecurity: 'definer',
|
|
63
|
-
});
|
|
64
|
-
|
|
65
|
-
expect(sqlStatements.length).toBe(1);
|
|
66
|
-
expect(sqlStatements[0]).toBe(`CREATE ALGORITHM = merge
|
|
67
|
-
SQL SECURITY definer
|
|
68
|
-
VIEW \`some_view\` AS (SELECT * FROM \`users\`)
|
|
69
|
-
WITH cascaded CHECK OPTION;`);
|
|
70
|
-
});
|
|
71
|
-
|
|
72
|
-
test('create view with existing flag', async () => {
|
|
73
|
-
const users = mysqlTable('users', {
|
|
74
|
-
id: int('id').primaryKey().notNull(),
|
|
75
|
-
});
|
|
76
|
-
|
|
77
|
-
const from = {
|
|
78
|
-
users: users,
|
|
79
|
-
};
|
|
80
|
-
const to = {
|
|
81
|
-
users: users,
|
|
82
|
-
view: mysqlView('some_view', {}).existing(),
|
|
83
|
-
};
|
|
84
|
-
|
|
85
|
-
const { statements, sqlStatements } = await diffTestSchemasMysql(from, to, []);
|
|
86
|
-
|
|
87
|
-
expect(statements.length).toBe(0);
|
|
88
|
-
expect(sqlStatements.length).toBe(0);
|
|
89
|
-
});
|
|
90
|
-
|
|
91
|
-
test('drop view', async () => {
|
|
92
|
-
const users = mysqlTable('users', {
|
|
93
|
-
id: int('id').primaryKey().notNull(),
|
|
94
|
-
});
|
|
95
|
-
|
|
96
|
-
const from = {
|
|
97
|
-
users: users,
|
|
98
|
-
view: mysqlView('some_view', {}).algorithm('merge').sqlSecurity('definer')
|
|
99
|
-
.withCheckOption('cascaded').as(sql`SELECT * FROM ${users}`),
|
|
100
|
-
};
|
|
101
|
-
const to = {
|
|
102
|
-
users: users,
|
|
103
|
-
};
|
|
104
|
-
|
|
105
|
-
const { statements, sqlStatements } = await diffTestSchemasMysql(from, to, []);
|
|
106
|
-
|
|
107
|
-
expect(statements.length).toBe(1);
|
|
108
|
-
expect(statements[0]).toStrictEqual({
|
|
109
|
-
type: 'drop_view',
|
|
110
|
-
name: 'some_view',
|
|
111
|
-
});
|
|
112
|
-
|
|
113
|
-
expect(sqlStatements.length).toBe(1);
|
|
114
|
-
expect(sqlStatements[0]).toBe(`DROP VIEW \`some_view\`;`);
|
|
115
|
-
});
|
|
116
|
-
|
|
117
|
-
test('drop view with existing flag', async () => {
|
|
118
|
-
const users = mysqlTable('users', {
|
|
119
|
-
id: int('id').primaryKey().notNull(),
|
|
120
|
-
});
|
|
121
|
-
|
|
122
|
-
const from = {
|
|
123
|
-
users: users,
|
|
124
|
-
view: mysqlView('some_view', {}).algorithm('merge').sqlSecurity('definer')
|
|
125
|
-
.withCheckOption('cascaded').existing(),
|
|
126
|
-
};
|
|
127
|
-
const to = {
|
|
128
|
-
users: users,
|
|
129
|
-
};
|
|
130
|
-
|
|
131
|
-
const { statements, sqlStatements } = await diffTestSchemasMysql(from, to, []);
|
|
132
|
-
|
|
133
|
-
expect(statements.length).toBe(0);
|
|
134
|
-
expect(sqlStatements.length).toBe(0);
|
|
135
|
-
});
|
|
136
|
-
|
|
137
|
-
test('rename view', async () => {
|
|
138
|
-
const users = mysqlTable('users', {
|
|
139
|
-
id: int('id').primaryKey().notNull(),
|
|
140
|
-
});
|
|
141
|
-
|
|
142
|
-
const from = {
|
|
143
|
-
users: users,
|
|
144
|
-
view: mysqlView('some_view', {}).algorithm('merge').sqlSecurity('definer')
|
|
145
|
-
.withCheckOption('cascaded').as(sql`SELECT * FROM ${users}`),
|
|
146
|
-
};
|
|
147
|
-
const to = {
|
|
148
|
-
users: users,
|
|
149
|
-
view: mysqlView('new_some_view', {}).algorithm('merge').sqlSecurity('definer')
|
|
150
|
-
.withCheckOption('cascaded').as(sql`SELECT * FROM ${users}`),
|
|
151
|
-
};
|
|
152
|
-
|
|
153
|
-
const { statements, sqlStatements } = await diffTestSchemasMysql(from, to, [
|
|
154
|
-
'public.some_view->public.new_some_view',
|
|
155
|
-
]);
|
|
156
|
-
|
|
157
|
-
expect(statements.length).toBe(1);
|
|
158
|
-
expect(statements[0]).toStrictEqual({
|
|
159
|
-
type: 'rename_view',
|
|
160
|
-
nameFrom: 'some_view',
|
|
161
|
-
nameTo: 'new_some_view',
|
|
162
|
-
});
|
|
163
|
-
expect(sqlStatements.length).toBe(1);
|
|
164
|
-
expect(sqlStatements[0]).toBe(`RENAME TABLE \`some_view\` TO \`new_some_view\`;`);
|
|
165
|
-
});
|
|
166
|
-
|
|
167
|
-
test('rename view and alter meta options', async () => {
|
|
168
|
-
const users = mysqlTable('users', {
|
|
169
|
-
id: int('id').primaryKey().notNull(),
|
|
170
|
-
});
|
|
171
|
-
|
|
172
|
-
const from = {
|
|
173
|
-
users: users,
|
|
174
|
-
view: mysqlView('some_view', {}).algorithm('merge').sqlSecurity('definer')
|
|
175
|
-
.withCheckOption('cascaded').as(sql`SELECT * FROM ${users}`),
|
|
176
|
-
};
|
|
177
|
-
const to = {
|
|
178
|
-
users: users,
|
|
179
|
-
view: mysqlView('new_some_view', {}).sqlSecurity('definer')
|
|
180
|
-
.withCheckOption('cascaded').as(sql`SELECT * FROM ${users}`),
|
|
181
|
-
};
|
|
182
|
-
|
|
183
|
-
const { statements, sqlStatements } = await diffTestSchemasMysql(from, to, [
|
|
184
|
-
'public.some_view->public.new_some_view',
|
|
185
|
-
]);
|
|
186
|
-
|
|
187
|
-
expect(statements.length).toBe(2);
|
|
188
|
-
expect(statements[0]).toStrictEqual({
|
|
189
|
-
type: 'rename_view',
|
|
190
|
-
nameFrom: 'some_view',
|
|
191
|
-
nameTo: 'new_some_view',
|
|
192
|
-
});
|
|
193
|
-
expect(statements[1]).toStrictEqual({
|
|
194
|
-
algorithm: 'undefined',
|
|
195
|
-
columns: {},
|
|
196
|
-
definition: 'SELECT * FROM `users`',
|
|
197
|
-
isExisting: false,
|
|
198
|
-
name: 'new_some_view',
|
|
199
|
-
sqlSecurity: 'definer',
|
|
200
|
-
type: 'alter_mysql_view',
|
|
201
|
-
withCheckOption: 'cascaded',
|
|
202
|
-
});
|
|
203
|
-
expect(sqlStatements.length).toBe(2);
|
|
204
|
-
expect(sqlStatements[0]).toBe(`RENAME TABLE \`some_view\` TO \`new_some_view\`;`);
|
|
205
|
-
expect(sqlStatements[1]).toBe(`ALTER ALGORITHM = undefined
|
|
206
|
-
SQL SECURITY definer
|
|
207
|
-
VIEW \`new_some_view\` AS SELECT * FROM \`users\`
|
|
208
|
-
WITH cascaded CHECK OPTION;`);
|
|
209
|
-
});
|
|
210
|
-
|
|
211
|
-
test('rename view with existing flag', async () => {
|
|
212
|
-
const users = mysqlTable('users', {
|
|
213
|
-
id: int('id').primaryKey().notNull(),
|
|
214
|
-
});
|
|
215
|
-
|
|
216
|
-
const from = {
|
|
217
|
-
users: users,
|
|
218
|
-
view: mysqlView('some_view', {}).algorithm('merge').sqlSecurity('definer')
|
|
219
|
-
.withCheckOption('cascaded').existing(),
|
|
220
|
-
};
|
|
221
|
-
const to = {
|
|
222
|
-
users: users,
|
|
223
|
-
view: mysqlView('new_some_view', {}).algorithm('merge').sqlSecurity('definer')
|
|
224
|
-
.withCheckOption('cascaded').existing(),
|
|
225
|
-
};
|
|
226
|
-
|
|
227
|
-
const { statements, sqlStatements } = await diffTestSchemasMysql(from, to, [
|
|
228
|
-
'public.some_view->public.new_some_view',
|
|
229
|
-
]);
|
|
230
|
-
|
|
231
|
-
expect(statements.length).toBe(0);
|
|
232
|
-
expect(sqlStatements.length).toBe(0);
|
|
233
|
-
});
|
|
234
|
-
|
|
235
|
-
test('add meta to view', async () => {
|
|
236
|
-
const users = mysqlTable('users', {
|
|
237
|
-
id: int('id').primaryKey().notNull(),
|
|
238
|
-
});
|
|
239
|
-
|
|
240
|
-
const from = {
|
|
241
|
-
users: users,
|
|
242
|
-
view: mysqlView('some_view', {}).as(sql`SELECT * FROM ${users}`),
|
|
243
|
-
};
|
|
244
|
-
const to = {
|
|
245
|
-
users: users,
|
|
246
|
-
view: mysqlView('some_view', {}).algorithm('merge').sqlSecurity('definer')
|
|
247
|
-
.withCheckOption('cascaded').as(sql`SELECT * FROM ${users}`),
|
|
248
|
-
};
|
|
249
|
-
|
|
250
|
-
const { statements, sqlStatements } = await diffTestSchemasMysql(from, to, []);
|
|
251
|
-
|
|
252
|
-
expect(statements.length).toBe(1);
|
|
253
|
-
expect(statements[0]).toStrictEqual({
|
|
254
|
-
algorithm: 'merge',
|
|
255
|
-
columns: {},
|
|
256
|
-
definition: 'SELECT * FROM `users`',
|
|
257
|
-
isExisting: false,
|
|
258
|
-
name: 'some_view',
|
|
259
|
-
sqlSecurity: 'definer',
|
|
260
|
-
type: 'alter_mysql_view',
|
|
261
|
-
withCheckOption: 'cascaded',
|
|
262
|
-
});
|
|
263
|
-
|
|
264
|
-
expect(sqlStatements.length).toBe(1);
|
|
265
|
-
expect(sqlStatements[0]).toBe(`ALTER ALGORITHM = merge
|
|
266
|
-
SQL SECURITY definer
|
|
267
|
-
VIEW \`some_view\` AS SELECT * FROM \`users\`
|
|
268
|
-
WITH cascaded CHECK OPTION;`);
|
|
269
|
-
});
|
|
270
|
-
|
|
271
|
-
test('add meta to view with existing flag', async () => {
|
|
272
|
-
const users = mysqlTable('users', {
|
|
273
|
-
id: int('id').primaryKey().notNull(),
|
|
274
|
-
});
|
|
275
|
-
|
|
276
|
-
const from = {
|
|
277
|
-
users: users,
|
|
278
|
-
view: mysqlView('some_view', {}).existing(),
|
|
279
|
-
};
|
|
280
|
-
const to = {
|
|
281
|
-
users: users,
|
|
282
|
-
view: mysqlView('some_view', {}).algorithm('merge').sqlSecurity('definer')
|
|
283
|
-
.withCheckOption('cascaded').existing(),
|
|
284
|
-
};
|
|
285
|
-
|
|
286
|
-
const { statements, sqlStatements } = await diffTestSchemasMysql(from, to, []);
|
|
287
|
-
|
|
288
|
-
expect(statements.length).toBe(0);
|
|
289
|
-
expect(sqlStatements.length).toBe(0);
|
|
290
|
-
});
|
|
291
|
-
|
|
292
|
-
test('alter meta to view', async () => {
|
|
293
|
-
const users = mysqlTable('users', {
|
|
294
|
-
id: int('id').primaryKey().notNull(),
|
|
295
|
-
});
|
|
296
|
-
|
|
297
|
-
const from = {
|
|
298
|
-
users: users,
|
|
299
|
-
view: mysqlView('some_view', {}).algorithm('temptable').sqlSecurity('invoker')
|
|
300
|
-
.withCheckOption('cascaded').as(sql`SELECT * FROM ${users}`),
|
|
301
|
-
};
|
|
302
|
-
const to = {
|
|
303
|
-
users: users,
|
|
304
|
-
view: mysqlView('some_view', {}).algorithm('merge').sqlSecurity('definer')
|
|
305
|
-
.withCheckOption('cascaded').as(sql`SELECT * FROM ${users}`),
|
|
306
|
-
};
|
|
307
|
-
|
|
308
|
-
const { statements, sqlStatements } = await diffTestSchemasMysql(from, to, []);
|
|
309
|
-
|
|
310
|
-
expect(statements.length).toBe(1);
|
|
311
|
-
expect(statements[0]).toStrictEqual({
|
|
312
|
-
algorithm: 'merge',
|
|
313
|
-
columns: {},
|
|
314
|
-
definition: 'SELECT * FROM `users`',
|
|
315
|
-
isExisting: false,
|
|
316
|
-
name: 'some_view',
|
|
317
|
-
sqlSecurity: 'definer',
|
|
318
|
-
type: 'alter_mysql_view',
|
|
319
|
-
withCheckOption: 'cascaded',
|
|
320
|
-
});
|
|
321
|
-
|
|
322
|
-
expect(sqlStatements.length).toBe(1);
|
|
323
|
-
expect(sqlStatements[0]).toBe(`ALTER ALGORITHM = merge
|
|
324
|
-
SQL SECURITY definer
|
|
325
|
-
VIEW \`some_view\` AS SELECT * FROM \`users\`
|
|
326
|
-
WITH cascaded CHECK OPTION;`);
|
|
327
|
-
});
|
|
328
|
-
|
|
329
|
-
test('alter meta to view with existing flag', async () => {
|
|
330
|
-
const users = mysqlTable('users', {
|
|
331
|
-
id: int('id').primaryKey().notNull(),
|
|
332
|
-
});
|
|
333
|
-
|
|
334
|
-
const from = {
|
|
335
|
-
users: users,
|
|
336
|
-
view: mysqlView('some_view', {}).algorithm('temptable').sqlSecurity('invoker')
|
|
337
|
-
.withCheckOption('cascaded').existing(),
|
|
338
|
-
};
|
|
339
|
-
const to = {
|
|
340
|
-
users: users,
|
|
341
|
-
view: mysqlView('some_view', {}).algorithm('merge').sqlSecurity('definer')
|
|
342
|
-
.withCheckOption('cascaded').existing(),
|
|
343
|
-
};
|
|
344
|
-
|
|
345
|
-
const { statements, sqlStatements } = await diffTestSchemasMysql(from, to, []);
|
|
346
|
-
|
|
347
|
-
expect(statements.length).toBe(0);
|
|
348
|
-
expect(sqlStatements.length).toBe(0);
|
|
349
|
-
});
|
|
350
|
-
|
|
351
|
-
test('drop meta from view', async () => {
|
|
352
|
-
const users = mysqlTable('users', {
|
|
353
|
-
id: int('id').primaryKey().notNull(),
|
|
354
|
-
});
|
|
355
|
-
|
|
356
|
-
const from = {
|
|
357
|
-
users: users,
|
|
358
|
-
view: mysqlView('some_view', {}).algorithm('merge').sqlSecurity('definer')
|
|
359
|
-
.withCheckOption('cascaded').as(sql`SELECT * FROM ${users}`),
|
|
360
|
-
};
|
|
361
|
-
const to = {
|
|
362
|
-
users: users,
|
|
363
|
-
view: mysqlView('some_view', {}).as(sql`SELECT * FROM ${users}`),
|
|
364
|
-
};
|
|
365
|
-
|
|
366
|
-
const { statements, sqlStatements } = await diffTestSchemasMysql(from, to, []);
|
|
367
|
-
|
|
368
|
-
expect(statements.length).toBe(1);
|
|
369
|
-
expect(statements[0]).toStrictEqual({
|
|
370
|
-
algorithm: 'undefined',
|
|
371
|
-
columns: {},
|
|
372
|
-
definition: 'SELECT * FROM `users`',
|
|
373
|
-
isExisting: false,
|
|
374
|
-
name: 'some_view',
|
|
375
|
-
sqlSecurity: 'definer',
|
|
376
|
-
type: 'alter_mysql_view',
|
|
377
|
-
withCheckOption: undefined,
|
|
378
|
-
});
|
|
379
|
-
|
|
380
|
-
expect(sqlStatements.length).toBe(1);
|
|
381
|
-
expect(sqlStatements[0]).toBe(`ALTER ALGORITHM = undefined
|
|
382
|
-
SQL SECURITY definer
|
|
383
|
-
VIEW \`some_view\` AS SELECT * FROM \`users\`;`);
|
|
384
|
-
});
|
|
385
|
-
|
|
386
|
-
test('drop meta from view existing flag', async () => {
|
|
387
|
-
const users = mysqlTable('users', {
|
|
388
|
-
id: int('id').primaryKey().notNull(),
|
|
389
|
-
});
|
|
390
|
-
|
|
391
|
-
const from = {
|
|
392
|
-
users: users,
|
|
393
|
-
|
|
394
|
-
view: mysqlView('some_view', {}).algorithm('merge').sqlSecurity('definer')
|
|
395
|
-
.withCheckOption('cascaded').existing(),
|
|
396
|
-
};
|
|
397
|
-
const to = {
|
|
398
|
-
users: users,
|
|
399
|
-
view: mysqlView('some_view', {}).existing(),
|
|
400
|
-
};
|
|
401
|
-
|
|
402
|
-
const { statements, sqlStatements } = await diffTestSchemasMysql(from, to, []);
|
|
403
|
-
|
|
404
|
-
expect(statements.length).toBe(0);
|
|
405
|
-
expect(sqlStatements.length).toBe(0);
|
|
406
|
-
});
|
|
407
|
-
|
|
408
|
-
test('alter view ".as" value', async () => {
|
|
409
|
-
const users = mysqlTable('users', {
|
|
410
|
-
id: int('id').primaryKey().notNull(),
|
|
411
|
-
});
|
|
412
|
-
|
|
413
|
-
const from = {
|
|
414
|
-
users: users,
|
|
415
|
-
view: mysqlView('some_view', {}).algorithm('temptable').sqlSecurity('invoker')
|
|
416
|
-
.withCheckOption('cascaded').as(sql`SELECT * FROM ${users}`),
|
|
417
|
-
};
|
|
418
|
-
const to = {
|
|
419
|
-
users: users,
|
|
420
|
-
view: mysqlView('some_view', {}).algorithm('temptable').sqlSecurity('invoker')
|
|
421
|
-
.withCheckOption('cascaded').as(sql`SELECT * FROM ${users} WHERE ${users.id} = 1`),
|
|
422
|
-
};
|
|
423
|
-
|
|
424
|
-
const { statements, sqlStatements } = await diffTestSchemasMysql(from, to, []);
|
|
425
|
-
|
|
426
|
-
expect(statements.length).toBe(1);
|
|
427
|
-
expect(statements[0]).toStrictEqual({
|
|
428
|
-
algorithm: 'temptable',
|
|
429
|
-
definition: 'SELECT * FROM `users` WHERE `users`.`id` = 1',
|
|
430
|
-
name: 'some_view',
|
|
431
|
-
sqlSecurity: 'invoker',
|
|
432
|
-
type: 'mysql_create_view',
|
|
433
|
-
withCheckOption: 'cascaded',
|
|
434
|
-
replace: true,
|
|
435
|
-
});
|
|
436
|
-
|
|
437
|
-
expect(sqlStatements.length).toBe(1);
|
|
438
|
-
expect(sqlStatements[0]).toBe(`CREATE OR REPLACE ALGORITHM = temptable
|
|
439
|
-
SQL SECURITY invoker
|
|
440
|
-
VIEW \`some_view\` AS (SELECT * FROM \`users\` WHERE \`users\`.\`id\` = 1)
|
|
441
|
-
WITH cascaded CHECK OPTION;`);
|
|
442
|
-
});
|
|
443
|
-
|
|
444
|
-
test('rename and alter view ".as" value', async () => {
|
|
445
|
-
const users = mysqlTable('users', {
|
|
446
|
-
id: int('id').primaryKey().notNull(),
|
|
447
|
-
});
|
|
448
|
-
|
|
449
|
-
const from = {
|
|
450
|
-
users: users,
|
|
451
|
-
view: mysqlView('some_view', {}).algorithm('temptable').sqlSecurity('invoker')
|
|
452
|
-
.withCheckOption('cascaded').as(sql`SELECT * FROM ${users}`),
|
|
453
|
-
};
|
|
454
|
-
const to = {
|
|
455
|
-
users: users,
|
|
456
|
-
view: mysqlView('new_some_view', {}).algorithm('temptable').sqlSecurity('invoker')
|
|
457
|
-
.withCheckOption('cascaded').as(sql`SELECT * FROM ${users} WHERE ${users.id} = 1`),
|
|
458
|
-
};
|
|
459
|
-
|
|
460
|
-
const { statements, sqlStatements } = await diffTestSchemasMysql(from, to, [
|
|
461
|
-
'public.some_view->public.new_some_view',
|
|
462
|
-
]);
|
|
463
|
-
|
|
464
|
-
expect(statements.length).toBe(2);
|
|
465
|
-
expect(statements[0]).toStrictEqual({
|
|
466
|
-
nameFrom: 'some_view',
|
|
467
|
-
nameTo: 'new_some_view',
|
|
468
|
-
type: 'rename_view',
|
|
469
|
-
});
|
|
470
|
-
expect(statements[1]).toStrictEqual({
|
|
471
|
-
algorithm: 'temptable',
|
|
472
|
-
definition: 'SELECT * FROM `users` WHERE `users`.`id` = 1',
|
|
473
|
-
name: 'new_some_view',
|
|
474
|
-
sqlSecurity: 'invoker',
|
|
475
|
-
type: 'mysql_create_view',
|
|
476
|
-
withCheckOption: 'cascaded',
|
|
477
|
-
replace: true,
|
|
478
|
-
});
|
|
479
|
-
|
|
480
|
-
expect(sqlStatements.length).toBe(2);
|
|
481
|
-
expect(sqlStatements[0]).toBe(`RENAME TABLE \`some_view\` TO \`new_some_view\`;`);
|
|
482
|
-
expect(sqlStatements[1]).toBe(`CREATE OR REPLACE ALGORITHM = temptable
|
|
483
|
-
SQL SECURITY invoker
|
|
484
|
-
VIEW \`new_some_view\` AS (SELECT * FROM \`users\` WHERE \`users\`.\`id\` = 1)
|
|
485
|
-
WITH cascaded CHECK OPTION;`);
|
|
486
|
-
});
|
|
487
|
-
|
|
488
|
-
test('set existing', async () => {
|
|
489
|
-
const users = mysqlTable('users', {
|
|
490
|
-
id: int('id').primaryKey().notNull(),
|
|
491
|
-
});
|
|
492
|
-
|
|
493
|
-
const from = {
|
|
494
|
-
users: users,
|
|
495
|
-
view: mysqlView('some_view', {}).algorithm('temptable').sqlSecurity('invoker')
|
|
496
|
-
.withCheckOption('cascaded').as(sql`SELECT * FROM ${users}`),
|
|
497
|
-
};
|
|
498
|
-
const to = {
|
|
499
|
-
users: users,
|
|
500
|
-
view: mysqlView('new_some_view', {}).algorithm('temptable').sqlSecurity('invoker')
|
|
501
|
-
.withCheckOption('cascaded').existing(),
|
|
502
|
-
};
|
|
503
|
-
|
|
504
|
-
const { statements, sqlStatements } = await diffTestSchemasMysql(from, to, [
|
|
505
|
-
'public.some_view->public.new_some_view',
|
|
506
|
-
]);
|
|
507
|
-
|
|
508
|
-
expect(statements.length).toBe(0);
|
|
509
|
-
expect(sqlStatements.length).toBe(0);
|
|
510
|
-
});
|
|
511
|
-
|
|
512
|
-
test('drop existing', async () => {
|
|
513
|
-
const users = mysqlTable('users', {
|
|
514
|
-
id: int('id').primaryKey().notNull(),
|
|
515
|
-
});
|
|
516
|
-
|
|
517
|
-
const from = {
|
|
518
|
-
users: users,
|
|
519
|
-
view: mysqlView('some_view', {}).algorithm('temptable').sqlSecurity('invoker')
|
|
520
|
-
.withCheckOption('cascaded').existing(),
|
|
521
|
-
};
|
|
522
|
-
const to = {
|
|
523
|
-
users: users,
|
|
524
|
-
view: mysqlView('new_some_view', {}).algorithm('temptable').sqlSecurity('invoker')
|
|
525
|
-
.withCheckOption('cascaded').as(sql`SELECT * FROM ${users} WHERE ${users.id} = 1`),
|
|
526
|
-
};
|
|
527
|
-
|
|
528
|
-
const { statements, sqlStatements } = await diffTestSchemasMysql(from, to, [
|
|
529
|
-
'public.some_view->public.new_some_view',
|
|
530
|
-
]);
|
|
531
|
-
|
|
532
|
-
expect(statements.length).toBe(2);
|
|
533
|
-
expect(statements[0]).toStrictEqual({
|
|
534
|
-
name: 'new_some_view',
|
|
535
|
-
type: 'drop_view',
|
|
536
|
-
});
|
|
537
|
-
expect(statements[1]).toStrictEqual({
|
|
538
|
-
algorithm: 'temptable',
|
|
539
|
-
definition: 'SELECT * FROM `users` WHERE `users`.`id` = 1',
|
|
540
|
-
name: 'new_some_view',
|
|
541
|
-
sqlSecurity: 'invoker',
|
|
542
|
-
type: 'mysql_create_view',
|
|
543
|
-
withCheckOption: 'cascaded',
|
|
544
|
-
replace: false,
|
|
545
|
-
});
|
|
546
|
-
|
|
547
|
-
expect(sqlStatements.length).toBe(2);
|
|
548
|
-
expect(sqlStatements[0]).toBe(`DROP VIEW \`new_some_view\`;`);
|
|
549
|
-
expect(sqlStatements[1]).toBe(`CREATE ALGORITHM = temptable
|
|
550
|
-
SQL SECURITY invoker
|
|
551
|
-
VIEW \`new_some_view\` AS (SELECT * FROM \`users\` WHERE \`users\`.\`id\` = 1)
|
|
552
|
-
WITH cascaded CHECK OPTION;`);
|
|
553
|
-
});
|