diff --git a/rule/manager_sql.go b/rule/manager_sql.go index a4442381d1..cb65636b26 100644 --- a/rule/manager_sql.go +++ b/rule/manager_sql.go @@ -14,7 +14,8 @@ import ( ) type sqlRule struct { - ID string `db:"id"` + ID string `db:"surrogate_id"` + InternalID int64 `db:"id"` MatchesMethods string `db:"matches_methods"` MatchesURL string `db:"matches_url"` RequiredScopes string `db:"required_scopes"` @@ -76,9 +77,10 @@ var migrations = &migrate.MemoryMigrationSource{ { Id: "1", Up: []string{`CREATE TABLE IF NOT EXISTS oathkeeper_rule ( - id varchar(64) NOT NULL PRIMARY KEY, + id SERIAL PRIMARY KEY, + surrogate_id varchar(190) NOT NULL UNIQUE, matches_methods varchar(64) NOT NULL, - matches_url text NOT NULL, + matches_url text NOT NULL, required_scopes text NOT NULL, required_action text NOT NULL, required_resource text NOT NULL, @@ -95,7 +97,7 @@ var migrations = &migrate.MemoryMigrationSource{ } var sqlParams = []string{ - "id", + "surrogate_id", "matches_methods", "matches_url", "required_scopes", @@ -146,7 +148,7 @@ func (s *SQLManager) ListRules() ([]Rule, error) { func (s *SQLManager) GetRule(id string) (*Rule, error) { var d sqlRule - if err := s.db.Get(&d, s.db.Rebind("SELECT * FROM oathkeeper_rule WHERE id=?"), id); err == sql.ErrNoRows { + if err := s.db.Get(&d, s.db.Rebind("SELECT * FROM oathkeeper_rule WHERE surrogate_id=?"), id); err == sql.ErrNoRows { return nil, errors.WithStack(helper.ErrResourceNotFound) } else if err != nil { return nil, errors.WithStack(err) @@ -175,14 +177,14 @@ func (s *SQLManager) UpdateRule(rule *Rule) error { for _, param := range sqlParams { query = append(query, fmt.Sprintf("%s=:%s", param, param)) } - if _, err := s.db.NamedExec(fmt.Sprintf(`UPDATE oathkeeper_rule SET %s WHERE id=:id`, strings.Join(query, ", ")), sr); err != nil { + if _, err := s.db.NamedExec(fmt.Sprintf(`UPDATE oathkeeper_rule SET %s WHERE surrogate_id=:surrogate_id`, strings.Join(query, ", ")), sr); err != nil { return errors.WithStack(err) } return nil } func (s *SQLManager) DeleteRule(id string) error { - if _, err := s.db.Exec(s.db.Rebind(`DELETE FROM oathkeeper_rule WHERE id=?`), id); err != nil { + if _, err := s.db.Exec(s.db.Rebind(`DELETE FROM oathkeeper_rule WHERE surrogate_id=?`), id); err != nil { return errors.WithStack(err) } return nil