node-server-engine 1.1.3 → 1.1.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -18,7 +18,7 @@ async function migrateMetadataTable(sequelize) {
|
|
|
18
18
|
namespace,
|
|
19
19
|
message: 'Executing metadata migration routine'
|
|
20
20
|
});
|
|
21
|
-
const query = `SELECT table_name FROM information_schema.tables
|
|
21
|
+
const query = `SELECT table_name FROM information_schema.tables`;
|
|
22
22
|
|
|
23
23
|
// We check if we have a custom sequelize_meta table yet
|
|
24
24
|
const tables = await sequelize.query(query, {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"migrateMetadataTable.js","names":["_sequelize","require","_report","namespace","migrateMetadataTable","sequelize","reportDebug","message","query","
|
|
1
|
+
{"version":3,"file":"migrateMetadataTable.js","names":["_sequelize","require","_report","namespace","migrateMetadataTable","sequelize","reportDebug","message","query","tables","type","QueryTypes","SELECT","hasCustomSequelizeMeta","process","env","SQL_TYPE","some","table","Object","values","hasLegacySequelizeMeta","createTableQuery","Error","RAW","migrations","insertQuery","map","migration","name","join","INSERT"],"sources":["../../../../src/utils/dbMigration/migrateMetadataTable/migrateMetadataTable.ts"],"sourcesContent":["import { Sequelize, QueryTypes } from 'sequelize';\r\nimport { SequelizeMeta } from 'db/models';\r\nimport { reportDebug } from 'utils/report';\r\n\r\nconst namespace = 'engine:utils:dbMigration';\r\n\r\n/**\r\n * Run migrations on the metadata table\r\n * The table containing the migrations metadata cannot be handled through migrations\r\n * Therefore, we use a more classic approach with this function and pure SQL queries\r\n */\r\nexport async function migrateMetadataTable(\r\n sequelize: Sequelize\r\n): Promise<void> {\r\n reportDebug({ namespace, message: 'Executing metadata migration routine' });\r\n\r\n const query = `SELECT table_name FROM information_schema.tables`;\r\n\r\n // We check if we have a custom sequelize_meta table yet\r\n const tables = await sequelize.query<Array<string>>(query, {\r\n type: QueryTypes.SELECT\r\n });\r\n\r\n const hasCustomSequelizeMeta =\r\n process.env.SQL_TYPE === 'postgres'\r\n ? tables.some((table) => table[0] === 'sequelize_meta')\r\n : tables.some((table) => Object.values(table)[0] === 'sequelize_meta');\r\n const hasLegacySequelizeMeta =\r\n process.env.SQL_TYPE === 'postgres'\r\n ? tables.some((table) => table[0] === 'SequelizeMeta')\r\n : tables.some((table) => Object.values(table)[0] === 'SequelizeMeta');\r\n if (!hasCustomSequelizeMeta) {\r\n reportDebug({\r\n namespace,\r\n message: 'No metadata table found, creating new one'\r\n });\r\n\r\n // Define SQL for creating the table based on the database type\r\n let createTableQuery = '';\r\n\r\n switch (process.env.SQL_TYPE) {\r\n case 'mysql':\r\n case 'postgres':\r\n createTableQuery = `\r\n CREATE TABLE sequelize_meta (\r\n name VARCHAR(100) PRIMARY KEY,\r\n version VARCHAR(25),\r\n createdAt TIMESTAMP NOT NULL,\r\n updatedAt TIMESTAMP NOT NULL\r\n )`;\r\n break;\r\n case 'mssql':\r\n createTableQuery = `\r\n CREATE TABLE sequelize_meta (\r\n name VARCHAR(100) PRIMARY KEY,\r\n version VARCHAR(25),\r\n createdAt DATETIME NOT NULL,\r\n updatedAt DATETIME NOT NULL\r\n )`;\r\n break;\r\n default:\r\n throw new Error('Unsupported SQL type');\r\n }\r\n\r\n // Create the new sequelize_meta table if it does not exist\r\n await sequelize.query(createTableQuery, { type: QueryTypes.RAW });\r\n\r\n // Migrate the data from the old table to the new one if needed\r\n if (hasLegacySequelizeMeta) {\r\n reportDebug({\r\n namespace,\r\n message: 'Legacy metadata table found, migrating data'\r\n });\r\n\r\n const migrations = await sequelize.query<SequelizeMeta>(\r\n 'SELECT name FROM SequelizeMeta ORDER BY name',\r\n {\r\n type: QueryTypes.SELECT\r\n }\r\n );\r\n\r\n const insertQuery = `\r\n INSERT INTO sequelize_meta (name, version, createdAt, updatedAt) VALUES\r\n ${migrations\r\n .map((migration) => {\r\n switch (process.env.SQL_TYPE) {\r\n case 'mysql':\r\n case 'postgres':\r\n return `('${migration.name}', NULL, NOW(), NOW())`;\r\n case 'mssql':\r\n return `('${migration.name}', NULL, GETDATE(), GETDATE())`;\r\n default:\r\n throw new Error('Unsupported SQL type');\r\n }\r\n })\r\n .join(',')}\r\n `;\r\n\r\n await sequelize.query(insertQuery, { type: QueryTypes.INSERT });\r\n }\r\n }\r\n}\r\n"],"mappings":";;;;;;AAAA,IAAAA,UAAA,GAAAC,OAAA;AAEA,IAAAC,OAAA,GAAAD,OAAA;AAEA,MAAME,SAAS,GAAG,0BAA0B;;AAE5C;AACA;AACA;AACA;AACA;AACO,eAAeC,oBAAoBA,CACxCC,SAAoB,EACL;EACf,IAAAC,mBAAW,EAAC;IAAEH,SAAS;IAAEI,OAAO,EAAE;EAAuC,CAAC,CAAC;EAE3E,MAAMC,KAAK,GAAG,kDAAkD;;EAEhE;EACA,MAAMC,MAAM,GAAG,MAAMJ,SAAS,CAACG,KAAK,CAAgBA,KAAK,EAAE;IACzDE,IAAI,EAAEC,qBAAU,CAACC;EACnB,CAAC,CAAC;EAEF,MAAMC,sBAAsB,GAC1BC,OAAO,CAACC,GAAG,CAACC,QAAQ,KAAK,UAAU,GAC/BP,MAAM,CAACQ,IAAI,CAAEC,KAAK,IAAKA,KAAK,CAAC,CAAC,CAAC,KAAK,gBAAgB,CAAC,GACrDT,MAAM,CAACQ,IAAI,CAAEC,KAAK,IAAKC,MAAM,CAACC,MAAM,CAACF,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,gBAAgB,CAAC;EAC1E,MAAMG,sBAAsB,GAC1BP,OAAO,CAACC,GAAG,CAACC,QAAQ,KAAK,UAAU,GAC/BP,MAAM,CAACQ,IAAI,CAAEC,KAAK,IAAKA,KAAK,CAAC,CAAC,CAAC,KAAK,eAAe,CAAC,GACpDT,MAAM,CAACQ,IAAI,CAAEC,KAAK,IAAKC,MAAM,CAACC,MAAM,CAACF,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,eAAe,CAAC;EACzE,IAAI,CAACL,sBAAsB,EAAE;IAC3B,IA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;EACF;AACF","ignoreList":[]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "node-server-engine",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.4",
|
|
4
4
|
"description": "Framework used to develop backend services. This package ships with a lot of features to standardize the creation of services, letting you focus on the business logic.",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -14,7 +14,7 @@ export async function migrateMetadataTable(
|
|
|
14
14
|
): Promise<void> {
|
|
15
15
|
reportDebug({ namespace, message: 'Executing metadata migration routine' });
|
|
16
16
|
|
|
17
|
-
const query = `SELECT table_name FROM information_schema.tables
|
|
17
|
+
const query = `SELECT table_name FROM information_schema.tables`;
|
|
18
18
|
|
|
19
19
|
// We check if we have a custom sequelize_meta table yet
|
|
20
20
|
const tables = await sequelize.query<Array<string>>(query, {
|