Skip to content

bytebase/active-record-example

Repository files navigation

Active Record GitOps Example

A demonstration of Active Record integration with Bytebase API and GitHub Actions GitOps workflow.

Workflow

  1. Developer creates a new migration file in db/migrate/ and applies to the local database.

  2. 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.

  3. Developer creates a PR (Sample) with the .rb and .sql files for review.

  4. bytebase-review-sql.yml GitHub action kicks off and post any warnings. Below shows 2 warnings: NOT NULL violation and missing CONCURRENT when creating index. These rules are configurable.

    sql-review

  5. Back and forth between the developer and the reviewer.

  6. PR is approved and merged to the main branch.

  7. bytebase-roll-out-sql.yml GitHub action kicks off:

    1. Create a Bytebase release.

      release

    2. Create a Bytebase plan based on the release. The plan can target multiple databases. Thus the plan may contain multiple stages and each stage may contain multiple tasks.

    3. Roll out the plan.

      rollout

    4. Rollout completes and Bytebase records the revision.

      revision

How to Sync Active Record schema_migrations table

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 schema_migrations table (Postgres Dialect)

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);

Update the migration history

INSERT INTO schema_migrations (version) VALUES ('20240320121000');

About

Active Record with Bytebase API, GitHub actions

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published