-- Bootstrap the UniFi Protect 7.3+ Find Anything vector database (isSearchHost). -- Protect rotates the login password on adoption via changeUserPassword. SET client_min_messages = warning; SELECT 'CREATE ROLE "unifi-protect" WITH LOGIN' WHERE NOT EXISTS (SELECT 1 FROM pg_roles WHERE rolname = 'unifi-protect') \gexec -- PostgreSQL 16+ requires CREATEROLE and ADMIN on the role to rotate its password. SELECT 'CREATE ROLE keystone LOGIN CREATEROLE' WHERE NOT EXISTS (SELECT 1 FROM pg_roles WHERE rolname = 'keystone') \gexec GRANT "unifi-protect" TO keystone WITH ADMIN TRUE, INHERIT FALSE, SET FALSE; -- On a bundled restart, just ensure the rotation role and grant. \if :{?keystone_roles_only} \quit \endif SELECT 'CREATE DATABASE "unifi-protect" OWNER "unifi-protect" ENCODING ''UTF8''' WHERE NOT EXISTS (SELECT 1 FROM pg_database WHERE datname = 'unifi-protect') \gexec \connect "unifi-protect" CREATE EXTENSION IF NOT EXISTS vector; CREATE EXTENSION IF NOT EXISTS pg_trgm; CREATE EXTENSION IF NOT EXISTS intarray;