A demonstration of Active Record integration with Bytebase API and GitHub Actions GitOps workflow.
-
Developer creates a new migration file in
db/migrate/
and applies to the local database. -
When developer finishes the local development, they can run
rake db:to_sql
to generate the raw SQL file. The file is co-located with the.rb
migration file. -
Developer creates a PR (Sample) with the
.rb
and.sql
files for review. -
bytebase-review-sql.yml
GitHub action kicks off and post any warnings. Below shows 2 warnings:NOT NULL
violation and missingCONCURRENT
when creating index. These rules are configurable. -
Back and forth between the developer and the reviewer.
-
PR is approved and merged to the main branch.
-
bytebase-roll-out-sql.yml
GitHub action kicks off:
Active Record creates its own schema_migrations
table to track the migration history. Because you are deploying schema migrations
via Bytebase, if you want to keep updating the schema_migrations
table, you need to manually create and update it.
CREATE SEQUENCE public.schema_migrations_id_seq;
CREATE TABLE public.schema_migrations (
id bigint PRIMARY KEY DEFAULT nextval('public.schema_migrations_id_seq'),
version character varying NOT NULL
);
CREATE UNIQUE INDEX index_schema_migrations_on_version ON public.schema_migrations (version);
INSERT INTO schema_migrations (version) VALUES ('20240320121000');