-- ============================================================================= -- Enablement — "Onboarding" mshowspace seed (PostgreSQL variant) -- See the SQL Server companion file for full context. -- -- SpaceId is reserved from mautonumber (entitycode = 'SHOWSPACE') using the same -- pre-increment-value convention this repo's other Postgres seed migrations already use -- (e.g. 20260817_Enablement_ModuleSeed_Postgres.sql's v_new_module_id), which matches -- AutoNumber.GetNumberAsync's own firstNumber formula for noOfId=1. No C# code hardcodes -- this row's numeric id — EmployeeOnboardedSubscriber.cs resolves it at runtime by -- spacecode ('ONBOARDING') via IShowSpaceSubscriptionBLL.GetMySpacesAsync. -- ============================================================================= DO $$ DECLARE v_onboarding_space_id BIGINT; BEGIN IF NOT EXISTS (SELECT 1 FROM mshowspace WHERE spacecode = 'ONBOARDING' AND tenantid = -1) THEN IF NOT EXISTS (SELECT 1 FROM mautonumber WHERE entitycode = 'SHOWSPACE') THEN RAISE EXCEPTION 'mautonumber row for entitycode = ''SHOWSPACE'' not found — EnablementBLL.ShowSpace.ShowSpaceBLL depends on this already existing. Fix mautonumber before re-running this migration.'; END IF; UPDATE mautonumber SET autoid = autoid + 1 WHERE entitycode = 'SHOWSPACE' RETURNING autoid INTO v_onboarding_space_id; v_onboarding_space_id := v_onboarding_space_id - 1; INSERT INTO mshowspace (spaceid, spacecode, spacename, description, ownerteam, icon, colorhex, subscriptiontype, autosubscriberule, isactive, version, status, sortorder, createdbyid, createdon, modifiedbyid, modifiedon, sourcetype, tenantid) VALUES (v_onboarding_space_id, 'ONBOARDING', 'Onboarding', 'Force-subscribed Space for newly-created employees (Recruitment/PayRoll -> Enablement Phase 3 hire bridge).', 'HR', '🎓', '#2563EB', 2, 3, 1, 0, 1, 100, -1, now(), -1, now(), 5, -1); END IF; END $$; -- ============================================================================= -- END OF MIGRATION 20260903_Enablement_OnboardingSpace_Seed (PostgreSQL variant) -- =============================================================================