Skip to content

Database governance built for humans and agents — controlling changes and access across every major database.

chore: migrate project member to policy table (#12109)

p0nyf6f07071cae3
diff --git a/backend/migrator/migration/prod/2.18/0006##policy_project_iam.sql b/backend/migrator/migration/prod/2.18/0006##policy_project_iam.sql
new file mode 100644
index 0000000000..cbadb1e4a7
--- /dev/null
+++ b/backend/migrator/migration/prod/2.18/0006##policy_project_iam.sql
@@ -0,0 +1,40 @@
+INSERT INTO policy (
+ creator_id,
+ updater_id,
+ type,
+ payload,
+ resource_type,
+ resource_id,
+ inherit_from_parent
+)
+SELECT
+ 1,
+ 1,
+ 'bb.policy.project-iam',
+ jsonb_build_object('bindings', jsonb_agg(t2.binding)),
+ 'PROJECT',
+ t2.project_id,
+ FALSE
+FROM
+(
+ SELECT
+ project_id,
+ 'roles/'||role AS role,
+ condition,
+ array_agg('users/'||principal_id) AS members
+ FROM project_member
+ GROUP BY project_id, role, condition
+ ORDER BY project_id
+) t1
+LEFT JOIN LATERAL (
+ SELECT
+ t1.project_id,
+ jsonb_build_object(
+ 'role', t1.role,
+ 'members', t1.members,
+ 'condition', t1.condition
+ ) AS binding
+ GROUP BY t1.project_id
+) t2 ON TRUE
+GROUP BY t2.project_id
+ORDER BY t2.project_id;
diff --git a/backend/migrator/migrator_test.go b/backend/migrator/migrator_test.go
index 7f3b0a6281..18a0e93eea 100644
--- a/backend/migrator/migrator_test.go
+++ b/backend/migrator/migrator_test.go
@@ -230,5 +230,5 @@ func TestMigrationCompatibility(t *testing.T) {
func TestGetCutoffVersion(t *testing.T) {
releaseVersion, err := getProdCutoffVersion()
require.NoError(t, err)
- require.Equal(t, semver.MustParse("2.18.5"), releaseVersion)
+ require.Equal(t, semver.MustParse("2.18.6"), releaseVersion)
}