Setup sync_runs table
This commit is contained in:
@@ -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,
|
||||
}),
|
||||
})
|
||||
});
|
||||
|
||||
@@ -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()
|
||||
)
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user