Something went wrong. Try again.
This repository has no description
Something went wrong. Try again.
2.1 kB · 66 lines
TypeScript
at main
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667import { Migration, Migrator } from "kysely/migration";import { Kysely } from "kysely";import { getDb } from ".";
const migrations: Record<string, Migration> = { "001": { async up(db: Kysely<unknown>) { await db.schema .createTable("auth_state") .addColumn("key", "text", (col) => col.primaryKey()) .addColumn("value", "text", (col) => col.notNull()) .execute();
await db.schema .createTable("auth_session") .addColumn("key", "text", (col) => col.primaryKey()) .addColumn("value", "text", (col) => col.notNull()) .execute(); }, async down(db: Kysely<unknown>) { await db.schema.dropTable("auth_session").execute(); await db.schema.dropTable("auth_state").execute(); }, }, "002": { async up(db: Kysely<unknown>) { await db.schema .createTable("account") .addColumn("did", "text", (col) => col.primaryKey()) .addColumn("handle", "text", (col) => col.notNull()) .addColumn("active", "integer", (col) => col.notNull().defaultTo(1)) .execute();
await db.schema .createTable("status") .addColumn("uri", "text", (col) => col.primaryKey()) .addColumn("authorDid", "text", (col) => col.notNull()) .addColumn("status", "text", (col) => col.notNull()) .addColumn("createdAt", "text", (col) => col.notNull()) .addColumn("indexedAt", "text", (col) => col.notNull()) .addColumn("current", "integer", (col) => col.notNull().defaultTo(0)) .execute();
await db.schema .createIndex("status_current_idx") .on("status") .columns(["current", "indexedAt"]) .execute(); }, async down(db: Kysely<unknown>) { await db.schema.dropIndex("status_current_idx").on("status").execute(); await db.schema.dropTable("status").execute(); await db.schema.dropTable("account").execute(); }, },};
export function getMigrator() { const db = getDb(); return new Migrator({ db, provider: { getMigrations: async () => migrations, }, });}