refs #4036 sumViews option, sum & template fixes
This commit is contained in:
parent
2f31d0f98e
commit
021e3cb083
|
@ -1,6 +1,7 @@
|
|||
versionSchema: myt
|
||||
versionDigits: 5
|
||||
maxOldVersions: 30
|
||||
sumViews: true
|
||||
schemas:
|
||||
- myt
|
||||
fixtures:
|
||||
|
|
10
myt-dump.js
10
myt-dump.js
|
@ -52,16 +52,6 @@ class Dump extends Command {
|
|||
}
|
||||
|
||||
await dumper.end();
|
||||
|
||||
console.log('Saving version.');
|
||||
await myt.dbConnect();
|
||||
const version = await myt.fetchDbVersion();
|
||||
if (version) {
|
||||
await fs.writeFile(
|
||||
`${opts.dumpDir}/.dump.json`,
|
||||
JSON.stringify(version)
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
18
myt-init.js
18
myt-init.js
|
@ -1,6 +1,7 @@
|
|||
const Myt = require('./myt');
|
||||
const Command = require('./lib/command');
|
||||
const fs = require('fs-extra');
|
||||
const path = require('path');
|
||||
|
||||
class Init extends Command {
|
||||
static usage = {
|
||||
|
@ -8,12 +9,23 @@ class Init extends Command {
|
|||
};
|
||||
|
||||
async run(myt, opts) {
|
||||
const templateDir = `${__dirname}/template`;
|
||||
const packageFile = path.join(opts.mytDir, 'package.json');
|
||||
const packageExists = await fs.pathExists(packageFile);
|
||||
|
||||
const templateDir = path.join(__dirname, 'template');
|
||||
const templates = await fs.readdir(templateDir);
|
||||
for (let template of templates) {
|
||||
const dst = `${opts.mytDir}/${template}`;
|
||||
const dst = path.join(opts.mytDir, template);
|
||||
if (!await fs.pathExists(dst))
|
||||
await fs.copy(`${templateDir}/${template}`, dst);
|
||||
await fs.copy(path.join(templateDir, template), dst);
|
||||
}
|
||||
|
||||
if (!packageExists) {
|
||||
const packageJson = require(packageFile);
|
||||
packageJson.dependencies[myt.packageJson.name] =
|
||||
`^${myt.packageJson.version}`;
|
||||
await fs.writeFile(packageFile,
|
||||
JSON.stringify(packageJson, null, ' '));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
15
myt-pull.js
15
myt-pull.js
|
@ -127,7 +127,9 @@ class Pull extends Command {
|
|||
const res = await exporter.query(conn, schema);
|
||||
if (!res.length) return;
|
||||
|
||||
const routineDir = `${opts.routinesDir}/${schema}/${exporter.objectType}s`;
|
||||
const type = exporter.objectType;
|
||||
|
||||
const routineDir = `${opts.routinesDir}/${schema}/${type}s`;
|
||||
if (!await fs.pathExists(routineDir))
|
||||
await fs.mkdir(routineDir);
|
||||
|
||||
|
@ -140,8 +142,10 @@ class Pull extends Command {
|
|||
const match = routineFile.match(/^(.*)\.sql$/);
|
||||
if (!match) continue;
|
||||
const routine = match[1];
|
||||
if (!routineSet.has(routine))
|
||||
if (!routineSet.has(routine)) {
|
||||
await fs.remove(`${routineDir}/${routine}.sql`);
|
||||
engine.deleteShaSum(type, schema, routine)
|
||||
}
|
||||
}
|
||||
|
||||
for (const params of res) {
|
||||
|
@ -150,12 +154,11 @@ class Pull extends Command {
|
|||
const routineFile = `${routineDir}/${routineName}.sql`;
|
||||
let update = opts.update;
|
||||
|
||||
const oldSum = engine.getShaSum(routineName);
|
||||
if (oldSum || opts.sums) {
|
||||
const oldSum = engine.getShaSum(type, schema, routineName);
|
||||
if (oldSum || opts.sums || (opts.sumViews && type === 'view')) {
|
||||
const shaSum = engine.shaSum(sql);
|
||||
if (oldSum !== shaSum) {
|
||||
engine.setShaSum(
|
||||
exporter.objectType, schema, routineName, shaSum);
|
||||
engine.setShaSum(type, schema, routineName, shaSum);
|
||||
update = true;
|
||||
}
|
||||
} else if (params.modified && engine.lastPull) {
|
||||
|
|
|
@ -349,7 +349,7 @@ class Push extends Command {
|
|||
);
|
||||
}
|
||||
|
||||
if (opts.sums || oldSum)
|
||||
if (opts.sums || oldSum || (opts.sumViews && type === 'view'))
|
||||
await engine.fetchShaSum(type, schema, name);
|
||||
} else {
|
||||
const escapedName =
|
||||
|
|
1
myt.js
1
myt.js
|
@ -45,6 +45,7 @@ class Myt {
|
|||
'Myt'.green,
|
||||
`v${packageJson.version}`.magenta
|
||||
);
|
||||
this.packageJson = packageJson;
|
||||
|
||||
let baseOpts = this.constructor.opts;
|
||||
baseOpts.default = Object.assign(baseOpts.default || {}, {
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
{
|
||||
"name": "@verdnatura/myt",
|
||||
"version": "1.5.8",
|
||||
"version": "1.5.9",
|
||||
"lockfileVersion": 2,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "@verdnatura/myt",
|
||||
"version": "1.5.8",
|
||||
"version": "1.5.9",
|
||||
"license": "GPL-3.0",
|
||||
"dependencies": {
|
||||
"@sqltools/formatter": "^1.2.5",
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "@verdnatura/myt",
|
||||
"version": "1.5.8",
|
||||
"version": "1.5.9",
|
||||
"author": "Verdnatura Levante SL",
|
||||
"description": "MySQL version control",
|
||||
"license": "GPL-3.0",
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
FROM mariadb:10.7
|
|
@ -0,0 +1 @@
|
|||
-- Executed after data dump
|
|
@ -0,0 +1 @@
|
|||
-- Executed before data dump
|
|
@ -1 +0,0 @@
|
|||
-- Place your local structure changes here
|
|
@ -8,6 +8,6 @@
|
|||
"type": "git"
|
||||
},
|
||||
"dependencies": {
|
||||
"@verdnatura/myt": "^1.5.8"
|
||||
"@verdnatura/myt": "^1.0.0"
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue