Skip to content

Commit 716f47f

Browse files
Remove redundant parameter from previous_migration function (#914)
Remove the `includeInferred` parameter from the `previous_migration` SQL function as it was set to `true` at all call sites. Part of #872
1 parent 542166f commit 716f47f

File tree

3 files changed

+6
-17
lines changed

3 files changed

+6
-17
lines changed

pkg/roll/execute.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -269,8 +269,8 @@ func (m *Roll) Rollback(ctx context.Context) error {
269269
m.logger.LogSchemaDeletion(migration.Name, versionSchema)
270270
}
271271

272-
// get the name of the previous version of the schema
273-
previousMigration, err := m.state.PreviousMigration(ctx, m.schema, true)
272+
// get the name of the previous migration
273+
previousMigration, err := m.state.PreviousMigration(ctx, m.schema)
274274
if err != nil {
275275
return fmt.Errorf("unable to get name of previous version: %w", err)
276276
}

pkg/state/init.sql

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -173,9 +173,7 @@ LANGUAGE SQL
173173
STABLE;
174174

175175
-- Get the name of the previous migration, or NULL if there is none.
176-
-- This ignores previous versions for which no version schema exists, such as
177-
-- versions corresponding to inferred migrations.
178-
CREATE OR REPLACE FUNCTION placeholder.previous_migration (schemaname name, includeInferred boolean)
176+
CREATE OR REPLACE FUNCTION placeholder.previous_migration (schemaname name)
179177
RETURNS text
180178
AS $$
181179
WITH RECURSIVE ancestors AS (
@@ -208,15 +206,6 @@ CREATE OR REPLACE FUNCTION placeholder.previous_migration (schemaname name, incl
208206
ancestors a
209207
WHERE
210208
a.depth > 0
211-
AND (includeInferred
212-
OR (a.migration_type = 'pgroll'
213-
AND EXISTS (
214-
SELECT
215-
s.schema_name
216-
FROM
217-
information_schema.schemata s
218-
WHERE
219-
s.schema_name = schemaname || '_' || a.name)))
220209
ORDER BY
221210
a.depth ASC
222211
LIMIT 1;

pkg/state/state.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -266,11 +266,11 @@ func (s *State) PreviousVersion(ctx context.Context, schema string, includeInfer
266266
}
267267

268268
// PreviousMigration returns the name of the previous migration
269-
func (s *State) PreviousMigration(ctx context.Context, schema string, includeInferred bool) (*string, error) {
269+
func (s *State) PreviousMigration(ctx context.Context, schema string) (*string, error) {
270270
var parent *string
271271
err := s.pgConn.QueryRowContext(ctx,
272-
fmt.Sprintf("SELECT %s.previous_migration($1, $2)", pq.QuoteIdentifier(s.schema)),
273-
schema, includeInferred).Scan(&parent)
272+
fmt.Sprintf("SELECT %s.previous_migration($1)", pq.QuoteIdentifier(s.schema)),
273+
schema).Scan(&parent)
274274
if err != nil {
275275
return nil, err
276276
}

0 commit comments

Comments
 (0)