Pull only overwrites modified routines

This commit is contained in:
Juan Ferrer 2020-12-19 02:06:06 +01:00
parent 9b3f795dce
commit fca2d471b1
3 changed files with 37 additions and 9 deletions

View File

@ -153,9 +153,11 @@ the following steps:
6. Merge the new branch into.
7. Let the user deal with merge conflicts.
Furthermore, migrate all possible tools and code from shell scripts to native
Javascript, dealing with dependencies and compatibility issues between various
OS that this may cause.
Use a custom *Dockerfile* for local database container.
Allow to specify a custom workspece subdirectory inside project directory.
Create a lock during push to avoid collisions.
## Built With

View File

@ -11,10 +11,15 @@ class Pull {
await exporter.init();
const exportDir = `${opts.workspace}/routines`;
if (await fs.pathExists(exportDir))
await fs.remove(exportDir, {recursive: true});
if (!await fs.pathExists(exportDir))
await fs.mkdir(exportDir);
const schemas = await fs.readdir(exportDir);
for (const schema of schemas) {
if (opts.schemas.indexOf(schema) == -1)
await fs.remove(`${exportDir}/${schema}`, {recursive: true});
}
for (const schema of opts.schemas) {
let schemaDir = `${exportDir}/${schema}`;
@ -52,13 +57,34 @@ class Exporter {
if (!await fs.pathExists(routineDir))
await fs.mkdir(routineDir);
const routineSet = new Set();
for (const params of res)
routineSet.add(params.name);
const routines = await fs.readdir(routineDir);
for (const routineFile of routines) {
const match = routineFile.match(/^(.*)\.sql$/);
if (!match) continue;
const routine = match[1];
if (!routineSet.has(routine))
await fs.remove(`${routineDir}/${routine}.sql`);
}
for (const params of res) {
if (this.formatter)
this.formatter(params, schema)
params.schema = schema;
let sql = this.template(params);
await fs.writeFile(`${routineDir}/${params.name}.sql`, sql);
const sql = this.template(params);
const routineFile = `${routineDir}/${params.name}.sql`;
let changed = true;
if (await fs.pathExists(routineFile)) {
const currentSql = await fs.readFile(routineFile, 'utf8');
changed = currentSql !== sql;
}
if (changed)
await fs.writeFile(routineFile, sql);
}
}
}

View File

@ -1,6 +1,6 @@
{
"name": "myvc",
"version": "1.1.6",
"version": "1.1.7",
"author": "Verdnatura Levante SL",
"description": "MySQL Version Control",
"license": "GPL-3.0",