|
1 | | --- Resolve the server-attested TikTok open_id once at deploy time, like Slack's |
2 | | --- team_id routing. Rows whose credential/account identity cannot be proven are |
3 | | --- deliberately left unchanged so the migration never guesses a tenant key. |
4 | | --- migration-safe: session-local scratch table created only by this migration; no application code reads it. |
5 | | -DROP TABLE IF EXISTS "_tiktok_webhook_routing_backfill"; |
6 | | ---> statement-breakpoint |
7 | | -CREATE TEMP TABLE "_tiktok_webhook_routing_backfill" ON COMMIT PRESERVE ROWS AS |
8 | | -SELECT |
9 | | - "webhook"."id" AS "webhook_id", |
10 | | - "webhook"."workflow_id", |
11 | | - "webhook"."path", |
12 | | - regexp_replace( |
13 | | - "account"."account_id", |
14 | | - '-[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$', |
15 | | - '', |
16 | | - 'i' |
17 | | - ) AS "routing_key" |
18 | | -FROM "webhook" |
19 | | -INNER JOIN "credential" |
20 | | - ON "credential"."id" = (("webhook"."provider_config")::jsonb ->> 'credentialId') |
21 | | - AND "credential"."type" = 'oauth' |
22 | | - AND "credential"."provider_id" = 'tiktok' |
23 | | -INNER JOIN "workflow" |
24 | | - ON "workflow"."id" = "webhook"."workflow_id" |
25 | | - AND "workflow"."workspace_id" = "credential"."workspace_id" |
26 | | -INNER JOIN "account" |
27 | | - ON "account"."id" = "credential"."account_id" |
28 | | - AND "account"."provider_id" = 'tiktok' |
29 | | -WHERE "webhook"."provider" = 'tiktok' |
30 | | - AND "account"."account_id" ~* '-[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$' |
31 | | - AND regexp_replace( |
32 | | - "account"."account_id", |
33 | | - '-[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$', |
34 | | - '', |
35 | | - 'i' |
36 | | - ) <> ''; |
37 | | ---> statement-breakpoint |
38 | | -DELETE FROM "webhook_path_claim" |
39 | | -USING "_tiktok_webhook_routing_backfill" |
40 | | -WHERE "webhook_path_claim"."path" = "_tiktok_webhook_routing_backfill"."path" |
41 | | - AND "webhook_path_claim"."workflow_id" = "_tiktok_webhook_routing_backfill"."workflow_id"; |
42 | | ---> statement-breakpoint |
43 | | -UPDATE "webhook" |
44 | | -SET |
45 | | - "routing_key" = "_tiktok_webhook_routing_backfill"."routing_key", |
46 | | - "path" = NULL, |
47 | | - "updated_at" = now() |
48 | | -FROM "_tiktok_webhook_routing_backfill" |
49 | | -WHERE "webhook"."id" = "_tiktok_webhook_routing_backfill"."webhook_id" |
50 | | - AND "_tiktok_webhook_routing_backfill"."routing_key" <> ''; |
51 | | ---> statement-breakpoint |
52 | | -DO $$ |
53 | | -DECLARE migrated_count integer; |
54 | | -BEGIN |
55 | | - SELECT count(*) INTO migrated_count FROM "_tiktok_webhook_routing_backfill"; |
56 | | - RAISE NOTICE 'Migrated % TikTok webhook rows to routing_key', migrated_count; |
57 | | -END $$; |
58 | | ---> statement-breakpoint |
59 | | --- migration-safe: remove the session-local scratch table after the backfill completes. |
60 | | -DROP TABLE IF EXISTS "_tiktok_webhook_routing_backfill"; |
61 | | ---> statement-breakpoint |
62 | | --- The routing-key index replaces the old TikTok credential-expression lookup. |
| 1 | +-- TikTok now uses the shared routing-key lookup. No deployed TikTok webhooks |
| 2 | +-- exist to backfill, so only remove the obsolete provider-specific index. |
63 | 3 | COMMIT; |
64 | 4 | --> statement-breakpoint |
65 | 5 | SET lock_timeout = 0; |
|
0 commit comments