stripe / pg-schema-diff

Go library for diffing Postgres schemas and generating SQL migrations
MIT License
316 stars 23 forks source link

Fix whitespace in PARTITION BY clause #39

Closed alexaub-stripe closed 1 year ago

alexaub-stripe commented 1 year ago

Description

Noticed that there's a space missing between a create table statement and its partition by clause. This was not an issue before because postgres considers the word after a closing paren to be a new token, even if there's no space. This fix is purely stylistic

CREATE TABLE(...)PARTITION BY ... -> CREATE TABLE(...) PARTITION BY ...
                                                      ^
                                                      |

Motivation

Saw this while generating a plan

Testing

Added a plan unit test covering a raw table create with partition.

Before:

alexaub in ~/stripe/pg-schema-diff on alexaub/partition-whitespace ● λ pg-schema-diff plan --dsn "postgres://alexaub@localhost:5432/postgres" --schema-dir schema

################################ Generated plan ################################
1. CREATE TABLE "foobar" (
    "id" integer,
    "foo" character varying(255) COLLATE "pg_catalog"."default"
)PARTITION BY LIST (foo);
    -- Timeout: 3s

After:

alexaub in ~/stripe/pg-schema-diff on alexaub/partition-whitespace ● λ go run ./cmd/pg-schema-diff plan --dsn "postgres://alexaub@localhost:5432/postgres" --schema-dir schema

################################ Generated plan ################################
1. CREATE TABLE "foobar" (
    "id" integer,
    "foo" character varying(255) COLLATE "pg_catalog"."default"
) PARTITION BY LIST (foo);
    -- Timeout: 3s