.
This commit is contained in:
parent
844cb438a7
commit
960e1cdd1a
@ -63,6 +63,10 @@ export class SequelizeAdapter implements ISequelizeAdapter {
|
|||||||
return this._queryBuilder;
|
return this._queryBuilder;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
get connection(): Sequelize {
|
||||||
|
return this._connection;
|
||||||
|
}
|
||||||
|
|
||||||
public startTransaction(): SequelizeBusinessTransactionType {
|
public startTransaction(): SequelizeBusinessTransactionType {
|
||||||
return new SequelizeBusinessTransaction(this._connection);
|
return new SequelizeBusinessTransaction(this._connection);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -107,7 +107,7 @@ const server: http.Server = http
|
|||||||
try {
|
try {
|
||||||
//firebirdConn.sync().then(() => {
|
//firebirdConn.sync().then(() => {
|
||||||
sequelizeConn.sync({ force: false, alter: true }).then(() => {
|
sequelizeConn.sync({ force: false, alter: true }).then(() => {
|
||||||
initStructure(sequelizeConn);
|
initStructure(sequelizeConn.connection);
|
||||||
insertUsers();
|
insertUsers();
|
||||||
|
|
||||||
// Launch server
|
// Launch server
|
||||||
|
|||||||
@ -1,14 +1,20 @@
|
|||||||
const createCatalogTableIfNotExists = async (sequelize) => {
|
import { initLogger } from "@/infrastructure/logger";
|
||||||
|
import rTracer from "cls-rtracer";
|
||||||
|
import { Sequelize } from "sequelize";
|
||||||
|
|
||||||
|
const logger = initLogger(rTracer);
|
||||||
|
|
||||||
|
const createCatalogTableIfNotExists = async (sequelize: Sequelize) => {
|
||||||
try {
|
try {
|
||||||
// Consulta para verificar si la tabla existe
|
// Consulta para verificar si la tabla existe
|
||||||
const checkTableQuery = `
|
const checkTableQuery = `
|
||||||
SELECT COUNT(*)
|
SELECT COUNT(*)
|
||||||
FROM information_schema.tables
|
FROM information_schema.tables
|
||||||
WHERE table_schema = DATABASE()
|
WHERE table_schema = DATABASE()
|
||||||
AND table_name = 'catalog';
|
AND table_name = 'catalog';`;
|
||||||
`;
|
|
||||||
|
|
||||||
const [result] = await sequelize.query(checkTableQuery);
|
const [result] = await sequelize.query(checkTableQuery);
|
||||||
|
|
||||||
const tableExists = result[0]["COUNT(*)"] > 0;
|
const tableExists = result[0]["COUNT(*)"] > 0;
|
||||||
|
|
||||||
if (!tableExists) {
|
if (!tableExists) {
|
||||||
@ -40,14 +46,14 @@ const createCatalogTableIfNotExists = async (sequelize) => {
|
|||||||
`;
|
`;
|
||||||
|
|
||||||
await sequelize.query(createTableQuery);
|
await sequelize.query(createTableQuery);
|
||||||
console.log('Tabla "catalog" creada con éxito.');
|
logger.debug('Tabla "catalog" creada con éxito.');
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Error al crear la tabla "catalog":', error);
|
logger.error('Error al crear la tabla "catalog":', error);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const createCatalogTranslationsTableIfNotExists = async (sequelize) => {
|
const createCatalogTranslationsTableIfNotExists = async (sequelize: Sequelize) => {
|
||||||
try {
|
try {
|
||||||
// Consulta para verificar si la tabla existe
|
// Consulta para verificar si la tabla existe
|
||||||
const checkTableQuery = `
|
const checkTableQuery = `
|
||||||
@ -88,14 +94,14 @@ const createCatalogTranslationsTableIfNotExists = async (sequelize) => {
|
|||||||
`;
|
`;
|
||||||
|
|
||||||
await sequelize.query(createTableQuery);
|
await sequelize.query(createTableQuery);
|
||||||
console.log('Tabla "catalog_translations" creada con éxito.');
|
logger.debug('Tabla "catalog_translations" creada con éxito.');
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Error al crear la tabla "catalog_translations":', error);
|
logger.error('Error al crear la tabla "catalog_translations":', error);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const createVCatalogViewIfNotExists = async (sequelize) => {
|
const createVCatalogViewIfNotExists = async (sequelize: Sequelize) => {
|
||||||
try {
|
try {
|
||||||
// Consulta para verificar si la tabla existe
|
// Consulta para verificar si la tabla existe
|
||||||
const checkViewQuery = `
|
const checkViewQuery = `
|
||||||
@ -129,15 +135,15 @@ const createVCatalogViewIfNotExists = async (sequelize) => {
|
|||||||
`;
|
`;
|
||||||
|
|
||||||
await sequelize.query(createViewQuery);
|
await sequelize.query(createViewQuery);
|
||||||
console.log('Vista "v_catalog" creada con éxito.');
|
logger.debug('Vista "v_catalog" creada con éxito.');
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Error al crear la vista "v_catalog":', error);
|
logger.error('Error al crear la vista "v_catalog":', error);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
export const initStructure = async (sequelize) => {
|
export const initStructure = async (sequelize) => {
|
||||||
createCatalogTableIfNotExists(sequelize);
|
await createCatalogTableIfNotExists(sequelize);
|
||||||
createCatalogTranslationsTableIfNotExists(sequelize);
|
await createCatalogTranslationsTableIfNotExists(sequelize);
|
||||||
createVCatalogViewIfNotExists(sequelize);
|
await createVCatalogViewIfNotExists(sequelize);
|
||||||
};
|
};
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user