release: WRNexusJS 0.4.0

This commit is contained in:
2026-07-27 12:42:18 +05:30
parent 8b728a3e5d
commit 30e5721e84
250 changed files with 10065 additions and 3923 deletions
+12 -7
View File
@@ -63,21 +63,26 @@ export async function appliedMigrations(db: Db): Promise<string[]> {
return rows.map((r) => r.name);
}
/** Apply all pending migrations (each in a transaction). Returns applied names. */
export async function migrate(db: Db, dir: string): Promise<string[]> {
/** Apply an ordered migration list (each in a transaction). Returns applied names. */
export async function applyMigrations(db: Db, migrations: readonly Migration[]): Promise<string[]> {
const applied = new Set(await appliedMigrations(db));
const pending = loadMigrations(dir).filter((m) => !applied.has(m.name));
const pending = migrations.filter((migration) => !applied.has(migration.name));
const done: string[] = [];
for (const m of pending) {
for (const migration of pending) {
await db.tx(async (tx) => {
if (m.up) await tx.exec(m.up);
await tx.exec(`INSERT INTO ${MIGRATIONS_TABLE} (name) VALUES (?)`, [m.name]);
if (migration.up) await tx.exec(migration.up);
await tx.exec(`INSERT INTO ${MIGRATIONS_TABLE} (name) VALUES (?)`, [migration.name]);
});
done.push(m.name);
done.push(migration.name);
}
return done;
}
/** Apply all pending migrations from a directory. */
export async function migrate(db: Db, dir: string): Promise<string[]> {
return applyMigrations(db, loadMigrations(dir));
}
/** Roll back the most recently applied migration. Returns its name, or null. */
export async function rollback(db: Db, dir: string): Promise<string | null> {
const applied = await appliedMigrations(db);