Track every change to Oracle SQL by combining Git workflows with an in-database query_versions table.
Version control preserves each change, enables rollbacks, and lets teams collaborate safely without pasting SQL in chat tools.
Most teams use Git plus pull requests. Liquibase, Flyway, and Sqitch add migration tracking, but plain Git handles ad-hoc reports well.
Create folders like /reports
, /etl
, and /dashboards
. Use clear names: monthly_active_customers.sql
.
Add a query_versions
table that stores the SQL text, author, commit hash, and endorsement status. An API or trigger can insert a Git commit SHA automatically.
The table includes id
, query_name
, version_no
, git_commit
, sql_text
, is_endorsed
, and created_at
.
Select with ORDER BY version_no DESC
and is_endorsed = true
to get production-ready SQL.
Commit small changes, reference ticket IDs, add unit tests, tag releases, and use CI pipelines to run syntax checks before merge.
Not necessarily. Plain Git works for report queries, while migration tools shine when you version schema changes.
Store the query_name and version_no in your application config or use is_endorsed
so dashboards always fetch the approved SQL.