create tags_usages kysely table

This commit is contained in:
Siddharth Singh 2024-05-17 14:46:20 +05:30
parent 8c46560df4
commit 83a7b1f231
No known key found for this signature in database
2 changed files with 35 additions and 0 deletions

View File

@ -6,8 +6,15 @@ export interface DittoTables {
author_stats: AuthorStatsRow;
event_stats: EventStatsRow;
pubkey_domains: PubkeyDomainRow;
trends_tag_usages: TagUsageRow;
}
interface TagUsageRow {
tag: string,
pubkey8: string,
inserted_at: number
};
interface AuthorStatsRow {
pubkey: string;
followers_count: number;

View File

@ -0,0 +1,28 @@
import { Kysely, sql } from 'kysely';
export async function up(db: Kysely<any>): Promise<void> {
await db.transaction().execute(async trx => {
await trx.schema
.createTable('trends_tag_usages')
.ifNotExists()
.addColumn('tag', 'text', c => c.notNull().modifyEnd(sql`collate nocase`))
.addColumn('pubkey8', 'text', c => c.notNull())
.addColumn('inserted_at', 'integer', c => c.notNull())
.execute();
await trx.schema
.createIndex('trends_idx_time_tag')
.ifNotExists()
.on('trends_tag_usages')
.column('inserted_at')
.column('tag')
.execute();
})
}
export async function down(db: Kysely<any>): Promise<void> {
await db.transaction().execute(async trx => {
await trx.schema.dropIndex('trends_idx_time_tag').ifExists().execute();
await trx.schema.dropTable('trends_tag_usages').ifExists().execute();
})
}