Skip to content

Commit

Permalink
ENG-11253: create partial unique index on template
Browse files Browse the repository at this point in the history
  • Loading branch information
ryli17 committed Dec 10, 2020
1 parent 9c52cca commit 419d7ff
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 7 deletions.
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

0 comments on commit 419d7ff

Please sign in to comment.