@anthonyalayo/drizzle-kit 1.0.1
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/.gitignore +25 -0
- package/README.md +79 -0
- package/build.dev.ts +51 -0
- package/build.ts +112 -0
- package/imports-checker/analyze.ts +78 -0
- package/imports-checker/checker.ts +296 -0
- package/imports-checker/grammar/grammar.ohm +121 -0
- package/imports-checker/grammar/grammar.ohm-bundle.d.ts +164 -0
- package/imports-checker/grammar/grammar.ohm-bundle.js +753 -0
- package/imports-checker/index.ts +48 -0
- package/package.json +142 -0
- package/patches/difflib@0.2.4.patch +31 -0
- package/src/@types/utils.ts +58 -0
- package/src/api.ts +504 -0
- package/src/cli/commands/_es5.ts +2 -0
- package/src/cli/commands/check.ts +52 -0
- package/src/cli/commands/drop.ts +60 -0
- package/src/cli/commands/introspect.ts +772 -0
- package/src/cli/commands/libSqlPushUtils.ts +355 -0
- package/src/cli/commands/migrate.ts +1526 -0
- package/src/cli/commands/mysqlIntrospect.ts +53 -0
- package/src/cli/commands/mysqlPushUtils.ts +352 -0
- package/src/cli/commands/mysqlUp.ts +102 -0
- package/src/cli/commands/pgIntrospect.ts +55 -0
- package/src/cli/commands/pgPushUtils.ts +269 -0
- package/src/cli/commands/pgUp.ts +217 -0
- package/src/cli/commands/push.ts +637 -0
- package/src/cli/commands/singlestoreIntrospect.ts +53 -0
- package/src/cli/commands/singlestorePushUtils.ts +456 -0
- package/src/cli/commands/singlestoreUp.ts +1 -0
- package/src/cli/commands/sqliteIntrospect.ts +96 -0
- package/src/cli/commands/sqlitePushUtils.ts +322 -0
- package/src/cli/commands/sqliteUp.ts +52 -0
- package/src/cli/commands/utils.ts +858 -0
- package/src/cli/connections.ts +914 -0
- package/src/cli/index.ts +48 -0
- package/src/cli/schema.ts +794 -0
- package/src/cli/selector-ui.ts +38 -0
- package/src/cli/utils.ts +112 -0
- package/src/cli/validations/cli.ts +79 -0
- package/src/cli/validations/common.ts +193 -0
- package/src/cli/validations/libsql.ts +27 -0
- package/src/cli/validations/mysql.ts +61 -0
- package/src/cli/validations/outputs.ts +91 -0
- package/src/cli/validations/postgres.ts +83 -0
- package/src/cli/validations/singlestore.ts +61 -0
- package/src/cli/validations/sqlite.ts +104 -0
- package/src/cli/validations/studio.ts +24 -0
- package/src/cli/views.ts +658 -0
- package/src/extensions/getTablesFilterByExtensions.ts +16 -0
- package/src/extensions/vector.ts +10 -0
- package/src/global.ts +61 -0
- package/src/index.ts +326 -0
- package/src/introspect-mysql.ts +1030 -0
- package/src/introspect-pg.ts +1435 -0
- package/src/introspect-singlestore.ts +913 -0
- package/src/introspect-sqlite.ts +533 -0
- package/src/jsonDiffer.js +882 -0
- package/src/jsonStatements.ts +3590 -0
- package/src/loader.mjs +57 -0
- package/src/migrationPreparator.ts +217 -0
- package/src/schemaValidator.ts +23 -0
- package/src/serializer/index.ts +142 -0
- package/src/serializer/mysqlImports.ts +38 -0
- package/src/serializer/mysqlSchema.ts +423 -0
- package/src/serializer/mysqlSerializer.ts +999 -0
- package/src/serializer/pgImports.ts +106 -0
- package/src/serializer/pgSchema.ts +937 -0
- package/src/serializer/pgSerializer.ts +2223 -0
- package/src/serializer/singlestoreImports.ts +38 -0
- package/src/serializer/singlestoreSchema.ts +257 -0
- package/src/serializer/singlestoreSerializer.ts +767 -0
- package/src/serializer/sqliteImports.ts +41 -0
- package/src/serializer/sqliteSchema.ts +352 -0
- package/src/serializer/sqliteSerializer.ts +931 -0
- package/src/serializer/studio.ts +694 -0
- package/src/serializer/utils.ts +45 -0
- package/src/simulator.ts +157 -0
- package/src/snapshotsDiffer.ts +4398 -0
- package/src/sqlgenerator.ts +4212 -0
- package/src/statementCombiner.ts +597 -0
- package/src/utils/certs.ts +44 -0
- package/src/utils/words.ts +1333 -0
- package/src/utils.ts +370 -0
- package/tests/bin.test.ts +58 -0
- package/tests/cli/d1http.config.ts +12 -0
- package/tests/cli/drizzle.config.ts +9 -0
- package/tests/cli/durable-sqlite.config.ts +7 -0
- package/tests/cli/expo.config.ts +7 -0
- package/tests/cli/postgres.config.ts +13 -0
- package/tests/cli/postgres2.config.ts +17 -0
- package/tests/cli/schema.ts +1 -0
- package/tests/cli/turso.config.ts +10 -0
- package/tests/cli-export.test.ts +79 -0
- package/tests/cli-generate.test.ts +259 -0
- package/tests/cli-migrate.test.ts +103 -0
- package/tests/cli-push.test.ts +126 -0
- package/tests/common.ts +15 -0
- package/tests/indexes/common.ts +21 -0
- package/tests/indexes/pg.test.ts +245 -0
- package/tests/introspect/libsql.test.ts +35 -0
- package/tests/introspect/mysql.test.ts +319 -0
- package/tests/introspect/pg.test.ts +894 -0
- package/tests/introspect/singlestore.test.ts +275 -0
- package/tests/introspect/sqlite.test.ts +122 -0
- package/tests/libsql-checks.test.ts +308 -0
- package/tests/libsql-statements.test.ts +989 -0
- package/tests/libsql-views.test.ts +218 -0
- package/tests/migrate/libsq-schema.ts +6 -0
- package/tests/migrate/libsql-migrate.test.ts +58 -0
- package/tests/migrate/migrations/0000_little_blizzard.sql +4 -0
- package/tests/migrate/migrations/0001_nebulous_storm.sql +10 -0
- package/tests/migrate/migrations/meta/0000_snapshot.json +40 -0
- package/tests/migrate/migrations/meta/0001_snapshot.json +40 -0
- package/tests/migrate/migrations/meta/_journal.json +20 -0
- package/tests/mysql-checks.test.ts +291 -0
- package/tests/mysql-generated.test.ts +1290 -0
- package/tests/mysql-schemas.test.ts +156 -0
- package/tests/mysql-views.test.ts +553 -0
- package/tests/mysql.test.ts +863 -0
- package/tests/pg-array.test.ts +368 -0
- package/tests/pg-checks.test.ts +329 -0
- package/tests/pg-columns.test.ts +484 -0
- package/tests/pg-domains.test.ts +306 -0
- package/tests/pg-enums.test.ts +751 -0
- package/tests/pg-generated.test.ts +529 -0
- package/tests/pg-identity.test.ts +447 -0
- package/tests/pg-schemas.test.ts +105 -0
- package/tests/pg-sequences.test.ts +298 -0
- package/tests/pg-tables.test.ts +1021 -0
- package/tests/pg-views.test.ts +1929 -0
- package/tests/push/common.ts +58 -0
- package/tests/push/libsql.test.ts +1400 -0
- package/tests/push/mysql-push.test.ts +345 -0
- package/tests/push/mysql.test.ts +788 -0
- package/tests/push/pg.test.ts +4341 -0
- package/tests/push/singlestore-push.test.ts +894 -0
- package/tests/push/singlestore.test.ts +444 -0
- package/tests/push/sqlite.test.ts +1613 -0
- package/tests/rls/pg-policy.test.ts +1656 -0
- package/tests/rls/pg-role.test.ts +234 -0
- package/tests/schemaDiffer.ts +2852 -0
- package/tests/singlestore-generated.test.ts +1290 -0
- package/tests/singlestore-schemas.test.ts +155 -0
- package/tests/singlestore.test.ts +978 -0
- package/tests/sqlite-checks.test.ts +308 -0
- package/tests/sqlite-columns.test.ts +1049 -0
- package/tests/sqlite-generated.test.ts +1726 -0
- package/tests/sqlite-tables.test.ts +637 -0
- package/tests/sqlite-views.test.ts +218 -0
- package/tests/statements-combiner/libsql-statements-combiner.test.ts +1812 -0
- package/tests/statements-combiner/singlestore-statements-combiner.test.ts +882 -0
- package/tests/statements-combiner/sqlite-statements-combiner.test.ts +1211 -0
- package/tests/test/sqlite.test.ts +39 -0
- package/tests/testsinglestore.ts +29 -0
- package/tests/validations.test.ts +869 -0
- package/tests/wrap-param.test.ts +16 -0
- package/tsconfig.build.json +4 -0
- package/tsconfig.cli-types.json +9 -0
- package/tsconfig.json +28 -0
- package/vitest.config.ts +34 -0
|
@@ -0,0 +1,156 @@
|
|
|
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
|
+
});
|
|
@@ -0,0 +1,553 @@
|
|
|
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
|
+
});
|