Files
frislit/server/utils/migrationRunner.js
T
fristy 650807c1fb
CI / Docker image (push) Successful in 12s
CI / Server (push) Successful in 25s
CI / CLI (push) Successful in 13s
Development image / Development image (push) Successful in 21s
CI / CLI (windows) (push) Successful in 57s
CI / CLI (linux-arm64, static) (push) Successful in 1m37s
Release / Prepare release (push) Successful in 2s
Release / Server (linux-x64) (push) Successful in 53s
Release / CLI (linux-arm64, static) (push) Successful in 1m32s
Release / Docker image (push) Successful in 2m48s
Release / Server (windows-x64) (push) Successful in 6m20s
Release / CLI (windows-x64) (push) Successful in 6m48s
Release / CLI (linux-x64) (push) Successful in 7m8s
Release / Publish release (push) Successful in 1s
chore: restart the repository with a clean history
Squash the tree into one commit, drop docs/architecture.html, reset the version line to 0.3.0, consolidate the changelog, enable Renovate automerge for non-major updates and add AGENTS.md.
2026-11-10 11:31:13 +03:00

42 lines
1.5 KiB
JavaScript

const fs = require("node:fs");
const path = require("node:path");
const { DataTypes } = require("sequelize");
const db = require("./database");
const logger = require("./logger");
const MIGRATION_DIR = path.join(__dirname, "..", "migrations");
const ensureTable = async queryInterface => {
const tables = await queryInterface.showAllTables();
if (tables.includes("SequelizeMeta")) return;
await queryInterface.createTable("SequelizeMeta", {
name: { type: DataTypes.STRING, allowNull: false, primaryKey: true },
});
};
const executed = async () => {
const rows = await db.query("SELECT name FROM SequelizeMeta ORDER BY name ASC", { type: db.QueryTypes.SELECT });
return rows.map(row => row.name);
};
const runMigrations = async () => {
const queryInterface = db.getQueryInterface();
await ensureTable(queryInterface);
const done = new Set(await executed());
const files = fs.existsSync(MIGRATION_DIR)
? fs.readdirSync(MIGRATION_DIR).filter(file => file.endsWith(".js")).sort()
: [];
const pending = files.filter(file => !done.has(file));
if (!pending.length) return;
for (const file of pending) {
const migration = require(path.join(MIGRATION_DIR, file));
await migration.up(queryInterface, db);
await db.query("INSERT INTO SequelizeMeta (name) VALUES (?)", { replacements: [file] });
logger.info(`Applied migration ${file}`);
}
};
module.exports = { runMigrations };