You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+54-26Lines changed: 54 additions & 26 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -29,19 +29,28 @@ index cc3a14b..cf4b32d 100644
29
29
The generated plan (*queries using `message_idx` will always have an index backing them, even while the new index is being built*):
30
30
```
31
31
$ pg-schema-diff plan --from-dsn "postgres://postgres:postgres@localhost:5432/postgres" --to-dir ./schema
32
-
################################ Generated plan ################################
33
-
1. ALTER INDEX "message_idx" RENAME TO "pgschemadiff_tmpidx_message_idx_IiaKzkvPQtyA7ob9piVqiQ";
34
-
-- Statement Timeout: 3s
35
-
36
-
2. CREATE INDEX CONCURRENTLY message_idx ON public.foobar USING btree (message, created_at);
37
-
-- Statement Timeout: 20m0s
38
-
-- Lock Timeout: 3s
39
-
-- 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.
40
-
41
-
3. DROP INDEX CONCURRENTLY "pgschemadiff_tmpidx_message_idx_IiaKzkvPQtyA7ob9piVqiQ";
42
-
-- Statement Timeout: 20m0s
43
-
-- Lock Timeout: 3s
44
-
-- Hazard INDEX_DROPPED: Dropping this index means queries that use this index might perform worse because they will no longer will be able to leverage it.
32
+
/*
33
+
Statement 0
34
+
*/
35
+
SET SESSION statement_timeout = 3000;
36
+
SET SESSION lock_timeout = 3000;
37
+
ALTER INDEX "public"."message_idx" RENAME TO "pgschemadiff_tmpidx_message_idx_cWw18w4cQ_i7MKzfy7ek9g";
38
+
39
+
/*
40
+
Statement 1
41
+
- 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.
42
+
*/
43
+
SET SESSION statement_timeout = 1200000;
44
+
SET SESSION lock_timeout = 3000;
45
+
CREATE INDEX CONCURRENTLY message_idx ON public.foobar USING btree (message, created_at);
46
+
47
+
/*
48
+
Statement 2
49
+
- INDEX_DROPPED: Dropping this index means queries that use this index might perform worse because they will no longer will be able to leverage it.
50
+
*/
51
+
SET SESSION statement_timeout = 1200000;
52
+
SET SESSION lock_timeout = 3000;
53
+
DROP INDEX CONCURRENTLY "public"."pgschemadiff_tmpidx_message_idx_cWw18w4cQ_i7MKzfy7ek9g";
45
54
```
46
55
### Online `NOT NULL` constraint creation
47
56
Your project's diff:
@@ -61,18 +70,33 @@ index cc3a14b..5a1cec2 100644
61
70
The generated plan (*leverages check constraints to eliminate the need for a long-lived access-exclusive lock on the table*):
62
71
```
63
72
$ pg-schema-diff plan --from-dsn "postgres://postgres:postgres@localhost:5432/postgres" --to-dir ./schema
64
-
################################ Generated plan ################################
65
-
1. ALTER TABLE "public"."foobar" ADD CONSTRAINT "pgschemadiff_tmpnn_BCOxMXqAQwaXlKPCRXoMMg" CHECK("created_at" IS NOT NULL) NOT VALID;
66
-
-- Statement Timeout: 3s
67
-
68
-
2. ALTER TABLE "public"."foobar" VALIDATE CONSTRAINT "pgschemadiff_tmpnn_BCOxMXqAQwaXlKPCRXoMMg";
69
-
-- Statement Timeout: 3s
70
-
71
-
3. ALTER TABLE "public"."foobar" ALTER COLUMN "created_at" SET NOT NULL;
72
-
-- Statement Timeout: 3s
73
-
74
-
4. ALTER TABLE "public"."foobar" DROP CONSTRAINT "pgschemadiff_tmpnn_BCOxMXqAQwaXlKPCRXoMMg";
75
-
-- Statement Timeout: 3s
73
+
/*
74
+
Statement 0
75
+
*/
76
+
SET SESSION statement_timeout = 3000;
77
+
SET SESSION lock_timeout = 3000;
78
+
ALTER TABLE "public"."foobar" ADD CONSTRAINT "pgschemadiff_tmpnn_GimngG1rRkODhKvgjhGfNA" CHECK("created_at" IS NOT NULL) NOT VALID;
79
+
80
+
/*
81
+
Statement 1
82
+
*/
83
+
SET SESSION statement_timeout = 3000;
84
+
SET SESSION lock_timeout = 3000;
85
+
ALTER TABLE "public"."foobar" VALIDATE CONSTRAINT "pgschemadiff_tmpnn_GimngG1rRkODhKvgjhGfNA";
86
+
87
+
/*
88
+
Statement 2
89
+
*/
90
+
SET SESSION statement_timeout = 3000;
91
+
SET SESSION lock_timeout = 3000;
92
+
ALTER TABLE "public"."foobar" ALTER COLUMN "created_at" SET NOT NULL;
93
+
94
+
/*
95
+
Statement 3
96
+
*/
97
+
SET SESSION statement_timeout = 3000;
98
+
SET SESSION lock_timeout = 3000;
99
+
ALTER TABLE "public"."foobar" DROP CONSTRAINT "pgschemadiff_tmpnn_GimngG1rRkODhKvgjhGfNA";
76
100
```
77
101
78
102
# Key features
@@ -90,10 +114,14 @@ $ pg-schema-diff plan --from-dsn "postgres://postgres:postgres@localhost:5432/po
90
114
* Strong support of partitions
91
115
# Install
92
116
## CLI
117
+
Brew:
118
+
```bash
119
+
brew install pg-schema-diff
120
+
```
121
+
Go toolchain:
93
122
```bash
94
123
go install github.com/stripe/pg-schema-diff/cmd/pg-schema-diff@latest
0 commit comments