Skip to content

Open-source platform for 3D AI agents. Turn text or a photo into a rigged, animated GLB avatar, give it an LLM brain, memory and a wallet, and embed it anywhere with one web component. Remote MCP server, x402 payments, Three.js, browser-native.

fix(db): rename an empty legacy discord activity table aside instead of failing the rooms migration

nirholas20b4baa5f070
diff --git a/api/_lib/migrations/20261015050000_discord_activity_rooms.sql b/api/_lib/migrations/20261015050000_discord_activity_rooms.sql
index 8230b5b81..e34ed95ac 100644
--- a/api/_lib/migrations/20261015050000_discord_activity_rooms.sql
+++ b/api/_lib/migrations/20261015050000_discord_activity_rooms.sql
@@ -4,6 +4,31 @@
-- in it. instance_id is Discord's own opaque activity-instance id, so it is
-- text, not a uuid; guild_id/channel_id are Discord snowflakes (text, they
-- exceed JS safe-integer range).
+-- Some databases already hold an earlier, empty discord_activity_rooms /
+-- discord_activity_participants pair keyed by instance_id (no `id` / `room_id`
+-- column). `create table if not exists` would skip them and the foreign keys
+-- below would fail, so an empty legacy-shaped table is renamed aside (kept, not
+-- dropped). A legacy table that holds rows aborts the migration instead.
+do $$
+declare
+ t text;
+ key text;
+ n bigint;
+begin
+ foreach t in array array['discord_activity_participants', 'discord_activity_rooms'] loop
+ key := case t when 'discord_activity_rooms' then 'id' else 'room_id' end;
+ if to_regclass(t) is not null and not exists (
+ select 1 from information_schema.columns
+ where table_schema = current_schema() and table_name = t and column_name = key) then
+ execute format('select count(*) from %I', t) into n;
+ if n > 0 then
+ raise exception 'legacy % holds % rows; migrate them by hand before this migration', t, n;
+ end if;
+ execute format('alter table %I rename to %I', t, t || '_legacy_instance_keyed');
+ end if;
+ end loop;
+end $$;
+
create table if not exists discord_activity_rooms (
id text primary key,
guild_id text not null,