fix: create prosody_unique_index on upgraded databases
Prosody 13's mod_storage_sql upgrade path only warns when the index is missing (it is created only on fresh tables). On DBs upgraded from 0.11.6 the table pre-existed, so the index was never created and has_upsert_index stayed false, disabling ON CONFLICT upserts and degrading write performance. Add an idempotent CREATE UNIQUE INDEX IF NOT EXISTS to both the migration and new-deployment scripts. Part-of: <http://gitlab.vnc.biz/uxf/vnctalk-prosody/-/merge_requests/4>
This commit is contained in:
@@ -35,6 +35,20 @@ begin
|
||||
end if;
|
||||
end $$;
|
||||
|
||||
-- ---------------------------------------------------------------------------
|
||||
-- 0. Create the unique index that Prosody 13 expects on the `prosody` table.
|
||||
--
|
||||
-- On a fresh DB, mod_storage_sql creates `prosody_unique_index` together with
|
||||
-- the table. On a DB upgraded from 0.11.6 the table already existed, so
|
||||
-- Prosody's upgrade path only *warns* ("Index prosody_unique_index does not
|
||||
-- exist") and sets has_upsert_index=false — disabling ON CONFLICT upserts and
|
||||
-- falling back to slower SELECT-then-INSERT/UPDATE. Create it here so the
|
||||
-- index exists after migration and the warning is gone on next startup.
|
||||
-- Idempotent: safe to re-run.
|
||||
-- ---------------------------------------------------------------------------
|
||||
create unique index if not exists prosody_unique_index
|
||||
on prosody ("host", "user", "store", "key");
|
||||
|
||||
-- ---------------------------------------------------------------------------
|
||||
-- 1. Drop obsolete objects that referenced the old `_affiliations` / `_occupants` rows
|
||||
-- ---------------------------------------------------------------------------
|
||||
|
||||
@@ -44,6 +44,16 @@ end $$;
|
||||
|
||||
create extension if not exists pgcrypto;
|
||||
|
||||
-- ---------------------------------------------------------------------------
|
||||
-- prosody_unique_index: the unique index mod_storage_sql creates on the
|
||||
-- `prosody` table (host, user, store, key). On a truly fresh DB Prosody
|
||||
-- creates this itself via create_table(); re-creating it here with IF NOT
|
||||
-- EXISTS is a harmless no-op in that case and fixes deployments where the
|
||||
-- table was created by an older Prosody version without the unique index.
|
||||
-- ---------------------------------------------------------------------------
|
||||
create unique index if not exists prosody_unique_index
|
||||
on prosody ("host", "user", "store", "key");
|
||||
|
||||
-- =============================================================================
|
||||
-- TABLES
|
||||
-- =============================================================================
|
||||
|
||||
Reference in New Issue
Block a user