Files
docmost/apps/server/src/database/migrations/20240324T086800-pages-tsvector-trigger.ts
T
Philipinho 9c7c2f1163 updates and fixes
* seo friendly urls
* custom client serve-static module
* database fixes
* fix recent pages
* other fixes
2024-05-18 03:19:42 +01:00

23 lines
877 B
TypeScript

import { type Kysely, sql } from 'kysely';
export async function up(db: Kysely<any>): Promise<void> {
await sql`CREATE OR REPLACE FUNCTION pages_tsvector_trigger() RETURNS trigger AS $$
begin
new.tsv :=
setweight(to_tsvector('english', coalesce(new.title, '')), 'A') ||
setweight(to_tsvector('english', coalesce(new.text_content, '')), 'B');
return new;
end;
$$ LANGUAGE plpgsql;`.execute(db);
await sql`CREATE OR REPLACE TRIGGER pages_tsvector_update BEFORE INSERT OR UPDATE
ON pages FOR EACH ROW EXECUTE FUNCTION pages_tsvector_trigger();`.execute(
db,
);
}
export async function down(db: Kysely<any>): Promise<void> {
await sql`DROP trigger pages_tsvector_update ON pages`.execute(db);
await sql`DROP FUNCTION pages_tsvector_trigger`.execute(db);
}