3333 logger log.Logger
3434 validatePlan bool
3535 getSchemaOpts []schema.GetSchemaOpt
36+ reverse bool
3637 }
3738
3839 PlanOpt func (opts * planOptions )
@@ -93,6 +94,13 @@ func WithGetSchemaOpts(getSchemaOpts ...externalschema.GetSchemaOpt) PlanOpt {
9394 }
9495}
9596
97+ // WithReverse return a diff to generate statements to migrate the schema to the current database
98+ func WithReverse () PlanOpt {
99+ return func (opts * planOptions ) {
100+ opts .reverse = true
101+ }
102+ }
103+
96104// deprecated: GeneratePlan generates a migration plan to migrate the database to the target schema. This function only
97105// diffs the public schemas.
98106//
@@ -127,6 +135,7 @@ func Generate(
127135 validatePlan : true ,
128136 ignoreChangesToColOrder : true ,
129137 logger : log .SimpleLogger (),
138+ reverse : false ,
130139 }
131140 for _ , opt := range opts {
132141 opt (planOptions )
@@ -145,6 +154,10 @@ func Generate(
145154 return Plan {}, fmt .Errorf ("getting new schema: %w" , err )
146155 }
147156
157+ if planOptions .reverse {
158+ currentSchema , newSchema = newSchema , currentSchema
159+ }
160+
148161 statements , err := generateMigrationStatements (currentSchema , newSchema , planOptions )
149162 if err != nil {
150163 return Plan {}, fmt .Errorf ("generating plan statements: %w" , err )
0 commit comments