Bugs fixed
This commit is contained in:
parent
b08617d77e
commit
b132a8b42e
|
@ -38,7 +38,7 @@ class Dump {
|
||||||
|
|
||||||
await docker.build(__dirname, {
|
await docker.build(__dirname, {
|
||||||
tag: 'myvc/client',
|
tag: 'myvc/client',
|
||||||
file: path.join(__dirname, 'server', 'Dockerfile')
|
file: path.join(__dirname, 'server', 'Dockerfile.client')
|
||||||
}, opts.debug);
|
}, opts.debug);
|
||||||
|
|
||||||
let dumpArgs = [
|
let dumpArgs = [
|
||||||
|
|
|
@ -31,10 +31,10 @@ class Push {
|
||||||
+ `\n -> Commit: ${version.gitCommit}`
|
+ `\n -> Commit: ${version.gitCommit}`
|
||||||
);
|
);
|
||||||
|
|
||||||
if (!/^[0-9]*$/.test(version.number))
|
|
||||||
throw new Error('Wrong database version');
|
|
||||||
if (!version.number)
|
if (!version.number)
|
||||||
version.number = '00000';
|
version.number = '00000';
|
||||||
|
if (!/^[0-9]*$/.test(version.number))
|
||||||
|
throw new Error('Wrong database version');
|
||||||
|
|
||||||
if (opts.user) {
|
if (opts.user) {
|
||||||
const [[user]] = conn.query(
|
const [[user]] = conn.query(
|
||||||
|
@ -217,8 +217,9 @@ class Push {
|
||||||
|
|
||||||
parseChanges(changes) {
|
parseChanges(changes) {
|
||||||
const routines = [];
|
const routines = [];
|
||||||
for (const change of changes)
|
if (changes)
|
||||||
routines.push(new Routine(change));
|
for (const change of changes)
|
||||||
|
routines.push(new Routine(change));
|
||||||
return routines;
|
return routines;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -27,6 +27,10 @@ class Run {
|
||||||
|
|
||||||
async run(myvc, opts) {
|
async run(myvc, opts) {
|
||||||
const dumpDir = `${opts.workspace}/dump`;
|
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`;
|
const dumpInfo = `${dumpDir}/.dump.json`;
|
||||||
|
|
||||||
if (await fs.pathExists(dumpInfo)) {
|
if (await fs.pathExists(dumpInfo)) {
|
||||||
|
@ -46,7 +50,6 @@ class Run {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!isEqual) {
|
if (!isEqual) {
|
||||||
console.log('not equal');
|
|
||||||
const fd = await fs.open(`${dumpDir}/.changes`, 'w+');
|
const fd = await fs.open(`${dumpDir}/.changes`, 'w+');
|
||||||
for (const change of changes)
|
for (const change of changes)
|
||||||
fs.write(fd, change.mark + change.path + '\n');
|
fs.write(fd, change.mark + change.path + '\n');
|
||||||
|
|
46
myvc.js
46
myvc.js
|
@ -131,6 +131,7 @@ class MyVC {
|
||||||
user: iniConfig.user,
|
user: iniConfig.user,
|
||||||
password: iniConfig.password,
|
password: iniConfig.password,
|
||||||
database: opts.versionSchema,
|
database: opts.versionSchema,
|
||||||
|
multipleStatements: true,
|
||||||
authPlugins: {
|
authPlugins: {
|
||||||
mysql_clear_password() {
|
mysql_clear_password() {
|
||||||
return () => iniConfig.password + '\0';
|
return () => iniConfig.password + '\0';
|
||||||
|
@ -194,28 +195,34 @@ class MyVC {
|
||||||
return version;
|
return version;
|
||||||
}
|
}
|
||||||
|
|
||||||
async changedRoutines(commit) {
|
async changedRoutines(commitSha) {
|
||||||
const repo = await nodegit.Repository.open(this.opts.workspace);
|
const {opts} = this;
|
||||||
|
|
||||||
const from = await repo.getCommit(commit);
|
if (!await fs.pathExists(`${opts.workspace}/.git`))
|
||||||
const fromTree = await from.getTree();
|
throw new Error ('Git not initialized');
|
||||||
|
|
||||||
const to = await repo.getHeadCommit();
|
|
||||||
const toTree = await to.getTree();
|
|
||||||
|
|
||||||
const diff = await toTree.diff(fromTree);
|
|
||||||
const patches = await diff.patches();
|
|
||||||
|
|
||||||
const changes = [];
|
const changes = [];
|
||||||
for (const patch of patches) {
|
const repo = await nodegit.Repository.open(opts.workspace);
|
||||||
const path = patch.newFile().path();
|
const head = await repo.getHeadCommit();
|
||||||
const match = path.match(/^routines\/(.+)\.sql$/);
|
|
||||||
if (!match) continue;
|
|
||||||
|
|
||||||
changes.push({
|
if (head && commitSha) {
|
||||||
mark: patch.isDeleted() ? '-' : '+',
|
const commit = await repo.getCommit(commitSha);
|
||||||
path: match[1]
|
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(
|
return changes.sort(
|
||||||
|
@ -224,7 +231,6 @@ class MyVC {
|
||||||
}
|
}
|
||||||
|
|
||||||
async cachedChanges() {
|
async cachedChanges() {
|
||||||
const changes = [];
|
|
||||||
const dumpDir = `${this.opts.workspace}/dump`;
|
const dumpDir = `${this.opts.workspace}/dump`;
|
||||||
const dumpChanges = `${dumpDir}/.changes`;
|
const dumpChanges = `${dumpDir}/.changes`;
|
||||||
|
|
||||||
|
@ -238,13 +244,13 @@ class MyVC {
|
||||||
console: false
|
console: false
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const changes = [];
|
||||||
for await (const line of rl) {
|
for await (const line of rl) {
|
||||||
changes.push({
|
changes.push({
|
||||||
mark: line.charAt(0),
|
mark: line.charAt(0),
|
||||||
path: line.substr(1)
|
path: line.substr(1)
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
return changes;
|
return changes;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "myvc",
|
"name": "myvc",
|
||||||
"version": "1.1.4",
|
"version": "1.1.5",
|
||||||
"author": "Verdnatura Levante SL",
|
"author": "Verdnatura Levante SL",
|
||||||
"description": "MySQL Version Control",
|
"description": "MySQL Version Control",
|
||||||
"license": "GPL-3.0",
|
"license": "GPL-3.0",
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
|
|
||||||
CREATE TABLE `version` (
|
CREATE TABLE `version` (
|
||||||
`code` varchar(255) NOT NULL,
|
`code` varchar(255) NOT NULL,
|
||||||
`number` char(11) NOT NULL,
|
`number` char(11) NULL,
|
||||||
`gitCommit` varchar(255) NOT NULL,
|
`gitCommit` varchar(255) NULL,
|
||||||
`updated` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
|
`updated` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
|
||||||
) ENGINE=InnoDB;
|
) ENGINE=InnoDB;
|
||||||
|
|
||||||
|
@ -12,8 +12,8 @@ ALTER TABLE `version`
|
||||||
CREATE TABLE `versionUser` (
|
CREATE TABLE `versionUser` (
|
||||||
`code` varchar(255) NOT NULL,
|
`code` varchar(255) NOT NULL,
|
||||||
`user` varchar(255) NOT NULL,
|
`user` varchar(255) NOT NULL,
|
||||||
`number` char(11) NOT NULL,
|
`number` char(11) NULL,
|
||||||
`gitCommit` varchar(255) NOT NULL,
|
`gitCommit` varchar(255) NULL,
|
||||||
`updated` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
|
`updated` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
|
||||||
) ENGINE=InnoDB;
|
) ENGINE=InnoDB;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue