@verdnatura/myt 1.6.9 → 1.6.10
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/assets/myt.default.yml +5 -0
- package/exporters/event.ejs +0 -0
- package/exporters/event.sql +0 -0
- package/exporters/function.ejs +0 -0
- package/exporters/function.sql +0 -0
- package/exporters/procedure.ejs +0 -0
- package/exporters/procedure.sql +0 -0
- package/exporters/trigger.ejs +0 -0
- package/exporters/trigger.sql +0 -0
- package/exporters/view.ejs +0 -0
- package/exporters/view.sql +0 -0
- package/myt-clean.js +1 -1
- package/myt-create.js +1 -1
- package/myt-dump.js +1 -1
- package/myt-init.js +0 -0
- package/myt-pull.js +0 -0
- package/myt-push.js +2 -2
- package/myt-version.js +119 -7
- package/myt.js +1 -1
- package/package.json +1 -1
- package/server/docker-dump.sh +0 -0
- package/server/docker-fixtures.sh +0 -0
- package/server/docker-import.sh +0 -0
- package/server/docker-init.sh +0 -0
- package/server/docker-start.sh +0 -0
- package/template/myt.config.yml +0 -0
package/assets/myt.default.yml
CHANGED
|
@@ -6,6 +6,11 @@ mockFunctions:
|
|
|
6
6
|
- mockTime
|
|
7
7
|
- mockUtcTime
|
|
8
8
|
sumViews: true
|
|
9
|
+
defaultDefiner: root@localhost
|
|
10
|
+
deprecMarkRegex: __$
|
|
11
|
+
deprecCommentRegex: ^@deprecated [0-9]{4}-[0-9]{2}-[0-9]{2}
|
|
12
|
+
deprecDateRegex: '[0-9]{4}-[0-9]{2}-[0-9]{2}'
|
|
13
|
+
deprecRetentionPeriod: 60 # Days
|
|
9
14
|
privileges:
|
|
10
15
|
userTable: global_priv
|
|
11
16
|
userWhere: >-
|
package/exporters/event.ejs
CHANGED
|
File without changes
|
package/exporters/event.sql
CHANGED
|
File without changes
|
package/exporters/function.ejs
CHANGED
|
File without changes
|
package/exporters/function.sql
CHANGED
|
File without changes
|
package/exporters/procedure.ejs
CHANGED
|
File without changes
|
package/exporters/procedure.sql
CHANGED
|
File without changes
|
package/exporters/trigger.ejs
CHANGED
|
File without changes
|
package/exporters/trigger.sql
CHANGED
|
File without changes
|
package/exporters/view.ejs
CHANGED
|
File without changes
|
package/exporters/view.sql
CHANGED
|
File without changes
|
package/myt-clean.js
CHANGED
package/myt-create.js
CHANGED
package/myt-dump.js
CHANGED
|
@@ -9,7 +9,7 @@ class Dump extends Command {
|
|
|
9
9
|
description: 'Dumps structure and fixtures from remote',
|
|
10
10
|
params: {
|
|
11
11
|
lock: 'Whether to lock tables on dump',
|
|
12
|
-
triggers: '
|
|
12
|
+
triggers: 'Whether to include triggers into dump'
|
|
13
13
|
},
|
|
14
14
|
operand: 'remote'
|
|
15
15
|
};
|
package/myt-init.js
CHANGED
|
File without changes
|
package/myt-pull.js
CHANGED
|
File without changes
|
package/myt-push.js
CHANGED
|
@@ -15,9 +15,9 @@ class Push extends Command {
|
|
|
15
15
|
description: 'Apply changes into database',
|
|
16
16
|
params: {
|
|
17
17
|
force: 'Answer yes to all questions',
|
|
18
|
-
commit: '
|
|
18
|
+
commit: 'Whether to save the commit SHA into database',
|
|
19
19
|
sums: 'Save SHA sums of pushed objects',
|
|
20
|
-
triggers: '
|
|
20
|
+
triggers: 'Whether to exclude triggers, used to generate local DB'
|
|
21
21
|
},
|
|
22
22
|
operand: 'remote'
|
|
23
23
|
};
|
package/myt-version.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
const Myt = require('./myt');
|
|
2
2
|
const Command = require('./lib/command');
|
|
3
3
|
const fs = require('fs-extra');
|
|
4
|
+
const SqlString = require('sqlstring');
|
|
4
5
|
|
|
5
6
|
/**
|
|
6
7
|
* Creates a new version.
|
|
@@ -9,18 +10,23 @@ class Version extends Command {
|
|
|
9
10
|
static usage = {
|
|
10
11
|
description: 'Creates a new version',
|
|
11
12
|
params: {
|
|
12
|
-
name: 'Name for the new version'
|
|
13
|
+
name: 'Name for the new version',
|
|
14
|
+
deprecate: 'Whether to generate sql to delete deprecated objects'
|
|
13
15
|
},
|
|
14
16
|
operand: 'name'
|
|
15
17
|
};
|
|
16
18
|
|
|
17
19
|
static opts = {
|
|
18
20
|
alias: {
|
|
19
|
-
name: 'n'
|
|
21
|
+
name: 'n',
|
|
22
|
+
deprecate: 'p'
|
|
20
23
|
},
|
|
21
24
|
string: [
|
|
22
25
|
'name'
|
|
23
26
|
],
|
|
27
|
+
boolean: [
|
|
28
|
+
'deprecate'
|
|
29
|
+
],
|
|
24
30
|
default: {
|
|
25
31
|
remote: 'production'
|
|
26
32
|
}
|
|
@@ -36,7 +42,8 @@ class Version extends Command {
|
|
|
36
42
|
},
|
|
37
43
|
versionCreated: function(versionName) {
|
|
38
44
|
console.log(`New version created: ${versionName}`);
|
|
39
|
-
}
|
|
45
|
+
},
|
|
46
|
+
deprecate: 'Generating SQL for deprecated objects deletion.'
|
|
40
47
|
};
|
|
41
48
|
|
|
42
49
|
async run(myt, opts) {
|
|
@@ -121,10 +128,16 @@ class Version extends Command {
|
|
|
121
128
|
[opts.code, newVersion]
|
|
122
129
|
);
|
|
123
130
|
await fs.mkdir(newVersionDir);
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
'
|
|
127
|
-
|
|
131
|
+
|
|
132
|
+
if (opts.deprecate) {
|
|
133
|
+
this.emit('deprecate');
|
|
134
|
+
await deprecate(conn, opts, newVersionDir);
|
|
135
|
+
} else
|
|
136
|
+
await fs.writeFile(
|
|
137
|
+
`${newVersionDir}/00-firstScript.sql`,
|
|
138
|
+
'-- Place your SQL code here\n'
|
|
139
|
+
);
|
|
140
|
+
|
|
128
141
|
this.emit('versionCreated', versionFolder);
|
|
129
142
|
|
|
130
143
|
await conn.query('COMMIT');
|
|
@@ -137,6 +150,105 @@ class Version extends Command {
|
|
|
137
150
|
}
|
|
138
151
|
}
|
|
139
152
|
|
|
153
|
+
async function deprecate(conn, opts, newVersionDir) {
|
|
154
|
+
const now = new Date();
|
|
155
|
+
const minDeprecDate = new Date(now.getTime() - opts.deprecRetentionPeriod * 24 * 60 * 60 * 1000);
|
|
156
|
+
const deprecMarkRegex = opts.deprecMarkRegex;
|
|
157
|
+
const deprecCommentRegex = opts.deprecCommentRegex;
|
|
158
|
+
const deprecDateRegex = opts.deprecDateRegex;
|
|
159
|
+
const filePath = `${newVersionDir}/00-deprecate.sql`;
|
|
160
|
+
|
|
161
|
+
// Generate the drops of the primary keys
|
|
162
|
+
const [primaryKeys] = await conn.query(`
|
|
163
|
+
SELECT c.TABLE_SCHEMA 'schema', c.TABLE_NAME 'table'
|
|
164
|
+
FROM information_schema.COLUMNS c
|
|
165
|
+
LEFT JOIN information_schema.VIEWS v ON v.TABLE_SCHEMA = c.TABLE_SCHEMA
|
|
166
|
+
AND v.TABLE_NAME = c.TABLE_NAME
|
|
167
|
+
JOIN information_schema.STATISTICS s ON s.TABLE_SCHEMA = c.TABLE_SCHEMA
|
|
168
|
+
AND s.TABLE_NAME = c.TABLE_NAME
|
|
169
|
+
AND s.COLUMN_NAME = c.COLUMN_NAME
|
|
170
|
+
WHERE c.COLUMN_NAME REGEXP ? COLLATE utf8mb4_unicode_ci
|
|
171
|
+
AND c.COLUMN_COMMENT REGEXP ? COLLATE utf8mb4_unicode_ci
|
|
172
|
+
AND REGEXP_SUBSTR(c.COLUMN_COMMENT, ? COLLATE utf8mb4_unicode_ci) < ?
|
|
173
|
+
AND v.TABLE_NAME IS NULL
|
|
174
|
+
AND s.INDEX_NAME = 'PRIMARY'
|
|
175
|
+
`, [deprecMarkRegex, deprecCommentRegex, deprecDateRegex, minDeprecDate]);
|
|
176
|
+
|
|
177
|
+
primaryKeys.map(async row => {
|
|
178
|
+
await fs.appendFile(
|
|
179
|
+
filePath,
|
|
180
|
+
'ALTER TABLE ' + SqlString.escapeId(row.schema, true) + '.' +
|
|
181
|
+
SqlString.escapeId(row.table, true) + ' DROP PRIMARY KEY;\n'
|
|
182
|
+
);
|
|
183
|
+
});
|
|
184
|
+
|
|
185
|
+
// Generate the drops of the foreign keys
|
|
186
|
+
const [foreignKeys] = await conn.query(`
|
|
187
|
+
SELECT c.TABLE_SCHEMA 'schema', c.TABLE_NAME 'table', kcu.CONSTRAINT_NAME 'constraint'
|
|
188
|
+
FROM information_schema.COLUMNS c
|
|
189
|
+
LEFT JOIN information_schema.VIEWS v ON v.TABLE_SCHEMA = c.TABLE_SCHEMA
|
|
190
|
+
AND v.TABLE_NAME = c.TABLE_NAME
|
|
191
|
+
JOIN information_schema.KEY_COLUMN_USAGE kcu ON kcu.TABLE_SCHEMA = c.TABLE_SCHEMA
|
|
192
|
+
AND kcu.TABLE_NAME = c.TABLE_NAME
|
|
193
|
+
AND kcu.COLUMN_NAME = c.COLUMN_NAME
|
|
194
|
+
WHERE c.COLUMN_NAME REGEXP ? COLLATE utf8mb4_unicode_ci
|
|
195
|
+
AND c.COLUMN_COMMENT REGEXP ? COLLATE utf8mb4_unicode_ci
|
|
196
|
+
AND REGEXP_SUBSTR(c.COLUMN_COMMENT, ? COLLATE utf8mb4_unicode_ci) < ?
|
|
197
|
+
AND v.TABLE_NAME IS NULL
|
|
198
|
+
AND kcu.REFERENCED_COLUMN_NAME IS NOT NULL
|
|
199
|
+
`, [deprecMarkRegex, deprecCommentRegex, deprecDateRegex, minDeprecDate]);
|
|
200
|
+
|
|
201
|
+
foreignKeys.map(async row => {
|
|
202
|
+
await fs.appendFile(
|
|
203
|
+
filePath,
|
|
204
|
+
'ALTER TABLE ' + SqlString.escapeId(row.schema, true) + '.' +
|
|
205
|
+
SqlString.escapeId(row.table, true) + ' DROP FOREIGN KEY ' +
|
|
206
|
+
SqlString.escapeId(row.constraint, true) + ';\n'
|
|
207
|
+
);
|
|
208
|
+
});
|
|
209
|
+
|
|
210
|
+
// Generate the drops of the columns
|
|
211
|
+
const [columns] = await conn.query(`
|
|
212
|
+
SELECT c.TABLE_SCHEMA 'schema', c.TABLE_NAME 'table', c.COLUMN_NAME 'column'
|
|
213
|
+
FROM information_schema.COLUMNS c
|
|
214
|
+
LEFT JOIN information_schema.VIEWS v ON v.TABLE_SCHEMA = c.TABLE_SCHEMA
|
|
215
|
+
AND v.TABLE_NAME = c.TABLE_NAME
|
|
216
|
+
LEFT JOIN information_schema.KEY_COLUMN_USAGE kcu ON kcu.TABLE_SCHEMA = c.TABLE_SCHEMA
|
|
217
|
+
AND kcu.TABLE_NAME = c.TABLE_NAME
|
|
218
|
+
AND kcu.COLUMN_NAME = c.COLUMN_NAME
|
|
219
|
+
WHERE c.COLUMN_NAME REGEXP ? COLLATE utf8mb4_unicode_ci
|
|
220
|
+
AND c.COLUMN_COMMENT REGEXP ? COLLATE utf8mb4_unicode_ci
|
|
221
|
+
AND REGEXP_SUBSTR(c.COLUMN_COMMENT, ? COLLATE utf8mb4_unicode_ci) <?
|
|
222
|
+
AND v.TABLE_NAME IS NULL
|
|
223
|
+
`, [deprecMarkRegex, deprecCommentRegex, deprecDateRegex, minDeprecDate]);
|
|
224
|
+
|
|
225
|
+
columns.map(async row => {
|
|
226
|
+
await fs.appendFile(
|
|
227
|
+
filePath,
|
|
228
|
+
'ALTER TABLE ' + SqlString.escapeId(row.schema, true) + '.' +
|
|
229
|
+
SqlString.escapeId(row.table, true) + ' DROP COLUMN ' +
|
|
230
|
+
SqlString.escapeId(row.column, true) + ';\n'
|
|
231
|
+
);
|
|
232
|
+
});
|
|
233
|
+
|
|
234
|
+
// Generate the drops of the tables
|
|
235
|
+
const [tables] = await conn.query(`
|
|
236
|
+
SELECT TABLE_SCHEMA 'schema', TABLE_NAME 'table'
|
|
237
|
+
FROM information_schema.TABLES
|
|
238
|
+
WHERE TABLE_NAME REGEXP ? COLLATE utf8mb4_unicode_ci
|
|
239
|
+
AND TABLE_COMMENT REGEXP ? COLLATE utf8mb4_unicode_ci
|
|
240
|
+
AND REGEXP_SUBSTR(TABLE_COMMENT, ? COLLATE utf8mb4_unicode_ci) < ?
|
|
241
|
+
`, [deprecMarkRegex, deprecCommentRegex, deprecDateRegex, minDeprecDate]);
|
|
242
|
+
|
|
243
|
+
tables.map(async row => {
|
|
244
|
+
await fs.appendFile(
|
|
245
|
+
filePath,
|
|
246
|
+
'DROP TABLE ' + SqlString.escapeId(row.schema, true) + '.' +
|
|
247
|
+
SqlString.escapeId(row.table, true) + ';\n'
|
|
248
|
+
);
|
|
249
|
+
});
|
|
250
|
+
}
|
|
251
|
+
|
|
140
252
|
function randomName() {
|
|
141
253
|
const color = random(colors);
|
|
142
254
|
let plant = random(plants);
|
package/myt.js
CHANGED
|
@@ -19,7 +19,7 @@ class Myt {
|
|
|
19
19
|
params: {
|
|
20
20
|
remote: 'Name of remote to use',
|
|
21
21
|
workspace: 'The base directory of the project',
|
|
22
|
-
debug: '
|
|
22
|
+
debug: 'Whether to enable debug mode',
|
|
23
23
|
version: 'Display the version number and exit',
|
|
24
24
|
help: 'Display this help message'
|
|
25
25
|
}
|
package/package.json
CHANGED
package/server/docker-dump.sh
CHANGED
|
File without changes
|
|
File without changes
|
package/server/docker-import.sh
CHANGED
|
File without changes
|
package/server/docker-init.sh
CHANGED
|
File without changes
|
package/server/docker-start.sh
CHANGED
|
File without changes
|
package/template/myt.config.yml
CHANGED
|
File without changes
|