Skip to content
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

ENG-11253: create partial unique index on template #378

Merged
merged 1 commit into from
Dec 11, 2020
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package migration

import migrate "github.com/rubenv/sql-migrate"

func Get202012091055() *migrate.Migration {
return &migrate.Migration{
Id: "202012091055-add-partial-unique-constraint-on-template",
Up: []string{`
CREATE UNIQUE INDEX uidx_template_name ON template (name) WHERE deleted_at IS NULL;
`},
}
}
1 change: 1 addition & 0 deletions db/migration/migration.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ func GetMigrations() *migrate.MemoryMigrationSource {
Get202010071530(),
Get202010221010(),
Get202012041103(),
Get202012091055(),
},
}
}
7 changes: 0 additions & 7 deletions db/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,6 @@ func (d TinkDB) CreateTemplate(ctx context.Context, name string, data string, id
return err
}

fields := map[string]string{
"name": name,
}
_, _, _, err = d.GetTemplate(ctx, fields, false)
if err != sql.ErrNoRows {
return errors.New("Template with name '" + name + "' already exist")
}
tx, err := d.instance.BeginTx(ctx, &sql.TxOptions{Isolation: sql.LevelSerializable})
if err != nil {
return errors.Wrap(err, "BEGIN transaction")
Expand Down