-
Notifications
You must be signed in to change notification settings - Fork 6
Database change management
Jeff Schwartz edited this page Nov 1, 2023
·
2 revisions
Changes to both the database schema and data are managed via Liquibase. Please see the Liquibase documentation for a better understanding of the main concepts.
The primary changelog is located at database/changelog/changelog-root.yaml
and includes the paths and files of other changelogs. The following table provides a mapping of schema objects to path.
Description | Changelog path | Object source path |
---|---|---|
Table | database/changelog/changelog-tables |
Not applicable. Tables are defined in changelog files. |
Function | database/changelog/changelog-functions |
database/changelog/src/functions |
Procedure | database/changelog/changelog-procedures |
database/changelog/src/procedures |
Trigger | database/changelog/changelog-triggers |
database/changelog/src/triggers |
Anonymous SQL | database/changelog/changelog-anonymous |
Not applicable. The anonymous SQL or PLPGSQL are defined in changelog files. |
Updates to datasets are also handled by changelog config files. These files are located in database/changelog/changelog-data
.
The CircleCI build pipeline includes a job titled apply-database-changes
. The steps of this job are as follows:
- Install dependencies (Cloud Foundry CLI, CF connect-to-service plugin, Java, Liquibase, and Postgresql clients)
- Login to Cloud Foundry using context variables stored in the environment context that is indicated in the workflow section of
config.yml
. - Tunnel to the database via the
connect-to-service
plugin. This step specifies the app and service stored in the target environment context variables. This step uses a non-deterministic approach to determine completion. The tunnel is considered open when the output of theconnect-to-service
command is at least 12 lines. If the tunnel is not opened within approximately 60 seconds, theapply-database-changes
job is halted. - Set environment variables specific to Liquibase from the output of the
connect-to-service
command after the database tunnel is successfully opened. These environment variables areLIQUIBASE_COMMAND_USERNAME
,LIQUIBASE_COMMAND_PASSWORD
, andLIQUIBASE_COMMAND_URL
. - Backup the current state of the database to be uploaded to an S3 bucket just prior to job completion.
- Run the
liquibase update
command to compare the changesets in thedatabasechangelog
table to what is in the current branch and apply any outstanding database schema or data updates. This step is contained in the.circleci/scripts/liquibase.sh
shell script. The script monitors the output of theliquibase update
command to determine if the command errored or resulted in 0 changesets applied. In the event that an error occurs or no database updates are applied, theapply-database-changes
job halts. - If the
liquibase update
command succeeds with applying one or more updates, all static data downloads are regenerated and transferred to an S3 bucket along with the database backup taken previously.
Please consider the following suggestions when applying schema and updates to the database.
- Use Liquibase for all database changes, no matter how trivial.
- When possible, use a change type provided by Liquibase rather than writing raw SQL. For example, use the
createTable
change type when adding a new table. - Create a new changeset for each schema change. (Data changes use the same changelog files but with a new id since these don't otherwise change).
- Use an anonymous changelog for data fixes.
- Scripts for stored procedures, functions, and triggers should attempt to drop the object before creation.
- Problem statement
- Product vision
- User scenarios
- What we're not trying to do
- Product risks
- Prioritization scale
- Technical overview
- Contributing to code
- Creating a new branch
- How to prepare and review PRs
- Releasing changes
- Database change management
- Tech Solutions
- Data overview
- How to upload monthly data
- How to upload OGOR-B Data
- Troubleshooting for specific datasets
- Goals and metrics
- Analytics
- DAP-GA4 templates & instructions
- DAP-UA templates & instructions
- User research plans & findings
- Joining the team
- Onboarding checklist
- Working as a distributed team
- Planning and organizing our work
- Sample retro doc
- Human centered design process
- User research study process
- Design Standards
- Usability testing process
- User research participant guide
- User research agreement
- Observing user research
- Design and research in the federal government
- Shaping process
- Research wiki
- Data catalog
- Problem statement (2016)
- Hypotheses (2016)
- Outcomes workshop (2017)
- Transition goals (2018)
- Product management training (2018)
- Information architecture
- NRRD-flavored Markdown (Jekyll site)
For information about our other website see our ONRR.gov wiki.