Bugs fixed

This commit is contained in:
Juan Ferrer 2020-12-05 22:50:45 +01:00
parent b08617d77e
commit b132a8b42e
6 changed files with 41 additions and 31 deletions

View File

@ -38,7 +38,7 @@ class Dump {
await docker.build(__dirname, {
tag: 'myvc/client',
file: path.join(__dirname, 'server', 'Dockerfile')
file: path.join(__dirname, 'server', 'Dockerfile.client')
}, opts.debug);
let dumpArgs = [

View File

@ -31,10 +31,10 @@ class Push {
+ `\n -> Commit: ${version.gitCommit}`
);
if (!/^[0-9]*$/.test(version.number))
throw new Error('Wrong database version');
if (!version.number)
version.number = '00000';
if (!/^[0-9]*$/.test(version.number))
throw new Error('Wrong database version');
if (opts.user) {
const [[user]] = conn.query(
@ -217,8 +217,9 @@ class Push {
parseChanges(changes) {
const routines = [];
for (const change of changes)
routines.push(new Routine(change));
if (changes)
for (const change of changes)
routines.push(new Routine(change));
return routines;
}

View File

@ -27,6 +27,10 @@ class Run {
async run(myvc, opts) {
const dumpDir = `${opts.workspace}/dump`;
if (!await fs.pathExists(`${dumpDir}/.dump.sql`))
throw new Error('To run local database you have to create a dump first');
const dumpInfo = `${dumpDir}/.dump.json`;
if (await fs.pathExists(dumpInfo)) {
@ -46,7 +50,6 @@ class Run {
}
if (!isEqual) {
console.log('not equal');
const fd = await fs.open(`${dumpDir}/.changes`, 'w+');
for (const change of changes)
fs.write(fd, change.mark + change.path + '\n');

46
myvc.js
View File

@ -131,6 +131,7 @@ class MyVC {
user: iniConfig.user,
password: iniConfig.password,
database: opts.versionSchema,
multipleStatements: true,
authPlugins: {
mysql_clear_password() {
return () => iniConfig.password + '\0';
@ -194,28 +195,34 @@ class MyVC {
return version;
}
async changedRoutines(commit) {
const repo = await nodegit.Repository.open(this.opts.workspace);
async changedRoutines(commitSha) {
const {opts} = this;
const from = await repo.getCommit(commit);
const fromTree = await from.getTree();
const to = await repo.getHeadCommit();
const toTree = await to.getTree();
const diff = await toTree.diff(fromTree);
const patches = await diff.patches();
if (!await fs.pathExists(`${opts.workspace}/.git`))
throw new Error ('Git not initialized');
const changes = [];
for (const patch of patches) {
const path = patch.newFile().path();
const match = path.match(/^routines\/(.+)\.sql$/);
if (!match) continue;
const repo = await nodegit.Repository.open(opts.workspace);
const head = await repo.getHeadCommit();
changes.push({
mark: patch.isDeleted() ? '-' : '+',
path: match[1]
});
if (head && commitSha) {
const commit = await repo.getCommit(commitSha);
const commitTree = await commit.getTree();
const headTree = await head.getTree();
const diff = await headTree.diff(commitTree);
const patches = await diff.patches();
for (const patch of patches) {
const path = patch.newFile().path();
const match = path.match(/^routines\/(.+)\.sql$/);
if (!match) continue;
changes.push({
mark: patch.isDeleted() ? '-' : '+',
path: match[1]
});
}
}
return changes.sort(
@ -224,7 +231,6 @@ class MyVC {
}
async cachedChanges() {
const changes = [];
const dumpDir = `${this.opts.workspace}/dump`;
const dumpChanges = `${dumpDir}/.changes`;
@ -238,13 +244,13 @@ class MyVC {
console: false
});
const changes = [];
for await (const line of rl) {
changes.push({
mark: line.charAt(0),
path: line.substr(1)
});
}
return changes;
}
}

View File

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

View File

@ -1,8 +1,8 @@
CREATE TABLE `version` (
`code` varchar(255) NOT NULL,
`number` char(11) NOT NULL,
`gitCommit` varchar(255) NOT NULL,
`number` char(11) NULL,
`gitCommit` varchar(255) NULL,
`updated` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
) ENGINE=InnoDB;
@ -12,8 +12,8 @@ ALTER TABLE `version`
CREATE TABLE `versionUser` (
`code` varchar(255) NOT NULL,
`user` varchar(255) NOT NULL,
`number` char(11) NOT NULL,
`gitCommit` varchar(255) NOT NULL,
`number` char(11) NULL,
`gitCommit` varchar(255) NULL,
`updated` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
) ENGINE=InnoDB;