Skip to content

Commit bcbbde8

Browse files
Chief-Rishabravisuhag
authored andcommitted
feat(grant): add unique index for active grants
1 parent 99e254e commit bcbbde8

File tree

3 files changed

+15
-0
lines changed

3 files changed

+15
-0
lines changed

internal/store/postgres/grant_repository_test.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,17 @@ func (s *GrantRepositoryTestSuite) SetupSuite() {
103103
s.Require().NoError(err)
104104
}
105105

106+
func (s *GrantRepositoryTestSuite) AfterTest(suiteName, testName string) {
107+
// clean grants table
108+
db, err := s.store.DB().DB()
109+
if err != nil {
110+
s.T().Fatal(err)
111+
}
112+
if _, err := db.Exec("DELETE FROM grants"); err != nil {
113+
s.T().Fatal(err)
114+
}
115+
}
116+
106117
func (s *GrantRepositoryTestSuite) TearDownSuite() {
107118
// Clean tests
108119
db, err := s.store.DB().DB()
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
DROP INDEX IF EXISTS "unique_active_grants_index";
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
CREATE UNIQUE INDEX IF NOT EXISTS "unique_active_grants_index" ON "grants" ("account_id", "account_type", "permissions")
2+
WHERE
3+
"status" = 'active';

0 commit comments

Comments
 (0)