diff --git a/src/db/migrations/009_add_stats.ts b/src/db/migrations/009_add_stats.ts new file mode 100644 index 0000000..9655c05 --- /dev/null +++ b/src/db/migrations/009_add_stats.ts @@ -0,0 +1,24 @@ +import { Kysely } from '@/deps.ts'; + +export async function up(db: Kysely): Promise { + 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): Promise { + await db.schema.dropTable('pubkey_stats').execute(); + await db.schema.dropTable('event_stats').execute(); +}