Skip to content
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

feat: add pg-schema as a new diff tool #1890

Merged
merged 2 commits into from
Feb 16, 2024
Merged

feat: add pg-schema as a new diff tool #1890

merged 2 commits into from
Feb 16, 2024

Conversation

sweatybridge
Copy link
Contributor

@sweatybridge sweatybridge commented Jan 28, 2024

What kind of change does this PR introduce?

PoC stripe/pg-schema-diff#85

What is the new behavior?

$ supabase db diff --schema public --use-pg-schema
Diffing schemas: public
Creating shadow database...
Setting up initial schema...
Creating custom roles supabase/roles.sql...
Finished supabase db diff on branch pg-diff.

-- HAS_UNTRACKABLE_DEPENDENCIES: This sequence has no owner, so it cannot be tracked. It may be in use by a table or function.
CREATE SEQUENCE "public"."employees_id_seq"
	AS integer
	INCREMENT BY 1
	MINVALUE 1 MAXVALUE 2147483647
	START WITH 1 CACHE 1 NO CYCLE
;
CREATE TABLE "employees" (
	"id" integer NOT NULL,
	"name" text COLLATE "pg_catalog"."default",
	"age" smallint NOT NULL
);
CREATE UNIQUE INDEX CONCURRENTLY employees_pkey ON public.employees USING btree (id);
ALTER TABLE "public"."employees" ADD CONSTRAINT "employees_pkey" PRIMARY KEY USING INDEX "employees_pkey";

TODO:

  • find out why shadow database is created twice
  • support remote -> local diff (currently impl requires a db factory)
  • support more pg entities, including custom types, RLS policies, etc

Additional context

  1. create an empty database: supabase db start
  2. create a schema file and save to supabase/migrations/0_schema.sql
create table public.employees (
    id integer primary key generated always as identity,
    name text,
    age smallint not null
);

@sweatybridge sweatybridge requested a review from a team as a code owner January 28, 2024 07:26
@coveralls
Copy link

coveralls commented Jan 28, 2024

Pull Request Test Coverage Report for Build 7720255566

Warning: This coverage report may be inaccurate.

We've detected an issue with your CI configuration that might affect the accuracy of this pull request's coverage report.
To ensure accuracy in future PRs, please see these guidelines.
A quick fix for this PR: rebase it; your next report should be accurate.

  • -106 of 109 (2.75%) changed or added relevant lines in 3 files are covered.
  • 9 unchanged lines in 3 files lost coverage.
  • Overall coverage decreased (-0.6%) to 58.085%

Changes Missing Coverage Covered Lines Changed/Added Lines %
cmd/db.go 1 6 16.67%
internal/db/diff/schema.go 0 101 0.0%
Files with Coverage Reduction New Missed Lines %
cmd/db.go 1 59.52%
internal/debug/postgres.go 3 64.86%
internal/gen/keys/keys.go 5 11.76%
Totals Coverage Status
Change from base Build 7692683417: -0.6%
Covered Lines: 6157
Relevant Lines: 10600

💛 - Coveralls

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

renamed from migra.go

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

renamed from diff.go

@sweatybridge sweatybridge merged commit 3043243 into main Feb 16, 2024
9 checks passed
@sweatybridge sweatybridge deleted the pg-diff branch February 16, 2024 09:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants