Implementa o MVP do Adaptador de Planilhas no Elo Pro.
O módulo usa a identidade Supabase, isola cada workspace e registra storage, TTL, runner e biblioteca XLSX como decisões ainda abertas. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
commit
6e23f1533b
144 files changed
+19060
No files matched your search
@@ -0,0 +1,28 @@
|
||||
import { readFile, readdir } from "node:fs/promises";
|
||||
import path from "node:path";
|
||||
import type { Db } from "./types";
|
||||
|
||||
export function migrationsDir(): string {
|
||||
return path.join(process.cwd(), "migrations");
|
||||
}
|
||||
|
||||
export async function migrate(db: Db, directory = migrationsDir()): Promise<string[]> {
|
||||
await db.exec(`
|
||||
create table if not exists public.schema_migrations (
|
||||
id text primary key,
|
||||
applied_at timestamptz not null default now()
|
||||
);
|
||||
`);
|
||||
const files = (await readdir(directory)).filter((file) => file.endsWith(".sql")).sort();
|
||||
const appliedRows = await db.withService((query) => query.query<{ id: string }>("select id from public.schema_migrations"));
|
||||
const applied = new Set(appliedRows.map((row) => row.id));
|
||||
const ran: string[] = [];
|
||||
for (const file of files) {
|
||||
if (applied.has(file)) continue;
|
||||
const sql = await readFile(path.join(directory, file), "utf8");
|
||||
await db.exec(sql);
|
||||
await db.withService((query) => query.query("insert into public.schema_migrations (id) values ($1)", [file]));
|
||||
ran.push(file);
|
||||
}
|
||||
return ran;
|
||||
}
|
||||
Reference in new issue
Block a user