Fix creacion de tabla + exit 0

This commit is contained in:
2026-02-19 12:48:00 +01:00
parent 3c4c8b2037
commit b580391f24

View File

@@ -120,7 +120,7 @@ async function getCurrentVersion(db: Pool, versionTable: string) {
`) `)
return lastVersion.rows[0] return lastVersion.rows[0]
} catch (e) { } catch (e) {
console.error("Error leyendo la tabla de versiones ", versionTable, e) console.error("[x] Error leyendo la tabla de versiones ", versionTable, e)
} }
} }
@@ -133,11 +133,11 @@ async function initVersionTable(db: Pool, versionTable: string) {
const ddlCreateVersionTable = ` const ddlCreateVersionTable = `
CREATE TABLE IF NOT EXISTS ${versionTable} ( CREATE TABLE IF NOT EXISTS ${versionTable} (
id BIGINT PRIMARY KEY GENERATED ALWAYS AS IDENTITY, id BIGINT PRIMARY KEY GENERATED ALWAYS AS IDENTITY,
version TEXT PRIMARY KEY, -- version semantica x.x.x, version TEXT, -- version semantica x.x.x,
notes TEXT, notes TEXT,
creation_date TIMESTAMP NOT NULL DEFAULT (now() at time zone 'utc'), creation_date TIMESTAMP NOT NULL DEFAULT (now() at time zone 'utc'),
stable BOOLEAN DEFAULT FALSE -- Si la version ha sido testada y se puede desplegar stable BOOLEAN DEFAULT FALSE -- Si la version ha sido testada y se puede desplegar
); );
` `
@@ -154,10 +154,11 @@ async function initVersionTable(db: Pool, versionTable: string) {
try { try {
await client.query("BEGIN") await client.query("BEGIN")
await client.query(ddlCreateVersionTable) await client.query(ddlCreateVersionTable)
await client.query(insertFistValue) await client.query("COMMIT")
await client.query("BEGIN")
await client.query(insertFistValue)
await client.query("COMMIT") await client.query("COMMIT")
return 0 return 0
} catch (e) { } catch (e) {
@@ -298,6 +299,14 @@ async function main() {
migrationDir: args.migrations, migrationDir: args.migrations,
versionTable: args.versionTable versionTable: args.versionTable
}) })
return 0
} }
main().then(e => console.log(e)).catch(console.error) main()
.then(e => {
process.exit(0)
})
.catch(e => {
console.error(e)
process.exit(1)
})