6204-fixturesByEnvironment #2

Merged
jgallego merged 7 commits from 6204-fixturesByEnvironment into master 2023-10-30 06:57:37 +00:00
3 changed files with 28 additions and 13 deletions
Showing only changes of commit 38aec90073 - Show all commits

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) {
jgallego marked this conversation as resolved Outdated
Outdated
Review

No es necesario declarar una función, el código solo se utiliza una vez

No es necesario declarar una función, el código solo se utiliza una vez

Cierto te paso una propuesta de como queda sin funcion, pero creo que es bastante menos legible

// Reemplazo de la función isOtherRealmScript
const splitScript = script.split('.');
const realmPart = splitScript[splitScript.length - 2];

if (splitScript.length > 2) {
    if (!realm && realmPart) {
        continue;
    }
    
    if (realmPart && realmPart !== realm) {
        continue;
    }
}
Cierto te paso una propuesta de como queda sin funcion, pero creo que es bastante menos legible ``` // Reemplazo de la función isOtherRealmScript const splitScript = script.split('.'); const realmPart = splitScript[splitScript.length - 2]; if (splitScript.length > 2) { if (!realm && realmPart) { continue; } if (realmPart && realmPart !== realm) { continue; } } ```
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();
jgallego marked this conversation as resolved Outdated
Outdated
Review

Esta haciendo el SELECT en cada iteración

Esta haciendo el `SELECT` en cada iteración
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)) {
jgallego marked this conversation as resolved Outdated
Outdated
Review

/^[0-9]{2}-[a-zA-Z0-9_]+(\.[a-zA-Z0-9_]+)?\.sql$/

`/^[0-9]{2}-[a-zA-Z0-9_]+(\.[a-zA-Z0-9_]+)?\.sql$/`
Outdated
Review
const match = script.match(/^[0-9]{2}-[a-zA-Z0-9_]+(?:\.(?!undo)([a-zA-Z0-9_]+))?(?:\.undo)?\.sql$/);
const skipRealm = match[1] && match[1] !== realm;

``` const match = script.match(/^[0-9]{2}-[a-zA-Z0-9_]+(?:\.(?!undo)([a-zA-Z0-9_]+))?(?:\.undo)?\.sql$/); const skipRealm = match[1] && match[1] !== realm; ```
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;
}
jgallego marked this conversation as resolved Outdated
Outdated
Review

Debería declararse en el fichero myt-push.js ya que solo se utiliza ahí, no declarar función, solo se utiliza una vez

Debería declararse en el fichero _myt-push.js_ ya que solo se utiliza ahí, no declarar función, solo se utiliza una vez
parseVersionDir(versionDir) {
const match = versionDir.match(/^([0-9]+)-([a-zA-Z0-9]+)?$/);
if (!match) return null;