Skip to content

Commit

Permalink
Merge b728145 into b1b2aa1
Browse files Browse the repository at this point in the history
  • Loading branch information
marctalbott committed Nov 5, 2020
2 parents b1b2aa1 + b728145 commit 0448e89
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@
<include file="changesets/20200901_descendant_permissions.xml" relativeToChangelogFile="true"/>
<include file="changesets/20201028_nested_roles.xml" relativeToChangelogFile="true"/>
<include file="changesets/20201029_resource_type_fields.xml" relativeToChangelogFile="true"/>
<include file="changesets/20201102_flattened_role_materialized_view.xml" relativeToChangelogFile="true"/>
</databaseChangeLog>
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<databaseChangeLog logicalFilePath="dummy"
xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
xmlns:ext="http://www.liquibase.org/xml/ns/dbchangelog-ext"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog-ext http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-ext.xsd http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.4.xsd">

<changeSet logicalFilePath="dummy" author="mtalbott" id="flattened_role_materialized_view">
<sql stripComments="true">
create materialized view sam_flattened_role as (
with recursive flattened_role(base_role_id, nested_role_id, descendants_only) as (
select resourceRole.id, resourceRole.id, false from sam_resource_role resourceRole
union
select flattened_role.base_role_id, nestedRole.nested_role_id, nestedRole.descendants_only from sam_nested_role nestedRole
join flattened_role on flattened_role.nested_role_id = nestedRole.base_role_id
) select * from flattened_role);
</sql>
</changeSet>
</databaseChangeLog>
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,9 @@ class PostgresAccessPolicyDAO(protected val dbRef: DbReference,
(values ${nestedRoles}) as insertValues (base_resource_type_id, base_role_name, nested_resource_type_id, nested_role_name, descendants_only)
join ${ResourceRoleTable as resourceRole} on insertValues.base_role_name = ${resourceRole.role} and insertValues.base_resource_type_id = ${resourceRole.resourceTypeId}
join ${ResourceRoleTable as nestedResourceRole} on insertValues.nested_role_name = ${nestedResourceRole.role} and insertValues.nested_resource_type_id = ${nestedResourceRole.resourceTypeId}"""
insertQuery.update().apply()
val result = insertQuery.update().apply()
samsql"""refresh materialized view sam_flattened_role""".update.apply()
result
} else {
0
}
Expand Down

0 comments on commit 0448e89

Please sign in to comment.