@verdnatura/myt 1.5.22 → 1.5.23

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/README.md CHANGED
@@ -64,7 +64,7 @@ Each command can have its own specific commandline options.
64
64
 
65
65
  ## Basic information
66
66
 
67
- First of all you have to initalize the workspace.
67
+ First of all you have to initialize the workspace.
68
68
 
69
69
  ```text
70
70
  $ myt init
@@ -72,7 +72,7 @@ $ myt init
72
72
 
73
73
  Now you can configure Myt using *myt.config.yml* file, located at the root of
74
74
  your workspace. This file should include the project codename and schemas/tables
75
- wich are exported when you use *pull* or *dump* commands.
75
+ which are exported when you use *pull* or *dump* commands.
76
76
 
77
77
  Don't forget to initialize git (if it isn't initialized yet).
78
78
 
@@ -143,6 +143,38 @@ Don't place your PL/SQL objects here, use the routines folder!
143
143
  `- 00-sameNumbers.sql
144
144
  ```
145
145
 
146
+ ### Environment-Specific Versioning with Realms
147
+
148
+ #### Overview
149
+
150
+ We have introduced a new feature that allows users to apply version-specific changes based on their configured environment, or "realm". This ensures that certain changes are only applied when the user is operating within a specific realm, providing an additional layer of customization and control.
151
+
152
+ #### Configuration
153
+
154
+ To make use of this feature, you need to configure your realm in the `versionConfig` table. Set your realm by inserting or updating a record in this table. The `realm` field should contain the identifier of your environment.
155
+
156
+ #### File Naming Convention
157
+
158
+ To designate a file as realm-specific, include a `.your_realm.` segment before the file extension. For example, if your realm is set to 'ab', the file should be named like this: `filename.ab.sql`.
159
+
160
+ #### How It Works
161
+
162
+ 1. **Set your Realm**: Configure your realm in the `versionConfig` table.
163
+
164
+ 2. **Add Files**: Place your realm-specific files in the `versions` folder. Make sure to follow the naming convention.
165
+
166
+ 3. **Version Order**: Files are applied in the existing version order. In addition to that, the realm is validated.
167
+
168
+ 4. **Apply Changes**: Run the usual versioning commands. The realm-specific files will only be applied if your configured realm matches the realm in the file name.
169
+
170
+ #### Important Notes
171
+
172
+ - If no realm is configured, realm-specific files will be ignored.
173
+
174
+ - If you have a realm configured but the realm-specific files belong to a different realm, those files will also be ignored.
175
+
176
+ This feature allows for greater flexibility when working in different environments, making it easier to manage realm-specific changes in a shared repository.
177
+
146
178
  ### Local server
147
179
 
148
180
  The local server is created as a MariaDB Docker container using the base dump
@@ -169,6 +201,7 @@ Initializes an empty workspace.
169
201
  $ myt init
170
202
  ```
171
203
 
204
+
172
205
  ### pull
173
206
 
174
207
  Incorporates database routine changes into workspace.
@@ -263,14 +296,14 @@ $ myt start
263
296
 
264
297
  ## Why
265
298
 
266
- The main reason for starting this project it's because there are no fully free
299
+ The main reason for starting this project is because there are no fully free
267
300
  and open source migration tools available that allow versioning database
268
- routines with an standard CVS system as if they were normal application code.
301
+ routines with a standard CVS system as if they were normal application code.
269
302
 
270
303
  Also, the existing tools are too complex and require too much knowledge to
271
- start a small project.
304
+ initiate a small project.
272
305
 
273
- ## ToDo
306
+ ## To-Do
274
307
 
275
308
  * Undo changes when there is an error applying a version using "undo" files.
276
309
  * Console logging via events.
@@ -280,6 +313,6 @@ start a small project.
280
313
  ## Built With
281
314
 
