fixes #6204 tested code

This commit is contained in:
Javi Gallego 2023-09-22 10:25:06 +02:00
parent 11a57b8168
commit 38aec90073
3 changed files with 28 additions and 13 deletions

View File

@ -22,3 +22,8 @@ CREATE TABLE `versionLog` (
ALTER TABLE `versionLog`
ADD PRIMARY KEY (`code`,`number`,`file`);
CREATE TABLE `util`.`versionConfig` (
`id` INT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
`realm` VARCHAR(16) NULL DEFAULT NULL COMMENT 'Data set on which the project runs'
) ENGINE=InnoDB;

View File

@ -151,19 +151,19 @@ class Push extends Command {
function isUndoScript(script) {
return /\.undo\.sql$/.test(script);
}
function isOtherEnvScript(script, env) {
function isOtherRealmScript(script, realm) {
const splitScript = script.split('.');
const envPart = splitScript[splitScript.length - 2];
const realmPart = splitScript[splitScript.length - 2];
if (splitScript.length <= 2) {
return false;
}
if (!env) {
return !!envPart;
if (!realm) {
return !!realmPart;
}
return envPart && envPart !== env;
return realmPart && realmPart !== realm;
}
@ -207,6 +207,8 @@ class Push extends Command {
[opts.code, versionNumber]
);
const realm = await myt.fetchDbRealm();
for (const script of scripts)
if (!isUndoScript(script)
&& versionLog.findIndex(x => x.file == script) === -1) {
@ -218,14 +220,14 @@ class Push extends Command {
logVersion(`[${versionNumber}]`.cyan, versionName);
for (const script of scripts) {
if (!/^[0-9]{2}-[a-zA-Z0-9_]+(.undo)?\.sql$/.test(script)) {
if (!/^[0-9]{2}-[a-zA-Z0-9_]+(\..+)?\.sql$/.test(script)) {
logScript('[W]'.yellow, script, `Wrong file name.`);
continue;
}
if (isUndoScript(script))
continue;
if (isOtherEnvScript(script, opts.env))
if (isOtherRealmScript(script, realm))
continue;
const [[row]] = await conn.query(

8
myt.js
View File

@ -323,6 +323,14 @@ class Myt {
return version;
}
async fetchDbRealm() {
const [[realm]] = await this.conn.query(
`SELECT realm
FROM versionConfig`
);
return realm?.realm;
}
parseVersionDir(versionDir) {
const match = versionDir.match(/^([0-9]+)-([a-zA-Z0-9]+)?$/);
if (!match) return null;