Setting up db migrations

This commit is contained in:
Dominic Ferrando
2026-07-03 21:01:56 -04:00
parent f5a68f436b
commit 37ffaa282b
8 changed files with 142 additions and 35 deletions
+14 -2
View File
@@ -1,5 +1,5 @@
import { Kysely, PostgresDialect } from 'kysely';
import { type DB } from 'kysely-codegen';
import { CreateTableBuilder, Kysely, PostgresDialect, sql } from 'kysely';
import { type DB } from "./types";
import { Pool } from "pg";
import { env } from '../util';
@@ -10,3 +10,15 @@ export const db = new Kysely<DB>({
}),
})
});
export 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()`)
)
};