Setting up db migrations
This commit is contained in:
@@ -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()`)
|
||||
)
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user