@verdnatura/myt 1.5.19 → 1.5.20

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 (64) hide show
  1. package/.dockerignore +2 -2
  2. package/LICENSE +17 -17
  3. package/README.md +278 -278
  4. package/assets/db.ini +5 -5
  5. package/assets/myt.default.yml +11 -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/lib/command.js +13 -13
  24. package/lib/conn.js +141 -141
  25. package/lib/docker.js +133 -133
  26. package/lib/dumper.js +83 -83
  27. package/lib/exporter-engine.js +112 -112
  28. package/lib/exporter.js +86 -86
  29. package/lib/repo.js +29 -29
  30. package/lib/server.js +71 -71
  31. package/lib/util.js +7 -7
  32. package/myt-clean.js +58 -58
  33. package/myt-create.js +74 -74
  34. package/myt-dump.js +75 -75
  35. package/myt-fixtures.js +29 -29
  36. package/myt-init.js +36 -36
  37. package/myt-pull.js +183 -183
  38. package/myt-push.js +568 -568
  39. package/myt-run.js +177 -177
  40. package/myt-start.js +54 -54
  41. package/myt-version.js +218 -218
  42. package/myt.js +361 -361
  43. package/package.json +41 -41
  44. package/server/Dockerfile.base +1 -1
  45. package/server/Dockerfile.client +14 -14
  46. package/server/Dockerfile.dump +16 -16
  47. package/server/Dockerfile.server +25 -25
  48. package/server/docker-dump.sh +4 -4
  49. package/server/docker-fixtures.sh +4 -4
  50. package/server/docker-import.sh +6 -6
  51. package/server/docker-init.sh +20 -20
  52. package/server/docker-start.sh +10 -10
  53. package/server/docker.cnf +9 -9
  54. package/template/dump/Dockerfile.base +1 -1
  55. package/template/dump/afterDump.sql +1 -1
  56. package/template/dump/beforeDump.sql +1 -1
  57. package/template/dump/fixtures.sql +1 -1
  58. package/template/myt.config.yml +11 -11
  59. package/template/package.json +13 -13
  60. package/template/remotes/docker.ini +4 -4
  61. package/template/remotes/local.ini +5 -5
  62. package/template/routines/README.md +1 -1
  63. package/template/versions/00001-firstVersion/00-firstScript.sql +1 -1
  64. package/template/versions/README.md +1 -1
