refactor(schema): remove deprecated space and space_member tables and associated logic
ZhenYi committed
Modified lib/share/models/schema_extras.sql lib/share/models/schema_extras.sql +0 −53 View lib/share/models/schema_extras.sql
@@ -306,59 +306,6 @@
306306END $$;
307307
308308-- ---------------------------------------------------------------------------
309-- 2026-10-30: KenOAuth becomes the only authority for organizations,
310-- membership and permissions. The old local mirrors are retired:
311-- * presentation-only fields move to space_extras
312-- * invited_at rows move to space_member_extras
313-- * `spaces` and `space_members` are dropped, together with every FK that
314-- pointed at `spaces` (local rows keep space_id as a plain UUID).
315-- Idempotent: the block is skipped once `spaces` no longer exists.
316-- ---------------------------------------------------------------------------
317DO $$
318DECLARE
319 fk record;
320BEGIN
321 IF to_regclass('spaces') IS NOT NULL THEN
322 IF to_regclass('space_extras') IS NOT NULL THEN
323 INSERT INTO space_extras (
324 space_id, avatar_url, invite_sort_url_hash,
325 banner_url, banner_width, banner_height,
326 invite_banner_url, invite_banner_width, invite_banner_height,
327 embed_splash_url, embed_splash_width, embed_splash_height,
328 welcome_object, created_at, updated_at
329 )
330 SELECT
331 id, avatar_url, invite_sort_url_hash,
332 banner_url, banner_width, banner_height,
333 invite_banner_url, invite_banner_width, invite_banner_height,
334 embed_splash_url, embed_splash_width, embed_splash_height,
335 welcome_object, created_at, updated_at
336 FROM spaces
337 ON CONFLICT (space_id) DO NOTHING;
338 END IF;
339
340 IF to_regclass('space_member_extras') IS NOT NULL
341 AND to_regclass('space_members') IS NOT NULL THEN
342 INSERT INTO space_member_extras (space_id, user_id, invited_at, created_at, updated_at)
343 SELECT space_id, user_id, invited_at, created_at, COALESCE(updated_at, created_at)
344 FROM space_members
345 ON CONFLICT (space_id, user_id) DO NOTHING;
346 END IF;
347
348 FOR fk IN
349 SELECT conrelid::regclass AS table_name, conname
350 FROM pg_constraint
351 WHERE contype = 'f' AND confrelid = 'spaces'::regclass
352 LOOP
353 EXECUTE format('ALTER TABLE %s DROP CONSTRAINT %I', fk.table_name, fk.conname);
354 END LOOP;
355
356 DROP TABLE IF EXISTS space_members CASCADE;
357 DROP TABLE IF EXISTS spaces CASCADE;
358 END IF;
359END $$;
360
361-- ---------------------------------------------------------------------------
362309-- 2026-10-31: retire the local identity projection.
363310-- KenOAuth owns username / display name / email / account state / password /
364311-- TOTP. Only local settings and a local avatar asset remain in `users`.