@verdnatura/myt 1.5.19 → 1.5.21

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.
Files changed (69) hide show
  1. package/.dockerignore +2 -2
  2. package/LICENSE +17 -17
  3. package/README.md +284 -278
  4. package/assets/db.ini +5 -5
  5. package/assets/myt.default.yml +28 -11
  6. package/assets/structure.sql +24 -24
  7. package/cli.js +4 -4
  8. package/exporters/event.ejs +18 -18
  9. package/exporters/event.js +31 -31
  10. package/exporters/event.sql +19 -19
  11. package/exporters/function.ejs +17 -17
  12. package/exporters/function.js +27 -27
  13. package/exporters/function.sql +16 -16
  14. package/exporters/procedure.ejs +11 -11
  15. package/exporters/procedure.js +23 -23
  16. package/exporters/procedure.sql +14 -14
  17. package/exporters/trigger.ejs +4 -4
  18. package/exporters/trigger.js +10 -10
  19. package/exporters/trigger.sql +13 -13
  20. package/exporters/view.ejs +7 -7
  21. package/exporters/view.js +29 -29
  22. package/exporters/view.sql +12 -12
  23. package/helpers/local-fixtures.js +79 -0
  24. package/lib/command.js +19 -13
  25. package/lib/conn.js +141 -141
  26. package/lib/docker.js +133 -133
  27. package/lib/dumper.js +104 -83
  28. package/lib/exporter-engine.js +112 -112
  29. package/lib/exporter.js +86 -86
  30. package/lib/repo.js +29 -29
  31. package/lib/server.js +71 -71
  32. package/lib/util.js +7 -7
  33. package/myt-clean.js +58 -58
  34. package/myt-create.js +74 -74
  35. package/myt-dump.js +134 -75
  36. package/myt-fixtures.js +28 -29
  37. package/myt-init.js +36 -36
  38. package/myt-pull.js +183 -183
  39. package/myt-push.js +575 -568
  40. package/myt-run.js +190 -177
  41. package/myt-start.js +54 -54
  42. package/myt-version.js +218 -218
  43. package/myt.js +378 -361
  44. package/package.json +41 -41
  45. package/server/Dockerfile.base +1 -1
  46. package/server/Dockerfile.client +14 -14
  47. package/server/Dockerfile.dump +13 -16
  48. package/server/Dockerfile.server +25 -25
  49. package/server/docker-dump.sh +4 -4
  50. package/server/docker-fixtures.sh +5 -4
  51. package/server/docker-import.sh +10 -6
  52. package/server/docker-init.sh +23 -20
  53. package/server/docker-start.sh +10 -10
  54. package/server/docker.cnf +9 -9
  55. package/template/dump/Dockerfile.base +1 -1
  56. package/template/dump/dump.after.sql +1 -0
  57. package/template/dump/dump.before.sql +1 -0
  58. package/template/dump/fixtures.after.sql +1 -0
  59. package/template/dump/fixtures.before.sql +1 -0
  60. package/template/myt.config.yml +11 -11
  61. package/template/package.json +13 -13
  62. package/template/remotes/docker.ini +4 -4
  63. package/template/remotes/local.ini +5 -5
  64. package/template/routines/README.md +1 -1
  65. package/template/versions/00001-firstVersion/00-firstScript.sql +1 -1
  66. package/template/versions/README.md +1 -1
  67. package/template/dump/afterDump.sql +0 -1
  68. package/template/dump/beforeDump.sql +0 -1
  69. package/template/dump/fixtures.sql +0 -1
