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

Update CLI with multi-schema support and database schema source #108

Merged

Conversation

bplunkett-stripe
Copy link
Collaborator

@bplunkett-stripe bplunkett-stripe commented Feb 8, 2024

Description

  • Add multi-schema support to CLI
  • Add support for a database schema source to the CLI

In a follow-up PR, I'm going to update the statement modifiers to follow logfmt. The current way they are specified is awful.

Motivation

#105

Testing

Normal (notice the some_schema related operations):

 ~/stripe/pg-schema-diff │ bplunkett/up…hema-support  go run ./cmd/pg-schema-diff plan  --dsn "host=localhost user=postgres password=postgres database=somedb" --schema-dir ~/stripe/temp/examplesql

################################ Generated plan ################################
1. CREATE TABLE "public"."foobar" (
        "id" integer,
        "some_other_column" character varying(255) COLLATE "pg_catalog"."default",
        "fizz" character varying(255) COLLATE "pg_catalog"."default"
);
        -- Statement Timeout: 3s

2. ALTER TABLE "public"."foobar" ADD CONSTRAINT "some_constraint" CHECK((id > 0));
        -- Statement Timeout: 3s

3. ALTER TABLE "public"."foobar" REPLICA IDENTITY FULL;
        -- Statement Timeout: 3s

4. CREATE INDEX CONCURRENTLY some_idx ON public.foobar USING btree (id);
        -- Statement Timeout: 20m0s
        -- Lock Timeout: 3s

5. DROP TABLE "some_schema"."foobar";
        -- Statement Timeout: 20m0s
        -- Lock Timeout: 3s
        -- Hazard DELETES_DATA: Deletes all rows in the table (and the table itself)

6. DROP SCHEMA "some_schema";
        -- Statement Timeout: 3s

Include schemas (public only):

 ~/stripe/pg-schema-diff │ bplunkett/up…hema-support  go run ./cmd/pg-schema-diff plan  --dsn "host=localhost user=postgres password=postgres database=somedb" --schema-dir ~/stripe/temp/examplesql --include-schema public

################################ Generated plan ################################
1. CREATE TABLE "public"."foobar" (
        "id" integer,
        "some_other_column" character varying(255) COLLATE "pg_catalog"."default",
        "fizz" character varying(255) COLLATE "pg_catalog"."default"
);
        -- Statement Timeout: 3s

2. ALTER TABLE "public"."foobar" ADD CONSTRAINT "some_constraint" CHECK((id > 0));
        -- Statement Timeout: 3s

3. ALTER TABLE "public"."foobar" REPLICA IDENTITY FULL;
        -- Statement Timeout: 3s

4. CREATE INDEX CONCURRENTLY some_idx ON public.foobar USING btree (id);
        -- Statement Timeout: 20m0s
        -- Lock Timeout: 3s

Exclude schemas (public only):

go run ./cmd/pg-schema-diff plan  --dsn "host=localhost user=postgres password=postgres database=somedb" --schema-dir ~/stripe/temp/examplesql --exclude-schema some_schema

################################ Generated plan ################################
1. CREATE TABLE "public"."foobar" (
        "id" integer,
        "some_other_column" character varying(255) COLLATE "pg_catalog"."default",
        "fizz" character varying(255) COLLATE "pg_catalog"."default"
);
        -- Statement Timeout: 3s

2. ALTER TABLE "public"."foobar" ADD CONSTRAINT "some_constraint" CHECK((id > 0));
        -- Statement Timeout: 3s

3. ALTER TABLE "public"."foobar" REPLICA IDENTITY FULL;
        -- Statement Timeout: 3s

4. CREATE INDEX CONCURRENTLY some_idx ON public.foobar USING btree (id);
        -- Statement Timeout: 20m0s
        -- Lock Timeout: 3s

Comparing two databases:

go run ./cmd/pg-schema-diff plan  --dsn "host=localhost user=postgres password=postgres database=somedb"  --include-schema public  --schema-source-dsn "host=localhost user=postgres password=postgres database=postgres"

################################ Generated plan ################################
1. CREATE TABLE "public"."foobar" (

);
        -- Statement Timeout: 3s

No source specified:

 ~/stripe/pg-schema-diff │ bplunkett/up…hema-support  go run ./cmd/pg-schema-diff plan  --dsn "host=localhost user=postgres password=postgres database=somedb"                          INT х │ 15:17:22
Error: either --schema-dir or --schema-source-dsn must be set
Usage:
  pg-schema-diff plan [flags]

@bplunkett-stripe bplunkett-stripe added the enhancement New feature or request label Feb 8, 2024
@bplunkett-stripe bplunkett-stripe force-pushed the bplunkett/update-cli-with-multi-schema-support branch from d9408cf to 935facf Compare February 8, 2024 09:14
@bplunkett-stripe bplunkett-stripe marked this pull request as ready for review February 8, 2024 23:18
@bplunkett-stripe bplunkett-stripe merged commit 7fc1d07 into main Feb 8, 2024
6 checks passed
@bplunkett-stripe bplunkett-stripe deleted the bplunkett/update-cli-with-multi-schema-support branch February 9, 2024 03:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants