-
Notifications
You must be signed in to change notification settings - Fork 292
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Organize DB Schema Migration Code and DB Init Checks #842
Conversation
…command is created. Replaced additional context.TODOs with context.Backgrounds.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks great.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall it looks great! Just a few questions and suggestions.
internal/db/schema/schema.go
Outdated
return false, err | ||
} | ||
if st.Dirty { | ||
return false, fmt.Errorf("The passed in database has had a failed migration applied to it.") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have the same question
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great job!
// https://www.postgresql.org/docs/9.6/static/explicit-locking.html#ADVISORY-LOCKS | ||
func (p *Postgres) TrySharedLock(ctx context.Context) error { | ||
const op = "postgres.(Postgres).TrySharedLock" | ||
r := p.conn.QueryRowContext(ctx, "SELECT pg_try_advisory_lock_shared($1)", schemaAccessLockId) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Previous comments are not showing up for some reason.
Me:
Why is there no equivalent unlock method for this (
select pg_advisory_unlock_shared($1)
)?
Todd:
Just because we do not have a use for it yet.
Shouldn't we be releasing the lock by calling select pg_advisory_unlock_shared($1)
? Or are we just letting Postgres do the cleanup when the connection closes? If it is the latter, are there any dangers on relying on that?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great.
Reorganizes the code which applies schema changes in Boundary and sets up the ability (in future PRs) to migrate to newer versions of the database schema when needed.
Added checks when
boundary server -config
starts a controller to ensure that the database was initialized correctly. Also checks inboundary database init -config
to ensure the database is in a state that can be initialized.Fixes #805