stats: add migration for stats tables

This commit is contained in:
Alex Gleason 2023-12-10 14:03:01 -06:00
parent 0f10a7c3a2
commit 8b03d492a1
No known key found for this signature in database
GPG Key ID: 7211D1F99744FBB7
1 changed files with 24 additions and 0 deletions

View File

@ -0,0 +1,24 @@
import { Kysely } from '@/deps.ts';
export async function up(db: Kysely<any>): Promise<void> {
await db.schema
.createTable('pubkey_stats')
.addColumn('pubkey', 'text', (col) => col.primaryKey())
.addColumn('followers_count', 'integer', (col) => col.notNull().defaultTo(0))
.addColumn('following_count', 'integer', (col) => col.notNull().defaultTo(0))
.addColumn('notes_count', 'integer', (col) => col.notNull().defaultTo(0))
.execute();
await db.schema
.createTable('event_stats')
.addColumn('event_id', 'text', (col) => col.primaryKey().references('events.id').onDelete('cascade'))
.addColumn('replies_count', 'integer', (col) => col.notNull().defaultTo(0))
.addColumn('reposts_count', 'integer', (col) => col.notNull().defaultTo(0))
.addColumn('reactions_count', 'integer', (col) => col.notNull().defaultTo(0))
.execute();
}
export async function down(db: Kysely<any>): Promise<void> {
await db.schema.dropTable('pubkey_stats').execute();
await db.schema.dropTable('event_stats').execute();
}