mirror of
https://gitlab.com/soapbox-pub/ditto.git
synced 2025-12-06 03:19:46 +00:00
refactor: remove author_search table, put search in author_stats
This commit is contained in:
parent
d1f452d87b
commit
017c17c8a2
1 changed files with 32 additions and 0 deletions
32
src/db/migrations/034_move_author_search_to_author_stats.ts
Normal file
32
src/db/migrations/034_move_author_search_to_author_stats.ts
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
import { Kysely, sql } from 'kysely';
|
||||
|
||||
export async function up(db: Kysely<any>): Promise<void> {
|
||||
await db.schema
|
||||
.alterTable('author_stats')
|
||||
.addColumn('search', 'text', (col) => col.notNull().defaultTo(''))
|
||||
.execute();
|
||||
|
||||
await sql`CREATE INDEX author_stats_search_idx ON author_stats USING GIN (search gin_trgm_ops)`.execute(db);
|
||||
|
||||
await db.insertInto('author_stats')
|
||||
.columns(['pubkey', 'search'])
|
||||
.expression(
|
||||
db.selectFrom('author_search')
|
||||
.select(['pubkey', 'search']),
|
||||
)
|
||||
.onConflict((oc) =>
|
||||
oc.column('pubkey')
|
||||
.doUpdateSet((eb) => ({
|
||||
search: eb.ref('excluded.search'),
|
||||
}))
|
||||
)
|
||||
.execute();
|
||||
|
||||
await db.schema.dropIndex('author_search_search_idx').ifExists().execute();
|
||||
await db.schema.dropTable('author_search').execute();
|
||||
}
|
||||
|
||||
export async function down(db: Kysely<any>): Promise<void> {
|
||||
await db.schema.dropIndex('author_stats_search_idx').ifExists().execute();
|
||||
await db.schema.alterTable('author_stats').dropColumn('search').execute();
|
||||
}
|
||||
Loading…
Add table
Reference in a new issue