@@ -1,24 +1,24 @@
1
-
2
- CREATE TABLE `version` (
3
- `code` VARCHAR(50) NOT NULL,
4
- `number` CHAR(11) NULL DEFAULT NULL,
5
- `gitCommit` VARCHAR(255) NULL DEFAULT NULL,
6
- `updated` DATETIME NOT NULL,
7
- `lastNumber` CHAR(11) NULL DEFAULT NULL
8
- ) ENGINE=InnoDB;
9
-
10
- ALTER TABLE `version`
11
- ADD PRIMARY KEY (`code`);
12
-
13
- CREATE TABLE `versionLog` (
14
- `code` VARCHAR(50) NOT NULL,
15
- `number` CHAR(11) NOT NULL,
16
- `file` VARCHAR(255) NOT NULL,
17
- `user` VARCHAR(255) NULL,
18
- `updated` DATETIME NOT NULL,
19
- `errorNumber` INT(10) UNSIGNED DEFAULT NULL,
20
- `errorMessage` VARCHAR(255) DEFAULT NULL
21
- ) ENGINE=InnoDB;
22
-
23
- ALTER TABLE `versionLog`
24
- ADD PRIMARY KEY (`code`,`number`,`file`);
1
+
2
+ CREATE TABLE `version` (
3
+ `code` VARCHAR(50) NOT NULL,
4
+ `number` CHAR(11) NULL DEFAULT NULL,
5
+ `gitCommit` VARCHAR(255) NULL DEFAULT NULL,
6
+ `updated` DATETIME NOT NULL,
7
+ `lastNumber` CHAR(11) NULL DEFAULT NULL
8
+ ) ENGINE=InnoDB;
9
+
10
+ ALTER TABLE `version`
11
+ ADD PRIMARY KEY (`code`);
12
+
13
+ CREATE TABLE `versionLog` (
14
+ `code` VARCHAR(50) NOT NULL,
15
+ `number` CHAR(11) NOT NULL,
16
+ `file` VARCHAR(255) NOT NULL,
17
+ `user` VARCHAR(255) NULL,
18
+ `updated` DATETIME NOT NULL,
19
+ `errorNumber` INT(10) UNSIGNED DEFAULT NULL,
20
+ `errorMessage` VARCHAR(255) DEFAULT NULL
21
+ ) ENGINE=InnoDB;
22
+
23
+ ALTER TABLE `versionLog`
24
+ ADD PRIMARY KEY (`code`,`number`,`file`);
package/cli.js CHANGED
@@ -1,4 +1,4 @@
1
- #!/usr/bin/env node
2
-
3
- const Myt = require('./myt');
4
- new Myt().run();
1
+ #!/usr/bin/env node
2
+
3
+ const Myt = require('./myt');
4
+ new Myt().run();
@@ -1,18 +1,18 @@
1
- <%- begin %> <%- typeAndName %><%
2
- if (params.type == 'RECURRING') { %>
3
- ON SCHEDULE EVERY <%- params.intervalValue %> <%- params.intervalField %><%
4
- if (params.starts) { %>
5
- STARTS <%- params.starts %><%
6
- }
7
- if (params.ends) { %>
8
- ENDS <%- params.ends %><%
9
- }
10
- } else { %>
11
- ON SCHEDULE AT <%- params.executeAt %><%
12
- } %>
13
- ON COMPLETION <%- params.onCompletion %>
14
- <%- params.status %><%
15
- if (params.comment) { %>
16
- COMMENT <%- params.comment %><%
17
- } %>
18
- DO <%- params.body %><%- end %>
1
+ <%- begin %> <%- typeAndName %><%
2
+ if (params.type == 'RECURRING') { %>
3
+ ON SCHEDULE EVERY <%- params.intervalValue %> <%- params.intervalField %><%
4
+ if (params.starts) { %>
5
+ STARTS <%- params.starts %><%
6
+ }
7
+ if (params.ends) { %>
8
+ ENDS <%- params.ends %><%
9
+ }
10
+ } else { %>
11
+ ON SCHEDULE AT <%- params.executeAt %><%
12
+ } %>
13
+ ON COMPLETION <%- params.onCompletion %>
14
+ <%- params.status %><%
15
+ if (params.comment) { %>
16
+ COMMENT <%- params.comment %><%
17
+ } %>
18
+ DO <%- params.body %><%- end %>
@@ -1,31 +1,31 @@
1
-
2
- module.exports = {
3
- schemaCol: 'EVENT_SCHEMA',
4
- nameCol: 'EVENT_NAME',
5
- escapeCols: [
6
- 'starts',
7
- 'ends',
8
- 'executeAt',
9
- 'comment'
10
- ],
11
- defaults: {
12
- type: 'RECURRING',
13
- intervalValue: 1,
14
- intervalField: 'DAY',
15
- onCompletion: 'PRESERVE'
16
- },
17
- formatter(params) {
18
- let status;
19
- switch(params.status){
20
- case 'DISABLED':
21
- status = 'DISABLE';
22
- break;
23
- case 'SLAVESIDE_DISABLED':
24
- status = 'DISABLE ON SLAVE';
25
- break;
26
- default:
27
- status = 'ENABLE'
28
- }
29
- params.status = status;
30
- }
31
- };
1
+
2
+ module.exports = {
3
+ schemaCol: 'EVENT_SCHEMA',
4
+ nameCol: 'EVENT_NAME',
5
+ escapeCols: [
6
+ 'starts',
7
+ 'ends',
8
+ 'executeAt',
9
+ 'comment'
10
+ ],
11
+ defaults: {
12
+ type: 'RECURRING',
13
+ intervalValue: 1,
14
+ intervalField: 'DAY',
15
+ onCompletion: 'PRESERVE'
16
+ },
17
+ formatter(params) {
18
+ let status;
19
+ switch(params.status){
20
+ case 'DISABLED':
21
+ status = 'DISABLE';
22
+ break;
23
+ case 'SLAVESIDE_DISABLED':
24
+ status = 'DISABLE ON SLAVE';
25
+ break;
26
+ default:
27
+ status = 'ENABLE'
28
+ }
29
+ params.status = status;
30
+ }
31
+ };
@@ -1,19 +1,19 @@
1
-
2
- SELECT
3
- `EVENT_SCHEMA` AS `schema`,
4
- `EVENT_NAME` AS `name`,
5
- `DEFINER` AS `definer`,
6
- `EVENT_DEFINITION` AS `body`,
7
- `EVENT_TYPE` AS `type`,
8
- `EXECUTE_AT` AS `executeAt`,
9
- `INTERVAL_VALUE` AS `intervalValue`,
10
- `INTERVAL_FIELD` AS `intervalField`,
11
- `STARTS` AS `starts`,
12
- `ENDS` AS `ends`,
13
- `STATUS` AS `status`,
14
- `ON_COMPLETION` AS `onCompletion`,
15
- `EVENT_COMMENT` AS `comment`,
16
- `LAST_ALTERED` AS `modified`
17
- FROM `information_schema`.`EVENTS`
18
- WHERE ?
19
- ORDER BY `name`
1
+
2
+ SELECT
3
+ `EVENT_SCHEMA` AS `schema`,
4
+ `EVENT_NAME` AS `name`,
5
+ `DEFINER` AS `definer`,
6
+ `EVENT_DEFINITION` AS `body`,
7
+ `EVENT_TYPE` AS `type`,
8
+ `EXECUTE_AT` AS `executeAt`,
9
+ `INTERVAL_VALUE` AS `intervalValue`,
10
+ `INTERVAL_FIELD` AS `intervalField`,
11
+ `STARTS` AS `starts`,
12
+ `ENDS` AS `ends`,
13
+ `STATUS` AS `status`,
14
+ `ON_COMPLETION` AS `onCompletion`,
15
+ `EVENT_COMMENT` AS `comment`,
16
+ `LAST_ALTERED` AS `modified`
17
+ FROM `information_schema`.`EVENTS`
18
+ WHERE ?
19
+ ORDER BY `name`
@@ -1,17 +1,17 @@
1
- <%- begin %> <%- typeAndName %>(<%- params.paramList %>)
2
- RETURNS <%- params.returns %><%
3
- if (params.isDeterministic == 'NO') { %>
4
- NOT DETERMINISTIC<%
5
- } else { %>
6
- DETERMINISTIC<%
7
- }
8
- if (params.dataAccess) { %>
9
- <%- params.dataAccess %><%
10
- }
11
- if (params.securityType == 'INVOKER') { %>
12
- SQL SECURITY <%- params.securityType %><%
13
- }
14
- if (params.comment) { %>
15
- COMMENT <%- params.comment %><%
16
- } %>
17
- <%- params.body %><%- end %>
1
+ <%- begin %> <%- typeAndName %>(<%- params.paramList %>)
2
+ RETURNS <%- params.returns %><%
3
+ if (params.isDeterministic == 'NO') { %>
4
+ NOT DETERMINISTIC<%
5
+ } else { %>
6
+ DETERMINISTIC<%
7
+ }
8
+ if (params.dataAccess) { %>
9
+ <%- params.dataAccess %><%
10
+ }
11
+ if (params.securityType == 'INVOKER') { %>
12
+ SQL SECURITY <%- params.securityType %><%
13
+ }
14
+ if (params.comment) { %>
15
+ COMMENT <%- params.comment %><%
16
+ } %>
17
+ <%- params.body %><%- end %>
@@ -1,27 +1,27 @@
1
-
2
- module.exports = {
3
- schemaCol: 'db',
4
- nameCol: 'name',
5
- escapeCols: [
6
- 'comment'
7
- ],
8
- defaults: {
9
- returns: 'INT',
10
- isDeterministic: 'NO'
11
- },
12
- formatter(params) {
13
- let dataAccess;
14
- switch(params.dataAccess) {
15
- case 'NO_SQL':
16
- dataAccess = 'NO SQL';
17
- break;
18
- case 'READS_SQL_DATA':
19
- dataAccess = 'READS SQL DATA';
20
- break;
21
- case 'MODIFIES_SQL_DATA':
22
- dataAccess = 'MODIFIES SQL DATA';
23
- break;
24
- }
25
- params.dataAccess = dataAccess;
26
- }
27
- };
1
+
2
+ module.exports = {
3
+ schemaCol: 'db',
4
+ nameCol: 'name',
5
+ escapeCols: [
6
+ 'comment'
7
+ ],
8
+ defaults: {
9
+ returns: 'INT',
10
+ isDeterministic: 'NO'
11
+ },
12
+ formatter(params) {
13
+ let dataAccess;
14
+ switch(params.dataAccess) {
15
+ case 'NO_SQL':
16
+ dataAccess = 'NO SQL';
17
+ break;
18
+ case 'READS_SQL_DATA':
19
+ dataAccess = 'READS SQL DATA';
20
+ break;
21
+ case 'MODIFIES_SQL_DATA':
22
+ dataAccess = 'MODIFIES SQL DATA';
23
+ break;
24
+ }
25
+ params.dataAccess = dataAccess;
26
+ }
27
+ };
@@ -1,16 +1,16 @@
1
-
2
- SELECT
3
- `db` AS `schema`,
4
- `name`,
5
- `definer`,
6
- `param_list` AS `paramList`,
7
- `body`,
8
- `sql_data_access` AS `dataAccess`,
9
- `security_type` AS `securityType`,
10
- `comment`,
11
- `modified`,
12
- `is_deterministic` AS `isDeterministic`,
13
- `returns`
14
- FROM `mysql`.`proc`
15
- WHERE ? AND `type` = 'FUNCTION'
16
- ORDER BY `name`
1
+
2
+ SELECT
3
+ `db` AS `schema`,
4
+ `name`,
5
+ `definer`,
6
+ `param_list` AS `paramList`,
7
+ `body`,
8
+ `sql_data_access` AS `dataAccess`,
9
+ `security_type` AS `securityType`,
10
+ `comment`,
11
+ `modified`,
12
+ `is_deterministic` AS `isDeterministic`,
13
+ `returns`
14
+ FROM `mysql`.`proc`
15
+ WHERE ? AND `type` = 'FUNCTION'
16
+ ORDER BY `name`
@@ -1,11 +1,11 @@
1
- <%- begin %> <%- typeAndName %>(<%- params.paramList %>)<%
2
- if (params.dataAccess) { %>
3
- <%- params.dataAccess %><%
4
- }
5
- if (params.securityType == 'INVOKER') { %>
6
- SQL SECURITY <%- params.securityType %><%
7
- }
8
- if (params.comment) { %>
9
- COMMENT <%- params.comment %><%
10
- } %>
11
- <%- params.body %><%- end %>
1
+ <%- begin %> <%- typeAndName %>(<%- params.paramList %>)<%
2
+ if (params.dataAccess) { %>
3
+ <%- params.dataAccess %><%
4
+ }
5
+ if (params.securityType == 'INVOKER') { %>
6
+ SQL SECURITY <%- params.securityType %><%
7
+ }
8
+ if (params.comment) { %>
9
+ COMMENT <%- params.comment %><%
10
+ } %>
11
+ <%- params.body %><%- end %>
@@ -1,23 +1,23 @@
1
-
2
- module.exports = {
3
- schemaCol: 'db',
4
- nameCol: 'name',
5
- escapeCols: [
6
- 'comment'
7
- ],
8
- formatter(params) {
9
- let dataAccess;
10
- switch(params.dataAccess) {
11
- case 'NO_SQL':
12
- dataAccess = 'NO SQL';
13
- break;
14
- case 'READS_SQL_DATA':
15
- dataAccess = 'READS SQL DATA';
16
- break;
17
- case 'MODIFIES_SQL_DATA':
18
- dataAccess = 'MODIFIES SQL DATA';
19
- break;
20
- }
21
- params.dataAccess = dataAccess;
22
- }
23
- };
1
+
2
+ module.exports = {
3
+ schemaCol: 'db',
4
+ nameCol: 'name',
5
+ escapeCols: [
6
+ 'comment'
7
+ ],
8
+ formatter(params) {
9
+ let dataAccess;
10
+ switch(params.dataAccess) {
11
+ case 'NO_SQL':
12
+ dataAccess = 'NO SQL';
13
+ break;
14
+ case 'READS_SQL_DATA':
15
+ dataAccess = 'READS SQL DATA';
16
+ break;
17
+ case 'MODIFIES_SQL_DATA':
18
+ dataAccess = 'MODIFIES SQL DATA';
19
+ break;
20
+ }
21
+ params.dataAccess = dataAccess;
22
+ }
23
+ };
@@ -1,14 +1,14 @@
1
-
2
- SELECT
3
- `db` AS `schema`,
4
- `name`,
5
- `definer`,
6
- `param_list` AS `paramList`,
7
- `body`,
8
- `sql_data_access` AS `dataAccess`,
9
- `security_type` AS `securityType`,
10
- `comment`,
11
- `modified`
12
- FROM `mysql`.`proc`
13
- WHERE ? AND `type` = 'PROCEDURE'
14
- ORDER BY `name`
1
+
2
+ SELECT
3
+ `db` AS `schema`,
4
+ `name`,
5
+ `definer`,
6
+ `param_list` AS `paramList`,
7
+ `body`,
8
+ `sql_data_access` AS `dataAccess`,
9
+ `security_type` AS `securityType`,
10
+ `comment`,
11
+ `modified`
12
+ FROM `mysql`.`proc`
13
+ WHERE ? AND `type` = 'PROCEDURE'
14
+ ORDER BY `name`
@@ -1,4 +1,4 @@
1
- <%- begin %> <%- typeAndName %>
2
- <%- params.actionTiming %> <%- params.actionType %> ON `<%- params.table %>`
3
- FOR EACH ROW
4
- <%- params.body %><%- end %>
1
+ <%- begin %> <%- typeAndName %>
2
+ <%- params.actionTiming %> <%- params.actionType %> ON `<%- params.table %>`
3
+ FOR EACH ROW
4
+ <%- params.body %><%- end %>
@@ -1,10 +1,10 @@
1
-
2
- module.exports = {
3
- schemaCol: 'TRIGGER_SCHEMA',
4
- nameCol: 'TRIGGER_NAME',
5
- defaults: {
6
- actionTiming: 'AFTER',
7
- actionType: 'INSERT',
8
- table: 'table'
9
- }
10
- };
1
+
2
+ module.exports = {
3
+ schemaCol: 'TRIGGER_SCHEMA',
4
+ nameCol: 'TRIGGER_NAME',
5
+ defaults: {
6
+ actionTiming: 'AFTER',
7
+ actionType: 'INSERT',
8
+ table: 'table'
9
+ }
10
+ };
@@ -1,13 +1,13 @@
1
-
2
- SELECT
3
- `TRIGGER_SCHEMA` AS `schema`,
4
- `TRIGGER_NAME` AS `name`,
5
- `DEFINER` AS `definer`,
6
- `ACTION_TIMING` AS `actionTiming`,
7
- `EVENT_MANIPULATION` AS `actionType`,
8
- `EVENT_OBJECT_TABLE` AS `table`,
9
- `ACTION_STATEMENT` AS `body`,
10
- `CREATED` AS `modified`
11
- FROM `information_schema`.`TRIGGERS`
12
- WHERE ?
13
- ORDER BY `name`
1
+
2
+ SELECT
3
+ `TRIGGER_SCHEMA` AS `schema`,
4
+ `TRIGGER_NAME` AS `name`,
5
+ `DEFINER` AS `definer`,
6
+ `ACTION_TIMING` AS `actionTiming`,
7
+ `EVENT_MANIPULATION` AS `actionType`,
8
+ `EVENT_OBJECT_TABLE` AS `table`,
9
+ `ACTION_STATEMENT` AS `body`,
10
+ `CREATED` AS `modified`
11
+ FROM `information_schema`.`TRIGGERS`
12
+ WHERE ?
13
+ ORDER BY `name`
@@ -1,7 +1,7 @@
1
- <%- createOrReplace %>
2
- SQL SECURITY <%- params.securityType %>
3
- <%- typeAndName %>
4
- AS <%- params.definition %><%
5
- if (params.checkOption != 'NONE') { %>
6
- WITH <%- params.checkOption %> CHECK OPTION<%
7
- } %>
1
+ <%- createOrReplace %>
2
+ SQL SECURITY <%- params.securityType %>
3
+ <%- typeAndName %>
4
+ AS <%- params.definition %><%
5
+ if (params.checkOption != 'NONE') { %>
6
+ WITH <%- params.checkOption %> CHECK OPTION<%
7
+ } %>
package/exporters/view.js CHANGED
@@ -1,29 +1,29 @@
1
-
2
- const sqlFormatter = require('@sqltools/formatter');
3
-
4
- module.exports = {
5
- schemaCol: 'TABLE_SCHEMA',
6
- nameCol: 'TABLE_NAME',
7
- defaults: {
8
- securityType: 'DEFINER',
9
- checkOption: 'NONE'
10
- },
11
- formatter(params) {
12
- params.definition = sqlFormatter.format(params.definition, {
13
- indent: '\t',
14
- reservedWordCase: 'upper'
15
- });
16
-
17
- let algorithm;
18
- switch (params.isUpdatable) {
19
- case 'YES':
20
- algorithm = 'MERGE';
21
- break;
22
- case 'NO':
23
- algorithm = 'TEMPTABLE';
24
- break;
25
- default:
26
- algorithm = 'UNDEFINED';
27
- }
28
- }
29
- };
1
+
2
+ const sqlFormatter = require('@sqltools/formatter');
3
+
4
+ module.exports = {
5
+ schemaCol: 'TABLE_SCHEMA',
6
+ nameCol: 'TABLE_NAME',
7
+ defaults: {
8
+ securityType: 'DEFINER',
9
+ checkOption: 'NONE'
10
+ },
11
+ formatter(params) {
12
+ params.definition = sqlFormatter.format(params.definition, {
13
+ indent: '\t',
14
+ reservedWordCase: 'upper'
15
+ });
16
+
17
+ let algorithm;
18
+ switch (params.isUpdatable) {
19
+ case 'YES':
20
+ algorithm = 'MERGE';
21
+ break;
22
+ case 'NO':
23
+ algorithm = 'TEMPTABLE';
24
+ break;
25
+ default:
26
+ algorithm = 'UNDEFINED';
27
+ }
28
+ }
29
+ };
@@ -1,12 +1,12 @@
1
-
2
- SELECT
3
- `TABLE_SCHEMA` AS `schema`,
4
- `TABLE_NAME` AS `name`,
5
- `VIEW_DEFINITION` AS `definition`,
6
- `CHECK_OPTION` AS `checkOption`,
7
- `IS_UPDATABLE` AS `isUpdatable`,
8
- `DEFINER` AS `definer`,
9
- `SECURITY_TYPE` AS `securityType`
10
- FROM `information_schema`.`VIEWS`
11
- WHERE ?
12
- ORDER BY `name`
1
+
2
+ SELECT
3
+ `TABLE_SCHEMA` AS `schema`,
4
+ `TABLE_NAME` AS `name`,
5
+ `VIEW_DEFINITION` AS `definition`,
6
+ `CHECK_OPTION` AS `checkOption`,
7
+ `IS_UPDATABLE` AS `isUpdatable`,
8
+ `DEFINER` AS `definer`,
9
+ `SECURITY_TYPE` AS `securityType`
10
+ FROM `information_schema`.`VIEWS`
11
+ WHERE ?
12
+ ORDER BY `name`
@@ -0,0 +1,79 @@
1
+ #!/bin/node
2
+
3
+ require('require-yaml');
4
+ const mysql = require('mysql2/promise');
5
+ const {fixtures} = require(`${process.cwd()}/myt.config.yml`);
6
+
7
+ const config = {
8
+ host: 'localhost',
9
+ user: 'root',
10
+ password: 'root'
11
+ };
12
+
13
+ async function connectAndQuery() {
14
+ try {
15
+ const connection = await mysql.createConnection(config);
16
+
17
+ // Get schemas
18
+
19
+ const [schemaResults] = await connection.query('SHOW DATABASES');
20
+ const schemaNames = schemaResults.map(r => r.Database);
21
+
22
+ // Filter system schemas
23
+
24
+ const systemSchemas = ['mysql', 'sys', 'information_schema', 'performance_schema'];
25
+ const userSchemas = schemaNames.filter(s => !systemSchemas.includes(s));
26
+
27
+ if (userSchemas.length === 0) {
28
+ console.log('There are no user schemas with tables that have records.');
29
+ connection.end();
30
+ return;
31
+ }
32
+
33
+ // Get tables with records
34
+
35
+ userSchemas.sort((a, b) => a.localeCompare(b));
36
+ for (const schemaName of userSchemas) {
37
+ const [tableResults] = await connection.query(
38
+ `SELECT TABLE_NAME tableName
39
+ FROM information_schema.TABLES
40
+ WHERE TABLE_SCHEMA = ?
41
+ AND TABLE_TYPE <> 'VIEW'`,
42
+ [schemaName]
43
+ );
44
+ const tableNames = tableResults.map(r => r.tableName);
45
+ if (tableNames.length === 0) continue;
46
+
47
+ const schemaFixtures = new Set(fixtures[schemaName]);
48
+ const nonEmptyTables = [];
49
+
50
+ for (const tableName of tableNames) {
51
+ if (schemaFixtures.has(tableName)) continue;
52
+ try {
53
+ const [[row]] = await connection.query(
54
+ `SELECT COUNT(*) \`count\` FROM ??.??`,
55
+ [schemaName, tableName]
56
+ );
57
+ if (row.count == 0) continue;
58
+ if (!fixtures[schemaName]?.[tableName])
59
+ nonEmptyTables.push(tableName);
60
+ } catch (err) {
61
+ console.error('Error:', err.message);
62
+ }
63
+ }
64
+
65
+ nonEmptyTables.sort((a, b) => a.localeCompare(b));
66
+ if (nonEmptyTables.length) {
67
+ console.log(`${schemaName}:`);
68
+ for (const tableName of nonEmptyTables)
69
+ console.log(` - ${tableName}`);
70
+ }
71
+ }
72
+
73
+ connection.end();
74
+ } catch (err) {
75
+ console.error('Error:', err.message);
76
+ }
77
+ }
78
+
79
+ connectAndQuery();