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