Skip to content

Commit c63b0b7

Browse files
Support multiple sql dirs (stripe#150)
1 parent 4fc0bff commit c63b0b7

1 file changed

Lines changed: 10 additions & 6 deletions

File tree

cmd/pg-schema-diff/plan_cmd.go

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ type (
7676
}
7777

7878
schemaSourceFlags struct {
79-
schemaDir string
79+
schemaDirs []string
8080
targetDatabaseDSN string
8181
}
8282

@@ -145,7 +145,7 @@ func createPlanFlags(cmd *cobra.Command) *planFlags {
145145
}
146146

147147
func schemaSourceFlagsVar(cmd *cobra.Command, p *schemaSourceFlags) {
148-
cmd.Flags().StringVar(&p.schemaDir, "schema-dir", "", "Directory of .SQL files to use as the schema source. Use to generate a diff between the target database and the schema in this directory.")
148+
cmd.Flags().StringArrayVar(&p.schemaDirs, "schema-dir", nil, "Directory of .SQL files to use as the schema source (can be multiple). Use to generate a diff between the target database and the schema in this directory.")
149149
if err := cmd.MarkFlagDirname("schema-dir"); err != nil {
150150
panic(err)
151151
}
@@ -222,10 +222,14 @@ func parsePlanConfig(p planFlags) (planConfig, error) {
222222
}
223223

224224
func parseSchemaSource(p schemaSourceFlags) (schemaSourceFactory, error) {
225-
if p.schemaDir != "" {
226-
ddl, err := getDDLFromPath(p.schemaDir)
227-
if err != nil {
228-
return nil, err
225+
if len(p.schemaDirs) > 0 {
226+
var ddl []string
227+
for _, schemaDir := range p.schemaDirs {
228+
stmts, err := getDDLFromPath(schemaDir)
229+
if err != nil {
230+
return nil, fmt.Errorf("getting DDL from path %q: %w", schemaDir, err)
231+
}
232+
ddl = append(ddl, stmts...)
229233
}
230234
return func() (diff.SchemaSource, io.Closer, error) {
231235
return diff.DDLSchemaSource(ddl), nil, nil

0 commit comments

Comments
 (0)