Skip to content

Commit

Permalink
feat(grant): add unique index for active grants
Browse files Browse the repository at this point in the history
  • Loading branch information
Chief-Rishab authored and ravisuhag committed Oct 20, 2023
1 parent 99e254e commit bcbbde8
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 0 deletions.
11 changes: 11 additions & 0 deletions internal/store/postgres/grant_repository_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,17 @@ func (s *GrantRepositoryTestSuite) SetupSuite() {
s.Require().NoError(err)
}

func (s *GrantRepositoryTestSuite) AfterTest(suiteName, testName string) {
// clean grants table
db, err := s.store.DB().DB()
if err != nil {
s.T().Fatal(err)
}
if _, err := db.Exec("DELETE FROM grants"); err != nil {
s.T().Fatal(err)
}
}

func (s *GrantRepositoryTestSuite) TearDownSuite() {
// Clean tests
db, err := s.store.DB().DB()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
DROP INDEX IF EXISTS "unique_active_grants_index";
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
CREATE UNIQUE INDEX IF NOT EXISTS "unique_active_grants_index" ON "grants" ("account_id", "account_type", "permissions")
WHERE
"status" = 'active';

0 comments on commit bcbbde8

Please sign in to comment.