Skip to content

Commit

Permalink
Update usages of fields in OpCreateIndex struct
Browse files Browse the repository at this point in the history
These fields are now non-pointer values.
  • Loading branch information
andrew-farries committed Dec 22, 2024
1 parent b9ba29f commit ff0e70f
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
14 changes: 7 additions & 7 deletions pkg/migrations/op_create_index.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,27 +20,27 @@ func (o *OpCreateIndex) Start(ctx context.Context, conn db.DB, latestSchema stri

// create index concurrently
stmtFmt := "CREATE INDEX CONCURRENTLY %s ON %s"
if o.Unique != nil && *o.Unique {
if o.Unique {
stmtFmt = "CREATE UNIQUE INDEX CONCURRENTLY %s ON %s"
}
stmt := fmt.Sprintf(stmtFmt,
pq.QuoteIdentifier(o.Name),
pq.QuoteIdentifier(table.Name))

if o.Method != nil {
stmt += fmt.Sprintf(" USING %s", string(*o.Method))
if o.Method != "" {
stmt += fmt.Sprintf(" USING %s", string(o.Method))
}

stmt += fmt.Sprintf(" (%s)", strings.Join(
quoteColumnNames(table.PhysicalColumnNamesFor(o.Columns...)), ", "),
)

if o.StorageParameters != nil {
stmt += fmt.Sprintf(" WITH (%s)", *o.StorageParameters)
if o.StorageParameters != "" {
stmt += fmt.Sprintf(" WITH (%s)", o.StorageParameters)
}

if o.Predicate != nil {
stmt += fmt.Sprintf(" WHERE %s", *o.Predicate)
if o.Predicate != "" {
stmt += fmt.Sprintf(" WHERE %s", o.Predicate)
}

_, err := conn.ExecContext(ctx, stmt)
Expand Down
6 changes: 3 additions & 3 deletions pkg/migrations/op_create_index_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ func TestCreateIndex(t *testing.T) {
Name: "idx_users_name_after_2019",
Table: "users",
Columns: []string{"registered_at_year"},
Predicate: ptr("registered_at_year > 2019"),
Predicate: "registered_at_year > 2019",
},
},
},
Expand Down Expand Up @@ -235,8 +235,8 @@ func TestCreateIndex(t *testing.T) {
Name: "idx_users_name_hash",
Table: "users",
Columns: []string{"name"},
Method: ptr(migrations.OpCreateIndexMethodHash),
StorageParameters: ptr("fillfactor = 70"),
Method: migrations.OpCreateIndexMethodHash,
StorageParameters: "fillfactor = 70",
},
},
},
Expand Down

0 comments on commit ff0e70f

Please sign in to comment.