-
Notifications
You must be signed in to change notification settings - Fork 333
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add MeetingTemplate update embeddings trigger (#9838)
- Loading branch information
1 parent
71b17c2
commit 87e0d86
Showing
6 changed files
with
71 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
packages/server/postgres/migrations/1718014847553_getEmbedderPriority.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import {Client} from 'pg' | ||
import getPgConfig from '../getPgConfig' | ||
|
||
export async function up() { | ||
const client = new Client(getPgConfig()) | ||
await client.connect() | ||
await client.query(` | ||
CREATE OR REPLACE FUNCTION "getEmbedderPriority"(IN "maxDelayInDays" INTEGER) | ||
RETURNS INTEGER LANGUAGE PLPGSQL AS $$ | ||
BEGIN | ||
RETURN -(2 ^ 31) + FLOOR(EXTRACT(EPOCH FROM CURRENT_TIMESTAMP) / 1000) + "maxDelayInDays" * 86400; | ||
END | ||
$$; | ||
`) | ||
await client.end() | ||
} | ||
|
||
export async function down() { | ||
const client = new Client(getPgConfig()) | ||
await client.connect() | ||
await client.query(` | ||
DROP FUNCTION IF EXISTS "getEmbedderPriority"(IN INTEGER); | ||
`) | ||
await client.end() | ||
} |
37 changes: 37 additions & 0 deletions
37
packages/server/postgres/migrations/1718014858965_updateEmbeddingOnMeetingTemplateUpdate.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import {Client} from 'pg' | ||
import getPgConfig from '../getPgConfig' | ||
|
||
export async function up() { | ||
const client = new Client(getPgConfig()) | ||
await client.connect() | ||
await client.query(` | ||
CREATE OR REPLACE FUNCTION "updateEmbedding"() | ||
RETURNS TRIGGER LANGUAGE PLPGSQL AS $$ | ||
DECLARE | ||
"metadataId" INTEGER; | ||
BEGIN | ||
BEGIN | ||
SELECT id FROM "EmbeddingsMetadata" WHERE "objectType" = 'meetingTemplate' AND "refId" = NEW.id INTO STRICT "metadataId"; | ||
EXCEPTION | ||
WHEN NO_DATA_FOUND THEN | ||
INSERT INTO "EmbeddingsMetadata" ("objectType", "refId", "teamId", "refUpdatedAt") VALUES ('meetingTemplate', NEW.id, NEW."teamId", NEW."updatedAt") RETURNING id INTO "metadataId"; | ||
END; | ||
INSERT INTO "EmbeddingsJobQueue" ("embeddingsMetadataId", "jobType", "priority", "model") VALUES ("metadataId", 'embed:start', "getEmbedderPriority"(1), 'Embeddings_ember_1') ON CONFLICT DO NOTHING; | ||
RETURN NEW; | ||
END | ||
$$; | ||
DROP TRIGGER IF EXISTS "update_embedding_on_MeetingTemplate" ON "MeetingTemplate"; | ||
CREATE TRIGGER "update_embedding_on_MeetingTemplate" AFTER UPDATE ON "MeetingTemplate" FOR EACH ROW EXECUTE PROCEDURE "updateEmbedding"(); | ||
`) | ||
await client.end() | ||
} | ||
|
||
export async function down() { | ||
const client = new Client(getPgConfig()) | ||
await client.connect() | ||
await client.query(` | ||
DROP TRIGGER IF EXISTS "update_embedding_on_MeetingTemplate" ON "User"; | ||
DROP FUNCTION IF EXISTS "update_embedding_on_MeetingTemplate"(); | ||
`) | ||
await client.end() | ||
} |