@5minds/processcube_engine
Version:
The ProcessCube Engine. Stores and executes BPMNs.
85 lines • 4.05 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.up = up;
exports.down = down;
const sequelize_typescript_1 = require("sequelize-typescript");
async function up(tools) {
tools.logger.debug('Dropping UserMetadataStorage table.');
const schema = !tools.sequelizeOptions.schema && tools.sequelizeOptions.dialect === 'mssql' ? 'dbo' : tools.sequelizeOptions.schema;
const userMetadataStorageExists = await checkIfTableExists(tools, 'UserMetadataStorage', schema);
if (userMetadataStorageExists) {
await tools.queryInterface.dropTable({ tableName: 'UserMetadataStorage', schema: schema });
}
tools.logger.debug('Done.');
}
async function down(tools) {
const schema = !tools.sequelizeOptions.schema && tools.sequelizeOptions.dialect === 'mssql' ? 'dbo' : tools.sequelizeOptions.schema;
const userMetadataStorageTableExists = await checkIfTableExists(tools, 'UserMetadataStorage', schema);
if (!userMetadataStorageTableExists) {
tools.logger.debug('Restoring UserMetadataStorage table.');
await tools.queryInterface.createTable({ tableName: 'UserMetadataStorage', schema: schema }, {
id: {
type: sequelize_typescript_1.DataType.INTEGER,
autoIncrement: true,
primaryKey: true,
},
userId: {
type: sequelize_typescript_1.DataType.STRING,
allowNull: false,
},
key: {
type: sequelize_typescript_1.DataType.STRING,
allowNull: false,
},
value: {
type: sequelize_typescript_1.DataType.TEXT({ length: 'long' }),
allowNull: true,
},
processInstanceScope: {
type: sequelize_typescript_1.DataType.STRING,
allowNull: true,
},
flowNodeInstanceScope: {
type: sequelize_typescript_1.DataType.STRING,
allowNull: true,
},
createdAt: {
type: sequelize_typescript_1.DataType.DATE(3),
allowNull: true,
},
updatedAt: {
type: sequelize_typescript_1.DataType.DATE(3),
allowNull: true,
},
});
await createIndex(tools, 'UserMetadataStorage', ['userId', 'key'], `UserMetadataStorage_userId_key`);
await createIndex(tools, 'UserMetadataStorage', ['userId', 'key', 'processInstanceScope'], `UserMetadataStorage_userId_key_processInstanceScope`);
await createIndex(tools, 'UserMetadataStorage', ['userId', 'key', 'flowNodeInstanceScope'], `UserMetadataStorage_userId_key_flowNodeInstanceScope`);
await createIndex(tools, 'UserMetadataStorage', ['userId', 'key', 'processInstanceScope', 'flowNodeInstanceScope'], `UserMetadataStorage_userId_key_processInstanceScope_flowNodeInstanceScope`);
}
tools.logger.debug('Done.');
}
async function checkIfTableExists(tools, tableName, schema) {
try {
await tools.queryInterface.describeTable({ tableName: tableName, schema: schema });
return true;
}
catch (error) {
return false;
}
}
async function createIndex(tools, tableName, index, indexName) {
if (tools.sequelizeOptions.dialect === 'sqlite' && tools.sequelizeOptions.schema) {
await createSQLiteSchemaIndex(tools, tableName, index, indexName);
}
else {
await createRegularIndex(tools, tableName, index, indexName);
}
}
async function createRegularIndex(tools, tableName, index, indexName) {
await tools.queryInterface.addIndex({ tableName: tableName, schema: tools.sequelizeOptions.schema }, index, { name: indexName });
}
async function createSQLiteSchemaIndex(tools, tableName, index, indexName) {
await tools.queryInterface.addIndex({ tableName: tableName, schema: tools.sequelizeOptions.schema }, index, { name: indexName });
}
//# sourceMappingURL=2023-10-01_decomission_deprecated_tables.js.map