Skip to content

Commit 6fdda1c

Browse files
Misc tweaks
1 parent e95ebeb commit 6fdda1c

File tree

5 files changed

+156
-103
lines changed

5 files changed

+156
-103
lines changed

cmd/pg-schema-diff/plan_cmd.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -112,9 +112,9 @@ type (
112112
includeSchemas []string
113113
excludeSchemas []string
114114

115-
dataPackNewTables bool
116-
disablePlanValidation bool
117-
disableConcurrentIndexOps bool
115+
dataPackNewTables bool
116+
disablePlanValidation bool
117+
noConcurrentIndexOps bool
118118

119119
statementTimeoutModifiers []string
120120
lockTimeoutModifiers []string
@@ -223,7 +223,7 @@ func createPlanOptionsFlags(cmd *cobra.Command) *planOptionsFlags {
223223
cmd.Flags().BoolVar(&flags.dataPackNewTables, "data-pack-new-tables", true, "If set, will data pack new tables in the plan to minimize table size (re-arranges columns).")
224224
cmd.Flags().BoolVar(&flags.disablePlanValidation, "disable-plan-validation", false, "If set, will disable plan validation. Plan validation runs the migration against a temporary"+
225225
"database with an identical schema to the original, asserting that the generated plan actually migrates the schema to the desired target.")
226-
cmd.Flags().BoolVar(&flags.disableConcurrentIndexOps, "disable-concurrent-index-ops", false, "If set, will disable the use of CONCURRENTLY in CREATE INDEX and DROP INDEX statements. "+
226+
cmd.Flags().BoolVar(&flags.noConcurrentIndexOps, "no-concurrent-index-ops", false, "If set, will disable the use of CONCURRENTLY in CREATE INDEX and DROP INDEX statements. "+
227227
"This may result in longer lock times and potential downtime during migrations.")
228228

229229
timeoutModifierFlagVar(cmd, &flags.statementTimeoutModifiers, "statement", "t")
@@ -324,8 +324,8 @@ func parsePlanOptions(p planOptionsFlags) (planOptions, error) {
324324
if p.disablePlanValidation {
325325
opts = append(opts, diff.WithDoNotValidatePlan())
326326
}
327-
if p.disableConcurrentIndexOps {
328-
opts = append(opts, diff.WithDisableConcurrentIndexOps())
327+
if p.noConcurrentIndexOps {
328+
opts = append(opts, diff.WithNoConcurrentIndexOps())
329329
}
330330

331331
var statementTimeoutModifiers []timeoutModifier
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
package migration_acceptance_tests
2+
3+
import (
4+
"testing"
5+
6+
"github.com/stripe/pg-schema-diff/pkg/diff"
7+
)
8+
9+
var indexNoConcurrentAcceptanceTestCases = []acceptanceTestCase{
10+
{
11+
name: "Add",
12+
oldSchemaDDL: []string{
13+
`
14+
CREATE TABLE "Foobar"(
15+
id INT PRIMARY KEY,
16+
"Foo" VARCHAR(255)
17+
);
18+
`,
19+
},
20+
newSchemaDDL: []string{
21+
`
22+
CREATE TABLE "Foobar"(
23+
id INT PRIMARY KEY,
24+
"Foo" VARCHAR(255)
25+
);
26+
CREATE INDEX "Some_idx" ON "Foobar"(id, "Foo");
27+
`,
28+
},
29+
expectedHazardTypes: []diff.MigrationHazardType{
30+
diff.MigrationHazardTypeAcquiresAccessExclusiveLock,
31+
},
32+
planOpts: []diff.PlanOpt{diff.WithNoConcurrentIndexOps()},
33+
},
34+
{
35+
name: "Delete",
36+
oldSchemaDDL: []string{
37+
`
38+
CREATE TABLE "Foobar"(
39+
id INT PRIMARY KEY,
40+
"Foo" VARCHAR(255)
41+
);
42+
CREATE INDEX "Some_idx" ON "Foobar"(id, "Foo");
43+
`,
44+
},
45+
newSchemaDDL: []string{
46+
`
47+
CREATE TABLE "Foobar"(
48+
id INT PRIMARY KEY,
49+
"Foo" VARCHAR(255) NOT NULL
50+
);
51+
`,
52+
},
53+
expectedHazardTypes: []diff.MigrationHazardType{
54+
diff.MigrationHazardTypeAcquiresAccessExclusiveLock,
55+
},
56+
planOpts: []diff.PlanOpt{diff.WithNoConcurrentIndexOps()},
57+
},
58+
}
59+
60+
func TestIndexNoConcurrentTestCases(t *testing.T) {
61+
runTestCases(t, indexNoConcurrentAcceptanceTestCases)
62+
}

internal/pgengine/engine.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ const (
6464
var (
6565
defaultServerConfiguration = map[string]string{
6666
"log_checkpoints": "false",
67+
"max_connections": "1000",
6768
}
6869
)
6970

pkg/diff/plan_generator.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ type (
3535
validatePlan bool
3636
getSchemaOpts []schema.GetSchemaOpt
3737
randReader io.Reader
38-
disableConcurrentIndexOps bool
38+
noConcurrentIndexOps bool
3939
}
4040

4141
PlanOpt func(opts *planOptions)
@@ -103,13 +103,13 @@ func WithRandReader(randReader io.Reader) PlanOpt {
103103
}
104104
}
105105

106-
// WithDisableConcurrentIndexOps disables the use of CONCURRENTLY in CREATE INDEX and DROP INDEX statements.
106+
// WithNoConcurrentIndexOps disables the use of CONCURRENTLY in CREATE INDEX and DROP INDEX statements.
107107
// This can be useful when you need simpler DDL statements or when working in environments that don't support
108108
// concurrent index operations. Note that disabling concurrent operations may result in longer lock times
109109
// and potential downtime during migrations.
110-
func WithDisableConcurrentIndexOps() PlanOpt {
110+
func WithNoConcurrentIndexOps() PlanOpt {
111111
return func(opts *planOptions) {
112-
opts.disableConcurrentIndexOps = true
112+
opts.noConcurrentIndexOps = true
113113
}
114114
}
115115

0 commit comments

Comments
 (0)