package/.dockerignore CHANGED
@@ -1,2 +1,2 @@
1
- node_modules
2
- .git
1
+ node_modules
2
+ .git
package/LICENSE CHANGED
@@ -1,17 +1,17 @@
1
- Copyright (C) 2020 - Verdnatura Levante S.L.
2
-
3
- This package is free software; you can redistribute it and/or modify
4
- it under the terms of the GNU General Public License as published by
5
- the Free Software Foundation, either version 3 of the License, or
6
- (at your option) any later version.
7
-
8
- This program is distributed in the hope that it will be useful,
9
- but WITHOUT ANY WARRANTY; without even the implied warranty of
10
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
- GNU General Public License for more details.
12
-
13
- You should have received a copy of the GNU General Public License
14
- along with this program. If not, see <http://www.gnu.org/licenses/>.
15
-
16
- On Debian systems, the complete text of the GNU General Public
17
- License can be found in "/usr/share/common-licenses/GPL-3".
1
+ Copyright (C) 2020 - Verdnatura Levante S.L.
2
+
3
+ This package is free software; you can redistribute it and/or modify
4
+ it under the terms of the GNU General Public License as published by
5
+ the Free Software Foundation, either version 3 of the License, or
6
+ (at your option) any later version.
7
+
8
+ This program is distributed in the hope that it will be useful,
9
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
10
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
+ GNU General Public License for more details.
12
+
13
+ You should have received a copy of the GNU General Public License
14
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
15
+
16
+ On Debian systems, the complete text of the GNU General Public
17
+ License can be found in "/usr/share/common-licenses/GPL-3".
package/README.md CHANGED
@@ -1,278 +1,278 @@
1
- # Myt - MySQL version control
2
-
3
- Utilities to ease the maintenance of MySQL or MariaDB database versioning using
4
- a Git repository.
5
-
6
- This project is just to bring an idea to life and is still in an early stage of
7
- development, so any help is welcomed! Feel free to contribute.
8
-
9
- ## Requirements
10
-
11
- * Git
12
- * Docker (Optional, used to manage local server)
13
-
14
- ## Installation
15
-
16
- It's recommended to install the package globally.
17
-
18
- ```text
19
- # npm install -g @verdnatura/myt
20
- $ myt <command>
21
- ```
22
-
23
- You can also install locally and use the *npx* command to execute it.
24
-
25
- ```text
26
- $ npm install @verdnatura/myt
27
- $ npx myt <command>
28
- ```
29
-
30
- ## How to use
31
-
32
- Execute *myt* with the desired command.
33
-
34
- ```text
35
- $ [npx] myt [-w|--workspace <string>] [-r|--remote <string>] [-d|--debug]
36
- [-h|--help] <command> [<args>]
37
- ```
38
-
39
- The default workspace directory is the current working directory and unless
40
- otherwise indicated, the default remote is *local*.
41
-
42
- Database versioning commands:
43
-
44
- * **init**: Initialize an empty workspace.
45
- * **pull**: Incorporate database routine changes into workspace.
46
- * **push**: Apply changes into database.
47
- * **version**: Creates a new version.
48
- * **create**: Creates a new routine file.
49
- * **clean**: Cleans old versions.
50
-
51
- Local server management commands:
52
-
53
- * **dump**: Export database structure and fixtures.
54
- * **fixtures**: Export local database fixtures.
55
- * **run**: Build and start local database server container.
56
- * **start**: Start local database server container.
57
-
58
- Each command can have its own specific commandline options.
59
-
60
- ## Basic information
61
-
62
- First of all you have to initalize the workspace.
63
-
64
- ```text
65
- $ myt init
66
- ```
67
-
68
- Now you can configure Myt using *myt.config.yml* file, located at the root of
69
- your workspace. This file should include the project codename and schemas/tables
70
- wich are exported when you use *pull* or *dump* commands.
71
-
72
- Don't forget to initialize git (if it isn't initialized yet).
73
-
74
- ```text
75
- $ git init
76
- ```
77
-
78
- ### Remotes
79
-
80
- Create database connection configuration for each environment at *remotes*
81
- folder using standard MySQL *ini* configuration files. The convention remote
82
- names are *local*, *production* and *test*.
83
-
84
- ```text
85
- remotes/[remote].ini
86
- ```
87
- ### Startup
88
-
89
- Once the basic configuration is done, routines can be imported from the
90
- database into the project, it is recommended to use the *production* remote.
91
-
92
- ```text
93
- $ myt pull production
94
- ```
95
-
96
- From now on, you can use the project as if it were a standard git repository
97
- (since it is). To apply changes to the database run the *push* command on the
98
- desired remote.
99
-
100
- ```text
101
- $ myt push [<remote>] [--commit]
102
- ```
103
-
104
- ### Routines
105
-
106
- Routines are placed inside *routines* folder. All objects that have PL/SQL code
107
- are considered routines. It includes events, functions, procedures, triggers
108
- and views with the following structure.
109
-
110
- ```text
111
- routines
112
- `- schema
113
- |- events
114
- | `- eventName.sql
115
- |- functions
116
- | `- functionName.sql
117
- |- procedures
118
- | `- procedureName.sql
119
- |- triggers
120
- | `- triggerName.sql
121
- `- views
122
- `- viewName.sql
123
- ```
124
-
125
- ### Versions
126
-
127
- Versions are placed inside *versions* folder with the following structure.
128
- Don't place your PL/SQL objects here, use the routines folder!
129
-
130
- ```text
131
- versions
132
- |- 00001-firstVersionCodeName
133
- | |- 00-firstExecutedScript.sql
134
- | |- 01-secondScript.sql
135
- | `- 99-lastScript.sql
136
- `- 00002-secondVersion
137
- |- 00-firstExecutedScript.sql
138
- `- 00-sameNumbers.sql
139
- ```
140
-
141
- ### Local server
142
-
143
- The local server is created as a MariaDB Docker container using the base dump
144
- created with the *dump* command plus pushing local versions and changed
145
- routines.
146
-
147
- ### Dumps
148
-
149
- You can create your local fixture and structure files.
150
-
151
- * *dump/beforeDump.sql*
152
- * *dump/afterDump.sql*
153
- * *dump/fixtures.sql*
154
-
155
- ## Versioning commands
156
-
157
- ### init
158
-
159
- Initializes an empty workspace.
160
-
161
- ```text
162
- $ myt init
163
- ```
164
-
165
- ### pull
166
-
167
- Incorporates database routine changes into workspace.
168
-
169
- ```text
170
- $ myt pull [remote] [-f|--force] [-c|--checkout] [-u|--update] [-s|--sums]
171
- ```
172
-
173
- When *--checkout* option is provided, it does the following before export:
174
-
175
- 1. Get the last database push commit (saved in versioning tables).
176
- 2. Creates and checkout to a new branch based in database commit.
177
-
178
- ### push
179
-
180
- Applies versions and routine changes into database.
181
-
182
- ```text
183
- $ myt push [<remote>] [-f|--force] [-c|--commit] [-s|--sums]
184
- ```
185
-
186
- Commit is saved into database only if *--commit* option is provided, it
187
- prevents from accidentally saving local commits into shared servers, causing
188
- subsequent pushes from other clients to fail because they can't get that
189
- commit from the git tree in order to get differences.
190
-
191
- ### version
192
-
193
- Creates a new version folder, when name is not specified it generates a random
194
- name mixing a color with a plant name.
195
-
196
- ```text
197
- $ myt version [<name>]
198
- ```
199
-
200
- ### create
201
-
202
- Creates a new routine file with a default template.
203
-
204
- ```text
205
- $ myt create [-t <type>] <schema>.<name>
206
- ```
207
-
208
- ### clean
209
-
210
- Cleans all already applied versions older than *maxOldVersions*.
211
-
212
- ```text
213
- $ myt clean
214
- ```
215
-
216
- ## Local server commands
217
-
218
- ### dump
219
-
220
- Exports database structure and fixtures from remote into hidden files located
221
- in *dump* folder. If no remote is specified *production* is used.
222
-
223
- ```text
224
- $ myt dump [<remote>] [-l|--lock]
225
- ```
226
-
227
- ### fixtures
228
-
229
- Exports local database fixtures into *dump/fixtures.sql* files. If no remote is
230
- specified *local* is used.
231
-
232
- ```text
233
- $ myt fixtures [<remote>]
234
- ```
235
-
236
- ### run
237
-
238
- Builds and starts local database server container. It only rebuilds the image
239
- when fixtures have been modified or when the day on which the image was built
240
- is different to today.
241
-
242
- ```text
243
- $ myt run [-c|--ci] [-r|--random]
244
- ```
245
-
246
- ### start
247
-
248
- Starts local database server container. It does the minium effort, if it
249
- doesn't exists calls the run command, if it is started does nothing. Keep in
250
- mind that when you do not rebuild the docker you may be using an outdated
251
- version of it.
252
-
253
- ```text
254
- $ myt start
255
- ```
256
-
257
- ## Why
258
-
259
- The main reason for starting this project it's because there are no fully free
260
- and open source migration tools available that allow versioning database
261
- routines with an standard CVS system as if they were normal application code.
262
-
263
- Also, the existing tools are too complex and require too much knowledge to
264
- start a small project.
265
-
266
- ## ToDo
267
-
268
- * Undo changes when there is an error applying a version using "undo" files.
269
- * Console logging via events.
270
- * Lock version table row when pushing.
271
- * Preserve all characteristics on pull: SQL mode, character set, algorithm...
272
-
273
- ## Built With
274
-
275
- * [Git](https://git-scm.com/)
276
- * [nodejs](https://nodejs.org/)
277
- * [NodeGit](https://www.nodegit.org/)
278
- * [docker](https://www.docker.com/)
1
+ # Myt - MySQL version control
2
+
3
+ Utilities to ease the maintenance of MySQL or MariaDB database versioning using
4
+ a Git repository.
5
+
6
+ This project is just to bring an idea to life and is still in an early stage of
7
+ development, so any help is welcomed! Feel free to contribute.
8
+
9
+ ## Requirements
10
+
11
+ * Git
12
+ * Docker (Optional, used to manage local server)
13
+
14
+ ## Installation
15
+
16
+ It's recommended to install the package globally.
17
+
18
+ ```text
19
+ # npm install -g @verdnatura/myt
20
+ $ myt <command>
21
+ ```
22
+
23
+ You can also install locally and use the *npx* command to execute it.
24
+
25
+ ```text
26
+ $ npm install @verdnatura/myt
27
+ $ npx myt <command>
28
+ ```
29
+
30
+ ## How to use
31
+
32
+ Execute *myt* with the desired command.
33
+
34
+ ```text
35
+ $ [npx] myt [-w|--workspace <string>] [-r|--remote <string>] [-d|--debug]
36
+ [-h|--help] <command> [<args>]
37
+ ```
38
+
39
+ The default workspace directory is the current working directory and unless
40
+ otherwise indicated, the default remote is *local*.
41
+
42
+ Database versioning commands:
43
+
44
+ * **init**: Initialize an empty workspace.
45
+ * **pull**: Incorporate database routine changes into workspace.
46
+ * **push**: Apply changes into database.
47
+ * **version**: Creates a new version.
48
+ * **create**: Creates a new routine file.
49
+ * **clean**: Cleans old versions.
50
+
51
+ Local server management commands:
52
+
53
+ * **dump**: Export database structure and fixtures.
54
+ * **fixtures**: Export local database fixtures.
55
+ * **run**: Build and start local database server container.
56
+ * **start**: Start local database server container.
57
+
58
+ Each command can have its own specific commandline options.
59
+
60
+ ## Basic information
61
+
62
+ First of all you have to initalize the workspace.
63
+
64
+ ```text
65
+ $ myt init
66
+ ```
67
+
68
+ Now you can configure Myt using *myt.config.yml* file, located at the root of
69
+ your workspace. This file should include the project codename and schemas/tables
70
+ wich are exported when you use *pull* or *dump* commands.
71
+
72
+ Don't forget to initialize git (if it isn't initialized yet).
73
+
74
+ ```text
75
+ $ git init
76
+ ```
77
+
78
+ ### Remotes
79
+
80
+ Create database connection configuration for each environment at *remotes*
81
+ folder using standard MySQL *ini* configuration files. The convention remote
82
+ names are *local*, *production* and *test*.
83
+
84
+ ```text
85
+ remotes/[remote].ini
86
+ ```
87
+ ### Startup
88
+
89
+ Once the basic configuration is done, routines can be imported from the
90
+ database into the project, it is recommended to use the *production* remote.
91
+
92
+ ```text
93
+ $ myt pull production
94
+ ```
95
+
96
+ From now on, you can use the project as if it were a standard git repository
97
+ (since it is). To apply changes to the database run the *push* command on the
98
+ desired remote.
99
+
100
+ ```text
101
+ $ myt push [<remote>] [--commit]
102
+ ```
103
+
104
+ ### Routines
105
+
106
+ Routines are placed inside *routines* folder. All objects that have PL/SQL code
107
+ are considered routines. It includes events, functions, procedures, triggers
108
+ and views with the following structure.
109
+
110
+ ```text
111
+ routines
112
+ `- schema
113
+ |- events
114
+ | `- eventName.sql
115
+ |- functions
116
+ | `- functionName.sql
117
+ |- procedures
118
+ | `- procedureName.sql
119
+ |- triggers
120
+ | `- triggerName.sql
121
+ `- views
122
+ `- viewName.sql
123
+ ```
124
+
125
+ ### Versions
126
+
127
+ Versions are placed inside *versions* folder with the following structure.
128
+ Don't place your PL/SQL objects here, use the routines folder!
129
+
130
+ ```text
131
+ versions
132
+ |- 00001-firstVersionCodeName
133
+ | |- 00-firstExecutedScript.sql
134
+ | |- 01-secondScript.sql
135
+ | `- 99-lastScript.sql
136
+ `- 00002-secondVersion
137
+ |- 00-firstExecutedScript.sql
138
+ `- 00-sameNumbers.sql
139
+ ```
140
+
141
+ ### Local server
142
+
143
+ The local server is created as a MariaDB Docker container using the base dump
144
+ created with the *dump* command plus pushing local versions and changed
145
+ routines.
146
+
147
+ ### Dumps
148
+
149
+ You can create your local fixture and structure files.
150
+
151
+ * *dump/beforeDump.sql*
152
+ * *dump/afterDump.sql*
153
+ * *dump/fixtures.sql*
154
+
155
+ ## Versioning commands
156
+
157
+ ### init
158
+
159
+ Initializes an empty workspace.
160
+
161
+ ```text
162
+ $ myt init
163
+ ```
164
+
165
+ ### pull
166
+
167
+ Incorporates database routine changes into workspace.
168
+
169
+ ```text
170
+ $ myt pull [remote] [-f|--force] [-c|--checkout] [-u|--update] [-s|--sums]
171
+ ```
172
+
173
+ When *--checkout* option is provided, it does the following before export:
174
+
175
+ 1. Get the last database push commit (saved in versioning tables).
176
+ 2. Creates and checkout to a new branch based in database commit.
177
+
178
+ ### push
179
+
180
+ Applies versions and routine changes into database.
181
+
182
+ ```text
183
+ $ myt push [<remote>] [-f|--force] [-c|--commit] [-s|--sums]
184
+ ```
185
+
186
+ Commit is saved into database only if *--commit* option is provided, it
187
+ prevents from accidentally saving local commits into shared servers, causing
188
+ subsequent pushes from other clients to fail because they can't get that
189
+ commit from the git tree in order to get differences.
190
+
191
+ ### version
192
+
193
+ Creates a new version folder, when name is not specified it generates a random
194
+ name mixing a color with a plant name.
195
+
196
+ ```text
197
+ $ myt version [<name>]
198
+ ```
199
+
200
+ ### create
201
+
202
+ Creates a new routine file with a default template.
203
+
204
+ ```text
205
+ $ myt create [-t <type>] <schema>.<name>
206
+ ```
207
+
208
+ ### clean
209
+
210
+ Cleans all already applied versions older than *maxOldVersions*.
211
+
212
+ ```text
213
+ $ myt clean
214
+ ```
215
+
216
+ ## Local server commands
217
+
218
+ ### dump
219
+
220
+ Exports database structure and fixtures from remote into hidden files located
221
+ in *dump* folder. If no remote is specified *production* is used.
222
+
223
+ ```text
224
+ $ myt dump [<remote>] [-l|--lock]
225
+ ```
226
+
227
+ ### fixtures
228
+
229
+ Exports local database fixtures into *dump/fixtures.sql* files. If no remote is
230
+ specified *local* is used.
231
+
232
+ ```text
233
+ $ myt fixtures [<remote>]
234
+ ```
235
+
236
+ ### run
237
+
238
+ Builds and starts local database server container. It only rebuilds the image
239
+ when fixtures have been modified or when the day on which the image was built
240
+ is different to today.
241
+
242
+ ```text
243
+ $ myt run [-c|--ci] [-r|--random]
244
+ ```
245
+
246
+ ### start
247
+
248
+ Starts local database server container. It does the minium effort, if it
249
+ doesn't exists calls the run command, if it is started does nothing. Keep in
250
+ mind that when you do not rebuild the docker you may be using an outdated
251
+ version of it.
252
+
253
+ ```text
254
+ $ myt start
255
+ ```
256
+
257
+ ## Why
258
+
259
+ The main reason for starting this project it's because there are no fully free
260
+ and open source migration tools available that allow versioning database
261
+ routines with an standard CVS system as if they were normal application code.
262
+
263
+ Also, the existing tools are too complex and require too much knowledge to
264
+ start a small project.
265
+
266
+ ## ToDo
267
+
268
+ * Undo changes when there is an error applying a version using "undo" files.
269
+ * Console logging via events.
270
+ * Lock version table row when pushing.
271
+ * Preserve all characteristics on pull: SQL mode, character set, algorithm...
272
+
273
+ ## Built With
274
+
275
+ * [Git](https://git-scm.com/)
276
+ * [nodejs](https://nodejs.org/)
277
+ * [NodeGit](https://www.nodegit.org/)
278
+ * [docker](https://www.docker.com/)
package/assets/db.ini CHANGED
@@ -1,5 +1,5 @@
1
- [client]
2
- host = localhost
3
- port = 3306
4
- user = root
5
- password = root
1
+ [client]
2
+ host = localhost
3
+ port = 3306
4
+ user = root
5
+ password = root
@@ -1,11 +1,11 @@
1
- versionSchema: myt
2
- versionDigits: 5
3
- maxOldVersions: 20
4
- mockDate: false
5
- sumViews: true
6
- schemas:
7
- - myt
8
- fixtures:
9
- myt:
10
- - version
11
- - versionLog
1
+ versionSchema: myt
2
+ versionDigits: 5
3
+ maxOldVersions: 20
4
+ mockDate: false
5
+ sumViews: true
6
+ schemas:
7
+ - myt
8
+ fixtures:
9
+ myt:
10
+ - version
11
+ - versionLog
@@ -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`);