282
315
  * [Git](https://git-scm.com/)
283
- * [nodejs](https://nodejs.org/)
316
+ * [Node.js](https://nodejs.org/)
284
317
  * [NodeGit](https://www.nodegit.org/)
285
- * [docker](https://www.docker.com/)
318
+ * [Docker](https://www.docker.com/)
@@ -22,3 +22,8 @@ CREATE TABLE `versionLog` (
22
22
 
23
23
  ALTER TABLE `versionLog`
24
24
  ADD PRIMARY KEY (`code`,`number`,`file`);
25
+
26
+ CREATE TABLE `util`.`versionConfig` (
27
+ `id` INT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
28
+ `realm` VARCHAR(16) NULL DEFAULT NULL COMMENT 'Data set on which the project runs'
29
+ ) ENGINE=InnoDB;
package/myt-push.js CHANGED
@@ -151,7 +151,7 @@ class Push extends Command {
151
151
  function isUndoScript(script) {
152
152
  return /\.undo\.sql$/.test(script);
153
153
  }
154
-
154
+
155
155
  const skipFiles = new Set([
156
156
  'README.md',
157
157
  '.archive'
@@ -159,6 +159,10 @@ class Push extends Command {
159
159
 
160
160
  if (await fs.pathExists(versionsDir)) {
161
161
  const versionDirs = await fs.readdir(versionsDir);
162
+ const [[realm]] = await this.conn.query(
163
+ `SELECT realm
164
+ FROM versionConfig`
165
+ );
162
166
 
163
167
  for (const versionDir of versionDirs) {
164
168
  if (skipFiles.has(versionDir)) continue;
@@ -203,11 +207,16 @@ class Push extends Command {
203
207
  logVersion(`[${versionNumber}]`.cyan, versionName);
204
208
 
205
209
  for (const script of scripts) {
206
- if (!/^[0-9]{2}-[a-zA-Z0-9_]+(.undo)?\.sql$/.test(script)) {
210
+ const match = script.match(/^[0-9]{2}-[a-zA-Z0-9_]+(?:\.(?!undo)([a-zA-Z0-9_]+))?(?:\.undo)?\.sql$/);
211
+
212
+ if (!match) {
207
213
  logScript('[W]'.yellow, script, `Wrong file name.`);
208
214
  continue;
209
215
  }
210
- if (isUndoScript(script))
216
+
217
+ const skipRealm = match[1] && match[1] !== realm;
218
+
219
+ if (isUndoScript(script) || skipRealm)
211
220
  continue;
212
221
 
213
222
  const [[row]] = await conn.query(
package/myt.js CHANGED
@@ -172,7 +172,7 @@ class Myt {
172
172
 
173
173
  const defaultConfig = require(`${__dirname}/assets/myt.default.yml`);
174
174
  const config = Object.assign({}, defaultConfig);
175
-
175
+
176
176
  const configFile = 'myt.config.yml';
177
177
  const configPath = path.join(opts.workspace, configFile);
178
178
 
@@ -205,7 +205,7 @@ class Myt {
205
205
  opts.dumpDir = path.join(opts.mytDir, 'dump');
206
206
 
207
207
  // Database configuration
208
-
208
+
209
209
  let iniDir = path.join(__dirname, 'assets');
210
210
  let iniFile = 'db.ini';
211
211
 
@@ -214,10 +214,10 @@ class Myt {
214
214
  iniFile = `${opts.remote}.ini`;
215
215
  }
216
216
  const iniPath = path.join(iniDir, iniFile);
217
-
217
+
218
218
  if (!await fs.pathExists(iniPath))
219
219
  throw new Error(`Database config file not found: ${iniPath}`);
220
-
220
+
221
221
  let dbConfig;
222
222
  try {
223
223
  const iniData = ini.parse(await fs.readFile(iniPath, 'utf8')).client;
@@ -299,7 +299,7 @@ class Myt {
299
299
  AND TABLE_NAME = 'version'`,
300
300
  [opts.versionSchema]
301
301
  );
302
-
302
+
303
303
  if (!res.tableExists) {
304
304
  const structure = await fs.readFile(
305
305
  `${__dirname}/assets/structure.sql`, 'utf8');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@verdnatura/myt",
3
- "version": "1.5.22",
3
+ "version": "1.5.23",
4
4
  "author": "Verdnatura Levante SL",
5
5
  "description": "MySQL version control",
6
6
  "license": "GPL-3.0",