node-server-engine 1.10.4 → 1.10.5
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.
|
@@ -14,82 +14,114 @@ const namespace = 'engine:utils:dbMigration';
|
|
|
14
14
|
* Therefore, we use a more classic approach with this function and pure SQL queries
|
|
15
15
|
*/
|
|
16
16
|
async function migrateMetadataTable(sequelize) {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
// We check if we have a custom sequelize_meta table yet
|
|
24
|
-
const tables = await sequelize.query(query, {
|
|
25
|
-
type: _sequelize.QueryTypes.SELECT
|
|
26
|
-
});
|
|
27
|
-
const hasCustomSequelizeMeta = process.env.SQL_TYPE === 'postgres' ? tables.some(table => table[0] === 'sequelize_meta') : tables.some(table => Object.values(table)[0] === 'sequelize_meta');
|
|
28
|
-
const hasLegacySequelizeMeta = process.env.SQL_TYPE === 'postgres' ? tables.some(table => table[0] === 'SequelizeMeta') : tables.some(table => Object.values(table)[0] === 'SequelizeMeta');
|
|
29
|
-
if (!hasCustomSequelizeMeta) {
|
|
17
|
+
try {
|
|
18
|
+
(0, _report.reportDebug)({
|
|
19
|
+
namespace,
|
|
20
|
+
message: 'Executing metadata migration routine'
|
|
21
|
+
});
|
|
22
|
+
const query = `SELECT table_name FROM information_schema.tables`;
|
|
30
23
|
(0, _report.reportDebug)({
|
|
31
24
|
namespace,
|
|
32
|
-
message: '
|
|
25
|
+
message: 'Checking for existing metadata tables',
|
|
26
|
+
data: {
|
|
27
|
+
sqlType: process.env.SQL_TYPE
|
|
28
|
+
}
|
|
33
29
|
});
|
|
34
30
|
|
|
35
|
-
//
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
31
|
+
// We check if we have a custom sequelize_meta table yet
|
|
32
|
+
const tables = await sequelize.query(query, {
|
|
33
|
+
type: _sequelize.QueryTypes.SELECT
|
|
34
|
+
});
|
|
35
|
+
const hasCustomSequelizeMeta = process.env.SQL_TYPE === 'postgres' ? tables.some(table => table[0] === 'sequelize_meta') : tables.some(table => Object.values(table)[0] === 'sequelize_meta');
|
|
36
|
+
const hasLegacySequelizeMeta = process.env.SQL_TYPE === 'postgres' ? tables.some(table => table[0] === 'SequelizeMeta') : tables.some(table => Object.values(table)[0] === 'SequelizeMeta');
|
|
37
|
+
if (!hasCustomSequelizeMeta) {
|
|
38
|
+
(0, _report.reportDebug)({
|
|
39
|
+
namespace,
|
|
40
|
+
message: 'No metadata table found, creating new one'
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
// Define SQL for creating the table based on the database type
|
|
44
|
+
let createTableQuery = '';
|
|
45
|
+
switch (process.env.SQL_TYPE) {
|
|
46
|
+
case 'mysql':
|
|
47
|
+
case 'postgres':
|
|
48
|
+
createTableQuery = `
|
|
41
49
|
CREATE TABLE sequelize_meta (
|
|
42
50
|
name VARCHAR(100) PRIMARY KEY,
|
|
43
51
|
version VARCHAR(25),
|
|
44
52
|
createdAt TIMESTAMP NOT NULL,
|
|
45
53
|
updatedAt TIMESTAMP NOT NULL
|
|
46
54
|
)`;
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
55
|
+
break;
|
|
56
|
+
case 'mssql':
|
|
57
|
+
createTableQuery = `
|
|
50
58
|
CREATE TABLE sequelize_meta (
|
|
51
59
|
name VARCHAR(100) PRIMARY KEY,
|
|
52
60
|
version VARCHAR(25),
|
|
53
61
|
createdAt DATETIME NOT NULL,
|
|
54
62
|
updatedAt DATETIME NOT NULL
|
|
55
63
|
)`;
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
64
|
+
break;
|
|
65
|
+
default:
|
|
66
|
+
throw new Error('Unsupported SQL type');
|
|
67
|
+
}
|
|
60
68
|
|
|
61
|
-
|
|
62
|
-
await sequelize.query(createTableQuery, {
|
|
63
|
-
type: _sequelize.QueryTypes.RAW
|
|
64
|
-
});
|
|
65
|
-
|
|
66
|
-
// Migrate the data from the old table to the new one if needed
|
|
67
|
-
if (hasLegacySequelizeMeta) {
|
|
69
|
+
// Create the new sequelize_meta table if it does not exist
|
|
68
70
|
(0, _report.reportDebug)({
|
|
69
71
|
namespace,
|
|
70
|
-
message: '
|
|
72
|
+
message: 'Creating sequelize_meta table',
|
|
73
|
+
data: {
|
|
74
|
+
sqlType: process.env.SQL_TYPE
|
|
75
|
+
}
|
|
76
|
+
});
|
|
77
|
+
await sequelize.query(createTableQuery, {
|
|
78
|
+
type: _sequelize.QueryTypes.RAW
|
|
71
79
|
});
|
|
72
|
-
|
|
73
|
-
|
|
80
|
+
(0, _report.reportDebug)({
|
|
81
|
+
namespace,
|
|
82
|
+
message: 'sequelize_meta table created successfully'
|
|
74
83
|
});
|
|
75
|
-
|
|
84
|
+
|
|
85
|
+
// Migrate the data from the old table to the new one if needed
|
|
86
|
+
if (hasLegacySequelizeMeta) {
|
|
87
|
+
(0, _report.reportDebug)({
|
|
88
|
+
namespace,
|
|
89
|
+
message: 'Legacy metadata table found, migrating data'
|
|
90
|
+
});
|
|
91
|
+
const migrations = await sequelize.query('SELECT name FROM SequelizeMeta ORDER BY name', {
|
|
92
|
+
type: _sequelize.QueryTypes.SELECT
|
|
93
|
+
});
|
|
94
|
+
const insertQuery = `
|
|
76
95
|
INSERT INTO sequelize_meta (name, version, createdAt, updatedAt) VALUES
|
|
77
96
|
${migrations.map(migration => {
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
97
|
+
switch (process.env.SQL_TYPE) {
|
|
98
|
+
case 'mysql':
|
|
99
|
+
case 'postgres':
|
|
100
|
+
return `('${migration.name}', NULL, NOW(), NOW())`;
|
|
101
|
+
case 'mssql':
|
|
102
|
+
return `('${migration.name}', NULL, GETDATE(), GETDATE())`;
|
|
103
|
+
default:
|
|
104
|
+
throw new Error('Unsupported SQL type');
|
|
105
|
+
}
|
|
106
|
+
}).join(',')}
|
|
88
107
|
`;
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
108
|
+
await sequelize.query(insertQuery, {
|
|
109
|
+
type: _sequelize.QueryTypes.INSERT
|
|
110
|
+
});
|
|
111
|
+
}
|
|
92
112
|
}
|
|
113
|
+
} catch (error) {
|
|
114
|
+
(0, _report.reportError)({
|
|
115
|
+
namespace,
|
|
116
|
+
message: 'Error in metadata migration',
|
|
117
|
+
data: {
|
|
118
|
+
error: error instanceof Error ? error.message : String(error),
|
|
119
|
+
stack: error instanceof Error ? error.stack : undefined,
|
|
120
|
+
sqlType: process.env.SQL_TYPE,
|
|
121
|
+
sqlHost: process.env.SQL_HOST
|
|
122
|
+
}
|
|
123
|
+
});
|
|
124
|
+
throw error;
|
|
93
125
|
}
|
|
94
126
|
}
|
|
95
127
|
//# sourceMappingURL=migrateMetadataTable.js.map
|
|
@@ -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","data","sqlType","process","env","SQL_TYPE","tables","type","QueryTypes","SELECT","hasCustomSequelizeMeta","some","table","Object","values","hasLegacySequelizeMeta","createTableQuery","Error","RAW","migrations","insertQuery","map","migration","name","join","INSERT","error","reportError","String","stack","undefined","sqlHost","SQL_HOST"],"sources":["../../../../src/utils/dbMigration/migrateMetadataTable/migrateMetadataTable.ts"],"sourcesContent":["import { Sequelize, QueryTypes } from 'sequelize';\nimport { SequelizeMeta } from 'db/models';\nimport { reportDebug, reportError } from 'utils/report';\n\nconst namespace = 'engine:utils:dbMigration';\n\n/**\n * Run migrations on the metadata table\n * The table containing the migrations metadata cannot be handled through migrations\n * Therefore, we use a more classic approach with this function and pure SQL queries\n */\nexport async function migrateMetadataTable(\n sequelize: Sequelize\n): Promise<void> {\n try {\n reportDebug({ namespace, message: 'Executing metadata migration routine' });\n\n const query = `SELECT table_name FROM information_schema.tables`;\n\n reportDebug({ \n namespace, \n message: 'Checking for existing metadata tables',\n data: { sqlType: process.env.SQL_TYPE }\n });\n\n // We check if we have a custom sequelize_meta table yet\n const tables = await sequelize.query<Array<string>>(query, {\n type: QueryTypes.SELECT\n });\n\n const hasCustomSequelizeMeta =\n process.env.SQL_TYPE === 'postgres'\n ? tables.some((table) => table[0] === 'sequelize_meta')\n : tables.some((table) => Object.values(table)[0] === 'sequelize_meta');\n const hasLegacySequelizeMeta =\n process.env.SQL_TYPE === 'postgres'\n ? tables.some((table) => table[0] === 'SequelizeMeta')\n : tables.some((table) => Object.values(table)[0] === 'SequelizeMeta');\n if (!hasCustomSequelizeMeta) {\n reportDebug({\n namespace,\n message: 'No metadata table found, creating new one'\n });\n\n // Define SQL for creating the table based on the database type\n let createTableQuery = '';\n\n switch (process.env.SQL_TYPE) {\n case 'mysql':\n case 'postgres':\n createTableQuery = `\n CREATE TABLE sequelize_meta (\n name VARCHAR(100) PRIMARY KEY,\n version VARCHAR(25),\n createdAt TIMESTAMP NOT NULL,\n updatedAt TIMESTAMP NOT NULL\n )`;\n break;\n case 'mssql':\n createTableQuery = `\n CREATE TABLE sequelize_meta (\n name VARCHAR(100) PRIMARY KEY,\n version VARCHAR(25),\n createdAt DATETIME NOT NULL,\n updatedAt DATETIME NOT NULL\n )`;\n break;\n default:\n throw new Error('Unsupported SQL type');\n }\n\n // Create the new sequelize_meta table if it does not exist\n reportDebug({ \n namespace, \n message: 'Creating sequelize_meta table',\n data: { sqlType: process.env.SQL_TYPE }\n });\n await sequelize.query(createTableQuery, { type: QueryTypes.RAW });\n reportDebug({ namespace, message: 'sequelize_meta table created successfully' });\n\n // Migrate the data from the old table to the new one if needed\n if (hasLegacySequelizeMeta) {\n reportDebug({\n namespace,\n message: 'Legacy metadata table found, migrating data'\n });\n\n const migrations = await sequelize.query<SequelizeMeta>(\n 'SELECT name FROM SequelizeMeta ORDER BY name',\n {\n type: QueryTypes.SELECT\n }\n );\n\n const insertQuery = `\n INSERT INTO sequelize_meta (name, version, createdAt, updatedAt) VALUES\n ${migrations\n .map((migration) => {\n switch (process.env.SQL_TYPE) {\n case 'mysql':\n case 'postgres':\n return `('${migration.name}', NULL, NOW(), NOW())`;\n case 'mssql':\n return `('${migration.name}', NULL, GETDATE(), GETDATE())`;\n default:\n throw new Error('Unsupported SQL type');\n }\n })\n .join(',')}\n `;\n\n await sequelize.query(insertQuery, { type: QueryTypes.INSERT });\n }\n }\n } catch (error) {\n reportError({\n namespace,\n message: 'Error in metadata migration',\n data: {\n error: error instanceof Error ? error.message : String(error),\n stack: error instanceof Error ? error.stack : undefined,\n sqlType: process.env.SQL_TYPE,\n sqlHost: process.env.SQL_HOST\n }\n });\n throw error;\n }\n}\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,IAAI;IACF,IAAAC,mBAAW,EAAC;MAAEH,SAAS;MAAEI,OAAO,EAAE;IAAuC,CAAC,CAAC;IAE3E,MAAMC,KAAK,GAAG,kDAAkD;IAEhE,IAAAF,mBAAW,EAAC;MACVH,SAAS;MACTI,OAAO,EAAE,uCAAuC;MAChDE,IAAI,EAAE;QAAEC,OAAO,EAAEC,OAAO,CAACC,GAAG,CAACC;MAAS;IACxC,CAAC,CAAC;;IAEF;IACA,MAAMC,MAAM,GAAG,MAAMT,SAAS,CAACG,KAAK,CAAgBA,KAAK,EAAE;MACzDO,IAAI,EAAEC,qBAAU,CAACC;IACnB,CAAC,CAAC;IAEJ,MAAMC,sBAAsB,GAC1BP,OAAO,CAACC,GAAG,CAACC,QAAQ,KAAK,UAAU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ignoreList":[]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "node-server-engine",
|
|
3
|
-
"version": "1.10.
|
|
3
|
+
"version": "1.10.5",
|
|
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": {
|