Database governance built for humans and agents — controlling changes and access across every major database.
Go cicddata-governancedata-maskingdata-securitydatabase-accessdatabase-governancedevopsdevsecopsflywaygitopsliquibasemongodbmysqloraclepostgresqlschema-migrationssecuritysql-clientsqlservertidb
Rename policy name field to type. It's more consistent with other storage naming schema type and payload.
spinningbot0818049e3984
diff --git a/api/policy.go b/api/policy.goindex 5f5de1b03d..5d399f4a87 100644--- a/api/policy.go+++ b/api/policy.go@@ -23,7 +23,7 @@ type Policy struct {Environment *Environment// Domain specific fields- Name string `jsonapi:"attr,name"`+ Type string `jsonapi:"attr,type"`Payload string `jsonapi:"attr,payload"`}@@ -35,7 +35,7 @@ type PolicyFind struct {EnvironmentId *int// Domain specific fields- Name *string `jsonapi:"attr,name"`+ Type *string `jsonapi:"attr,type"`}// PolicyUpsert is the message to upsert a policy.@@ -50,7 +50,7 @@ type PolicyUpsert struct {EnvironmentId int `jsonapi:"attr,environmentId"`// Domain specific fields- Name string `jsonapi:"attr,name"`+ Type string `jsonapi:"attr,type"`Payload string `jsonapi:"attr,payload"`}diff --git a/store/migration/10001__init_schema.sql b/store/migration/10001__init_schema.sqlindex a1cf540806..a35e403656 100644--- a/store/migration/10001__init_schema.sql+++ b/store/migration/10001__init_schema.sql@@ -167,6 +167,7 @@ END;-- Policy-- policy stores the policies for each environment.+-- Policies are associated with environments. Since we may have policies not associated with environment later, we name the table policy.CREATE TABLE policy (id INTEGER PRIMARY KEY AUTOINCREMENT,row_status TEXT NOT NULL CHECK (@@ -177,13 +178,13 @@ CREATE TABLE policy (updater_id INTEGER NOT NULL REFERENCES principal (id),updated_ts BIGINT NOT NULL DEFAULT (strftime('%s', 'now')),environment_id INTEGER NOT NULL REFERENCES environment (id),- name TEXT NOT NULL,+ type TEXT NOT NULL,payload TEXT NOT NULL);CREATE INDEX idx_policy_environment_id ON policy(environment_id);-CREATE UNIQUE INDEX idx_policy_environment_id_name ON policy(environment_id, name);+CREATE UNIQUE INDEX idx_policy_environment_id_type ON policy(environment_id, type);INSERT INTOsqlite_sequence (name, seq)diff --git a/store/policy.go b/store/policy.goindex 0f1b2a6b1f..6b19e047c4 100644--- a/store/policy.go+++ b/store/policy.go@@ -58,8 +58,8 @@ func (s *PolicyService) findPolicy(ctx context.Context, tx *Tx, find *api.Policyif v := find.EnvironmentId; v != nil {where, args = append(where, "environment_id = ?"), append(args, *v)}- if v := find.Name; v != nil {- where, args = append(where, "name = ?"), append(args, *v)+ if v := find.Type; v != nil {+ where, args = append(where, "type = ?"), append(args, *v)}rows, err := tx.QueryContext(ctx, `@@ -70,7 +70,7 @@ func (s *PolicyService) findPolicy(ctx context.Context, tx *Tx, find *api.Policyupdater_id,updated_ts,environment_id,- name,+ type,payloadFROM policyWHERE `+strings.Join(where, " AND "),@@ -92,7 +92,7 @@ func (s *PolicyService) findPolicy(ctx context.Context, tx *Tx, find *api.Policy&policy.UpdaterId,&policy.UpdatedTs,&policy.Environment,- &policy.Name,+ &policy.Type,&policy.Payload,); err != nil {return nil, FormatError(err)@@ -136,18 +136,18 @@ func (s *PolicyService) upsertPolicy(ctx context.Context, tx *Tx, upsert *api.Pocreator_id,updater_id,environment_id,- name,+ type,payload)VALUES (?, ?, ?, ?, ?)- ON CONFLICT(environment_id, name) DO UPDATE SET+ ON CONFLICT(environment_id, type) DO UPDATE SETpayload = excluded.payload- RETURNING id, creator_id, created_ts, updater_id, updated_ts, environment_id, name, payload+ RETURNING id, creator_id, created_ts, updater_id, updated_ts, environment_id, type, payload`,upsert.UpdaterId,upsert.UpdaterId,upsert.EnvironmentId,- upsert.Name,+ upsert.Type,upsert.Payload,)@@ -165,7 +165,7 @@ func (s *PolicyService) upsertPolicy(ctx context.Context, tx *Tx, upsert *api.Po&policy.UpdaterId,&policy.UpdatedTs,&policy.EnvironmentId,- &policy.Name,+ &policy.Type,&policy.Payload,); err != nil {return nil, FormatError(err)diff --git a/store/seed/test/10050__environment.sql b/store/seed/test/10050__environment.sqlindex d34ec55989..e661ebacb6 100644--- a/store/seed/test/10050__environment.sql+++ b/store/seed/test/10050__environment.sql@@ -94,43 +94,3 @@ VALUES4,'MANUAL_APPROVAL_NEVER');--INSERT INTO- policy (- id,- creator_id,- updater_id,- environment_id,- name,- payload- )-VALUES- (- 1001,- 101,- 101,- 5004,- 'approval_policy',- 'MANUAL_APPROVAL_NEVER'- );--INSERT INTO- policy (- id,- creator_id,- updater_id,- environment_id,- name,- payload- )-VALUES- (- 1001,- 101,- 101,- 5004,- 'approval_policy',- 'MANUAL_APPROVAL_ALWAYS'- )- ON CONFLICT(environment_id, name) DO UPDATE SET- payload = excluded.payload;diff --git a/store/seed/test/10051__policy.sql b/store/seed/test/10051__policy.sqlnew file mode 100644index 0000000000..fd52223daa--- /dev/null+++ b/store/seed/test/10051__policy.sql@@ -0,0 +1,39 @@+INSERT INTO+ policy (+ id,+ creator_id,+ updater_id,+ environment_id,+ type,+ payload+ )+VALUES+ (+ 5101,+ 101,+ 101,+ 5004,+ 'approval_policy',+ 'MANUAL_APPROVAL_NEVER'+ );++INSERT INTO+ policy (+ id,+ creator_id,+ updater_id,+ environment_id,+ type,+ payload+ )+VALUES+ (+ 5101,+ 101,+ 101,+ 5004,+ 'approval_policy',+ 'MANUAL_APPROVAL_ALWAYS'+ )+ ON CONFLICT(environment_id, type) DO UPDATE SET+ payload = excluded.payload;