stripe / pg-schema-diff

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

Allow root db to be something other than postgres in temp db factory #79

Closed bplunkett-stripe closed 10 months ago

bplunkett-stripe commented 10 months ago

Description

Users who don't have access to a postgres database (or don't have a postgres database) are unable to use the tooling. Now, the tempdb will just connect to the provided database and use that to spin off the temporary databases.

Motivation

Bug fix

https://github.com/stripe/pg-schema-diff/issues/78

Testing

  1. ALTER TABLE "public"."foobar" VALIDATE CONSTRAINT "some_constraint"; -- Statement Timeout: 3s

  2. CREATE INDEX CONCURRENTLY some_idx ON public.foobar USING btree (id); -- Statement Timeout: 20m0s -- Lock Timeout: 3s -- Hazard INDEX_BUILD: This might affect database performance. Concurrent index builds require a non-trivial amount of CPU, potentially affecting database performance. They also can take a while but do not lock out writes.

✔ Yes ############################# Executing statement 1 ############################# ALTER TABLE "public"."foobar" ADD CONSTRAINT "some_constraint" CHECK((id > 0)) NOT VALID; -- Statement Timeout: 3s

Finished executing statement. Duration: 3.157042ms ############################# Executing statement 2 ############################# ALTER TABLE "public"."foobar" VALIDATE CONSTRAINT "some_constraint"; -- Statement Timeout: 3s

Finished executing statement. Duration: 941µs ############################# Executing statement 3 ############################# CREATE INDEX CONCURRENTLY some_idx ON public.foobar USING btree (id); -- Statement Timeout: 20m0s -- Lock Timeout: 3s -- Hazard INDEX_BUILD: This might affect database performance. Concurrent index builds require a non-trivial amount of CPU, potentially affecting database performance. They also can take a while but do not lock out writes.

Finished executing statement. Duration: 2.808ms ################################### Complete ################################### Schema applied successfully