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