Compare commits

..

4 Commits

6 changed files with 1361 additions and 9 deletions

View File

@ -191,6 +191,23 @@ You can create your local fixture and structure files.
* *dump/fixtures.after.sql* * *dump/fixtures.after.sql*
* *dump/fixtures.local.sql* * *dump/fixtures.local.sql*
### Realms
You can create your local realms folders.
```text
dump
`- realms
|- marvel
| `- 00-spiderman.sql
| `- 01-hulk.sql
`- dc
`- 00-superman.sql
`- 01-batman.sql
`- 02-wonder_woman.sql
`- 03-flash.sql
```
## Versioning commands ## Versioning commands
### init ### init
@ -279,7 +296,7 @@ Builds and starts local database server container. It only rebuilds the image
when dump have been modified. when dump have been modified.
```text ```text
$ myt run [-c|--ci] [-r|--random] [-t|--tmpfs] [-n|--network <string>] $ myt run [-c|--ci] [-r|--random] [-t|--tmpfs] [-n|--network <string>] [--realm <string>]
``` ```
### start ### start

View File

@ -47,6 +47,7 @@ class Run extends Command {
waitingDb: 'Waiting for MySQL init process.', waitingDb: 'Waiting for MySQL init process.',
mockingDate: 'Mocking date functions.', mockingDate: 'Mocking date functions.',
applyingFixtures: 'Applying fixtures.', applyingFixtures: 'Applying fixtures.',
applyingRealms: (realm) => console.log(`Applying '${realm}' realm fixtures.`),
creatingTriggers: 'Creating triggers.' creatingTriggers: 'Creating triggers.'
}; };
@ -185,11 +186,19 @@ class Run extends Command {
] ]
for (const file of fixturesFiles) { for (const file of fixturesFiles) {
if (!await fs.exists(`${dumpDir}/${file}.sql`)) continue; if (!await fs.exists(`${dumpDir}/${file}.sql`)) continue;
await ct.exec(null, 'docker-import.sh', await execFile(`dump/${file}`)
[`/workspace/dump/${file}`], }
'spawn',
true // Apply realms
);
if(opts.realm) {
this.emit('applyingRealms', opts.realm);
const realmDir = `realms/${opts.realm}`;
let realmFiles = await fs.readdir(`${dumpDir}/${realmDir}`);
realmFiles = realmFiles.map(file => path.parse(file).name);
for (const file of realmFiles) {
await execFile(`${realmDir}/${file}`)
}
} }
// Create triggers // Create triggers
@ -216,6 +225,14 @@ class Run extends Command {
} catch (e) {} } catch (e) {}
throw err; throw err;
} }
async function execFile(path){
await ct.exec(null, 'docker-import.sh',
[`/workspace/${path}` ],
'spawn',
true
);
}
} }
} }

3
myt.js
View File

@ -21,7 +21,8 @@ class Myt {
workspace: 'The base directory of the project', workspace: 'The base directory of the project',
debug: 'Whether to enable debug mode', debug: 'Whether to enable debug mode',
version: 'Display the version number and exit', version: 'Display the version number and exit',
help: 'Display this help message' help: 'Display this help message',
realm: 'Name of fixture realm to use',
} }
}; };

View File

@ -1,6 +1,6 @@
{ {
"name": "@verdnatura/myt", "name": "@verdnatura/myt",
"version": "1.6.13", "version": "1.6.14",
"author": "Verdnatura Levante SL", "author": "Verdnatura Levante SL",
"description": "MySQL version control", "description": "MySQL version control",
"license": "GPL-3.0", "license": "GPL-3.0",

1316
pnpm-lock.yaml Normal file

File diff suppressed because it is too large Load Diff

View File

@ -12,3 +12,4 @@ RUN echo "[LOG] Import finished." \
&& rm -rf dump && rm -rf dump
COPY fixtures.*.sql dump/ COPY fixtures.*.sql dump/
COPY realms realms/