Skip to content

Remove State.LastSchema method #909

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 17, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pkg/roll/execute.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func (m *Roll) Validate(ctx context.Context, migration *migrations.Migration) er
if m.skipValidation {
return nil
}
lastSchema, err := m.state.LastSchema(ctx, m.schema)
lastSchema, err := m.state.ReadSchema(ctx, m.schema)
if err != nil {
return err
}
Expand Down
21 changes: 0 additions & 21 deletions pkg/state/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -328,27 +328,6 @@ func (s *State) Start(ctx context.Context, schemaname string, migration *migrati
return err
}

func (s *State) LastSchema(ctx context.Context, schemaname string) (*schema.Schema, error) {
stmt := fmt.Sprintf(`SELECT COALESCE(
(SELECT resulting_schema FROM %[1]s.migrations WHERE schema=$1 AND name=%[1]s.latest_version($1)),
%[1]s.read_schema($1))`,
pq.QuoteIdentifier(s.schema))

var rawSchema string
err := s.pgConn.QueryRowContext(ctx, stmt, schemaname).Scan(&rawSchema)
if err != nil {
return nil, err
}

var unmarshalledSchema schema.Schema
err = json.Unmarshal([]byte(rawSchema), &unmarshalledSchema)
if err != nil {
return nil, fmt.Errorf("unable to unmarshal schema: %w", err)
}

return &unmarshalledSchema, nil
}

// Complete marks a migration as completed
func (s *State) Complete(ctx context.Context, schema, name string) error {
res, err := s.pgConn.ExecContext(ctx, fmt.Sprintf("UPDATE %[1]s.migrations SET done=$1, resulting_schema=(SELECT %[1]s.read_schema($2)) WHERE schema=$2 AND name=$3 AND done=$4", pq.QuoteIdentifier(s.schema)), true, schema, name, false)
Expand Down
2 changes: 1 addition & 1 deletion pkg/state/state_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func TestSchemaOptionIsRespected(t *testing.T) {
}

// check that we can retrieve the already existing table
currentSchema, err := state.LastSchema(ctx, "public")
currentSchema, err := state.ReadSchema(ctx, "public")
assert.NoError(t, err)

assert.Equal(t, 1, len(currentSchema.Tables))
Expand Down
Loading