diff --git a/internal/store/postgres/grant_repository_test.go b/internal/store/postgres/grant_repository_test.go index 0147c4771..684876d1d 100644 --- a/internal/store/postgres/grant_repository_test.go +++ b/internal/store/postgres/grant_repository_test.go @@ -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() diff --git a/internal/store/postgres/migrations/000019_create_grant_unique_index.down.sql b/internal/store/postgres/migrations/000019_create_grant_unique_index.down.sql new file mode 100644 index 000000000..8de222b64 --- /dev/null +++ b/internal/store/postgres/migrations/000019_create_grant_unique_index.down.sql @@ -0,0 +1 @@ +DROP INDEX IF EXISTS "unique_active_grants_index"; \ No newline at end of file diff --git a/internal/store/postgres/migrations/000019_create_grant_unique_index.up.sql b/internal/store/postgres/migrations/000019_create_grant_unique_index.up.sql new file mode 100644 index 000000000..398112dbb --- /dev/null +++ b/internal/store/postgres/migrations/000019_create_grant_unique_index.up.sql @@ -0,0 +1,3 @@ +CREATE UNIQUE INDEX IF NOT EXISTS "unique_active_grants_index" ON "grants" ("account_id", "account_type", "permissions") +WHERE + "status" = 'active'; \ No newline at end of file