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(

18
myt.js
View File

@ -172,7 +172,7 @@ class Myt {
const defaultConfig = require(`${__dirname}/assets/myt.default.yml`);
const config = Object.assign({}, defaultConfig);
const configFile = 'myt.config.yml';
const configPath = path.join(opts.workspace, configFile);
@ -205,7 +205,7 @@ class Myt {
opts.dumpDir = path.join(opts.mytDir, 'dump');
// Database configuration
let iniDir = path.join(__dirname, 'assets');
let iniFile = 'db.ini';
@ -214,10 +214,10 @@ class Myt {
iniFile = `${opts.remote}.ini`;
}
const iniPath = path.join(iniDir, iniFile);
if (!await fs.pathExists(iniPath))
throw new Error(`Database config file not found: ${iniPath}`);
let dbConfig;
try {
const iniData = ini.parse(await fs.readFile(iniPath, 'utf8')).client;
@ -299,7 +299,7 @@ class Myt {
AND TABLE_NAME = 'version'`,
[opts.versionSchema]
);
if (!res.tableExists) {
const structure = await fs.readFile(
`${__dirname}/assets/structure.sql`, 'utf8');
@ -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;