diff options
author | EuAndreh <eu@euandre.org> | 2024-03-25 06:42:35 -0300 |
---|---|---|
committer | EuAndreh <eu@euandre.org> | 2024-03-25 06:44:18 -0300 |
commit | 077b81b2bd2c0d418635b265b35f582d68cec16a (patch) | |
tree | ed3c928ea3b1d5df539b6e1902ab418caa937672 /src/accretion.mjs | |
parent | src/hero.mjs: Retire code (diff) | |
download | papod-077b81b2bd2c0d418635b265b35f582d68cec16a.tar.gz papod-077b81b2bd2c0d418635b265b35f582d68cec16a.tar.xz |
Node.js -> Go
Diffstat (limited to 'src/accretion.mjs')
-rw-r--r-- | src/accretion.mjs | 42 |
1 files changed, 0 insertions, 42 deletions
diff --git a/src/accretion.mjs b/src/accretion.mjs deleted file mode 100644 index dd3372c..0000000 --- a/src/accretion.mjs +++ /dev/null @@ -1,42 +0,0 @@ -import assert from "node:assert/strict"; -import fs from "node:fs"; -import path from "node:path"; -import url from "node:url"; - -import sqlite from "./sqlite.cjs"; - -import * as u from "./utils.mjs"; - - -const DIRNAME = path.dirname(url.fileURLToPath(import.meta.url)); -export const MIGRATIONS_DIR = DIRNAME + "/sql/migrations/"; - -export const runMigrations = async (logFn, db) => { - assert(db); - - await db.exec(` - BEGIN TRANSACTION; - CREATE TABLE IF NOT EXISTS migrations ( - filename TEXT NOT NULL PRIMARY KEY - ); - COMMIT TRANSACTION; - `); - - const done = [...(await db.all("SELECT filename FROM migrations;"))] - .map(row => row.filename); - const allFiles = fs.readdirSync(MIGRATIONS_DIR, "UTF-8"); - const pending = u.difference(new Set(allFiles), new Set(done)); - const sortedPending = [...pending].sort(u.strSortFn); - - for (const filename of sortedPending) { - logFn({ log: "exec-migration", filename }); - const sql = fs.readFileSync(MIGRATIONS_DIR + filename, "UTF-8"); - await db.exec("BEGIN TRANSACTION;"); - await db.exec(sql); - await db.run( - "INSERT INTO migrations (filename) VALUES ($filename);", - { $filename: filename }, - ); - await db.exec("COMMIT TRANSACTION;") - } -}; |