Setup sync_runs table

This commit is contained in:
Dominic Ferrando
2026-07-02 00:03:01 -04:00
parent f2781e1803
commit 934c523bf9
5 changed files with 81 additions and 52 deletions
+12
View File
@@ -0,0 +1,12 @@
import { Kysely, PostgresDialect } from 'kysely';
import { type DB } from 'kysely-codegen';
import { Pool } from "pg";
import { env } from '../util';
export const db = new Kysely<DB>({
dialect: new PostgresDialect({
pool: new Pool({
connectionString: env.DATABASE_URL,
}),
})
});
+27 -11
View File
@@ -1,12 +1,28 @@
import { Kysely, PostgresDialect } from 'kysely';
import { type DB } from 'kysely-codegen';
import { Pool } from "pg";
import { env } from '../index';
import { CreateTableBuilder, sql } from "kysely";
import { db } from "./db";
import { log } from "../util";
const db = new Kysely<DB>({
dialect: new PostgresDialect({
pool: new Pool({
connectionString: env.DATABASE_URL,
}),
})
});
// =====================
// SYNC RUNS
// =====================
{
log.info({ name: "sync_runs" }, "Creating table");
await db.schema.dropTable("sync_runs").ifExists().execute()
await db.schema.createTable("sync_runs")
.$call(addDefaultColumns)
.addColumn("completed_at", "timestamptz")
.execute()
}
function addDefaultColumns(ctb: CreateTableBuilder<any, any>) {
return ctb
.addColumn("id", "bigint", (cb) => cb
.generatedAlwaysAsIdentity()
.primaryKey()
)
.addColumn("created_at", "timestamptz", (cb) => cb
.notNull()
.defaultTo(sql`now()`)
.unique()
)
};