diff --git a/pkg/migrations/op_create_index.go b/pkg/migrations/op_create_index.go index 7408471b..80f71de4 100644 --- a/pkg/migrations/op_create_index.go +++ b/pkg/migrations/op_create_index.go @@ -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) diff --git a/pkg/migrations/op_create_index_test.go b/pkg/migrations/op_create_index_test.go index ad8c67af..a47cf1f5 100644 --- a/pkg/migrations/op_create_index_test.go +++ b/pkg/migrations/op_create_index_test.go @@ -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", }, }, }, @@ -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", }, }, }, diff --git a/pkg/migrations/types.go b/pkg/migrations/types.go index 2346d0ba..888d1909 100644 --- a/pkg/migrations/types.go +++ b/pkg/migrations/types.go @@ -177,22 +177,22 @@ type OpCreateIndex struct { Columns []string `json:"columns"` // Index method to use for the index: btree, hash, gist, spgist, gin, brin - Method *OpCreateIndexMethod `json:"method,omitempty"` + Method OpCreateIndexMethod `json:"method,omitempty"` // Index name Name string `json:"name"` // Conditional expression for defining a partial index - Predicate *string `json:"predicate,omitempty"` + Predicate string `json:"predicate,omitempty"` // Storage parameters for the index - StorageParameters *string `json:"storage_parameters,omitempty"` + StorageParameters string `json:"storage_parameters,omitempty"` // Name of table on which to define the index Table string `json:"table"` // Indicates if the index is unique - Unique *bool `json:"unique,omitempty"` + Unique bool `json:"unique,omitempty"` } type OpCreateIndexMethod string diff --git a/schema.json b/schema.json index 729699df..4a35ee07 100644 --- a/schema.json +++ b/schema.json @@ -238,20 +238,24 @@ }, "predicate": { "description": "Conditional expression for defining a partial index", - "type": "string" + "type": "string", + "default": "" }, "method": { "description": "Index method to use for the index: btree, hash, gist, spgist, gin, brin", "type": "string", - "enum": ["btree", "hash", "gist", "spgist", "gin", "brin"] + "enum": ["btree", "hash", "gist", "spgist", "gin", "brin"], + "default": "btree" }, "storage_parameters": { "description": "Storage parameters for the index", - "type": "string" + "type": "string", + "default": "" }, "unique": { "description": "Indicates if the index is unique", - "type": "boolean" + "type": "boolean", + "default": false } }, "required": ["columns", "name", "table"],