feat: refs #7562 deleteDeprecatedObjects #6

Merged
guillermo merged 7 commits from 7562-deleteDeprecatedObjects into master 2024-09-12 08:06:15 +00:00
1 changed files with 10 additions and 12 deletions
Showing only changes of commit a38cda0ba3 - Show all commits

View File

@ -42,7 +42,7 @@ class Version extends Command {
versionCreated: function(versionName) {
console.log(`New version created: ${versionName}`);
},
deprecate: 'Generating sql.'
deprecate: 'Generating SQL for deprecate.'
};
guillermo marked this conversation as resolved Outdated
Outdated
Review

Generating SQL for deprecated objects deletion

_Generating SQL for deprecated objects deletion_
async run(myt, opts) {
@ -128,16 +128,11 @@ class Version extends Command {
);
await fs.mkdir(newVersionDir);
let content;
if (opts.deprecate) {
this.emit('deprecate');
content = await deprecate();
} else
content = '-- Place your SQL code here\n'
await fs.writeFile(
`${newVersionDir}/00-firstScript.sql`,
content
opts.deprecate
? (this.emit('deprecate'), await deprecate(conn))
: '-- Place your SQL code here\n'
);
guillermo marked this conversation as resolved
Review

else y } deben estar en la misma linea: } else

`else` y `}` deben estar en la misma linea: `} else`
this.emit('versionCreated', versionFolder);
@ -152,7 +147,7 @@ class Version extends Command {
}
}
async function deprecate() {
async function deprecate(conn) {
const [[config]] = await conn.query(`
SELECT dateRegex,
deprecatedMarkRegex,
@ -160,11 +155,14 @@ async function deprecate() {
FROM config
`);
guillermo marked this conversation as resolved Outdated
Outdated
Review

Usar el fichero de configuración de Myt para estos parámetros

Usar el fichero de configuración de Myt para estos parámetros
const sql = await conn.query(`
if (!config || Object.values(config).some(value => value == null || value === ''))
throw new Error('missing configuration variables');
const [sql] = await conn.query(`
WITH variables AS (
SELECT ? markRegex, ? dateRegex, ? dated
)
SELECT CONCAT('ALTER TABLE ', c.TABLE_SCHEMA, '.', c.TABLE_NAME, ' DROP PRIMARY KEY;') sql
SELECT CONCAT('ALTER TABLE ', c.TABLE_SCHEMA, '.', c.TABLE_NAME, ' DROP PRIMARY KEY;') "sql"
FROM information_schema.COLUMNS c
LEFT JOIN information_schema.VIEWS v ON v.TABLE_SCHEMA = c.TABLE_SCHEMA
AND v.TABLE_NAME = c.TABLE_NAME