Skip to content

Commit

Permalink
feat(grant): add unique index for active grants (#91)
Browse files Browse the repository at this point in the history
* feat(grant): add unique index for active grants

* test(grant): cleanup grants table after each test in grant repository test
  • Loading branch information
rahmatrhd authored Oct 11, 2023
1 parent 993e2c5 commit 38643f8
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 38643f8

Please sign in to comment.