@grouparoo/core
Version:
The Grouparoo Core
30 lines (29 loc) • 1.48 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.MigrationUtils = void 0;
var MigrationUtils;
(function (MigrationUtils) {
function getOption(queryInterface, q) {
// @ts-ignore
return queryInterface.sequelize["options"][q];
}
MigrationUtils.getOption = getOption;
function getDialect(queryInterface) {
const dialect = getOption(queryInterface, "dialect");
return dialect;
}
MigrationUtils.getDialect = getDialect;
async function countRows(queryInterface, table, whereClause) {
const [rows] = await queryInterface.sequelize.query(`SELECT COUNT(*) as c FROM "${table}" ${whereClause ? `WHERE ${whereClause}` : ""}`);
return parseInt(rows[0]["c"]);
}
MigrationUtils.countRows = countRows;
async function ensureSQLiteTableEmpty(queryInterface, table) {
if (getDialect(queryInterface) !== "sqlite")
return;
const count = await countRows(queryInterface, table);
if (count > 0)
throw new Error(`[ migration ] Cannot proceed with migration - table ${table} is not empty. Please remove your SQLite database at ${getOption(queryInterface, "storage")} and retry the migration. See https://github.com/grouparoo/grouparoo/discussions/2428 for more information.`);
}
MigrationUtils.ensureSQLiteTableEmpty = ensureSQLiteTableEmpty;
})(MigrationUtils = exports.MigrationUtils || (exports.MigrationUtils = {}));