-- Fix final_lines_summary view -- -- New schema version: 0.6.1 -- -- ATTENTION: -- -- ENSURE YOU HAVE BACKED UP THE DATABASE BEFORE RUNNING THIS SCRIPT. -- -- -- NOTE: This upgrade only affects the `public` schema. -- NOTE: Each application starts a transaction, which must be committed -- or rolled back. -- -- This update adds a default user to the system (see #176, #177, #180). -- The default user can only be invoked by connecting from localhost. -- -- This user has full access to every project via the organisations -- permissions wildcard: `{"*": {read: true, write: true, edit: true}}` -- and can be used to bootstrap the system by creating other users -- and assigning organisational permissions. -- -- To apply, run as the dougal user: -- -- psql <>'db_schema' INTO current_db_version FROM public.info WHERE key = 'version'; IF current_db_version >= '0.6.1' THEN RAISE EXCEPTION USING MESSAGE='Patch already applied'; END IF; IF current_db_version != '0.6.0' THEN RAISE EXCEPTION USING MESSAGE='Invalid database version: ' || current_db_version, HINT='Ensure all previous patches have been applied.'; END IF; CALL pg_temp.upgrade_database(); END; $outer$ LANGUAGE plpgsql; CALL pg_temp.upgrade(); CALL pg_temp.show_notice('Cleaning up'); DROP PROCEDURE pg_temp.upgrade_database (); DROP PROCEDURE pg_temp.upgrade (); CALL pg_temp.show_notice('Updating db_schema version'); INSERT INTO public.info VALUES ('version', '{"db_schema": "0.6.1"}') ON CONFLICT (key) DO UPDATE SET value = public.info.value || '{"db_schema": "0.6.1"}' WHERE public.info.key = 'version'; CALL pg_temp.show_notice('All done. You may now run "COMMIT;" to persist the changes'); DROP PROCEDURE pg_temp.show_notice (notice text); -- --NOTE Run `COMMIT;` now if all went well --