fix: make auth SQL bootstrap idempotent#165
Open
bhudevbhanpuriya wants to merge 1 commit into
Open
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR makes the auth database bootstrap script idempotent.
In practice, that means
database/istsos_auth.sqlcan be run more than once without failing just because the expected auth objects already exist.Problem
The script previously assumed it was always running on a fresh database.
Some statements used plain creation commands such as:
Those commands succeed the first time, but fail on a later redeploy or retry because PostgreSQL reports that the column, role, or policy already exists.
What Changed
The initial administrator user insert now uses
ON CONFLICT ("username") DO NOTHING.Auth-related columns now use
ADD COLUMN IF NOT EXISTS.user_idorcommit_idalready exists.The user, guest, and sensor database roles are now created only if they do not already exist.
Anonymous RLS policies are now checked before creation.
Expected Result
Running database/istsos_auth.sql multiple times should no longer fail because of already-existing auth bootstrap objects.