Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CORE-17362: Change rbac-creation schema correctly #1266

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.5.xsd">
<include file="net/corda/db/schema/rbac/migration/rbac-creation-v1.0.xml"/>
<include file="net/corda/db/schema/rbac/migration/rbac-creation-v5.1.xml"/>
</databaseChangeLog>
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@
<column name="update_ts" type="TIMESTAMP">
<constraints nullable="false"/>
</column>
<column name="actor_user" type="VARCHAR(255)">
<column name="actor_user" type="VARCHAR(36)">
<constraints nullable="false"/>
</column>
<column name="change_type" type="VARCHAR(255)">
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,300 @@
<?xml version="1.1" encoding="UTF-8" standalone="no"?>
<databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-4.18.xsd">

<changeSet author="R3.Corda" id="rbac-creation-v1.0">
<createTable tableName="rbac_user">
vkolomeyko marked this conversation as resolved.
Show resolved Hide resolved
<column name="id" type="VARCHAR(36)">
<constraints nullable="false"/>
</column>
<column name="update_ts" type="TIMESTAMP">
<constraints nullable="false"/>
</column>
<column name="version" type="INT">
<constraints nullable="false"/>
</column>
<column name="full_name" type="VARCHAR(255)">
<constraints nullable="false"/>
</column>
<column name="login_name" type="VARCHAR(255)">
<constraints nullable="false"/>
</column>
<column name="enabled" type="BOOLEAN">
<constraints nullable="false"/>
</column>
<column name="salt_value" type="VARCHAR(255)">
<constraints nullable="true"/>
</column>
<column name="hashed_password" type="VARCHAR(255)">
<constraints nullable="true"/>
</column>
<column name="password_expiry" type="TIMESTAMP">
<constraints nullable="true"/>
</column>
<column name="parent_group" type="VARCHAR(36)">
<constraints nullable="true"/>
</column>
</createTable>
<addPrimaryKey tableName="rbac_user" columnNames="id" constraintName="rbac_user_pkey"/>
<addUniqueConstraint tableName="rbac_user" columnNames="login_name" constraintName="rbac_user_uc1"/>

<createTable tableName="rbac_user_props"
remarks="Holds properties for an individual user">
<column name="id" type="VARCHAR(36)">
<constraints nullable="false"/>
</column>
<column name="update_ts" type="TIMESTAMP">
<constraints nullable="false"/>
</column>
<column name="version" type="INT">
<constraints nullable="false"/>
</column>
<column name="user_ref" type="VARCHAR(36)">
<constraints nullable="false"/>
</column>
<column name="key" type="VARCHAR(255)">
<constraints nullable="false"/>
</column>
<column name="value" type="VARCHAR(255)">
<constraints nullable="false"/>
</column>
</createTable>
<addPrimaryKey tableName="rbac_user_props" columnNames="id" constraintName="rbac_user_props_pkey"/>
<addUniqueConstraint tableName="rbac_user_props" columnNames="user_ref, key" constraintName="rbac_user_props_uc1"/>

<addForeignKeyConstraint baseTableName="rbac_user_props" baseColumnNames="user_ref"
referencedTableName="rbac_user" referencedColumnNames="id"
constraintName="FK__rbac_user_props__user_ref"
onDelete="CASCADE"/>

<createTable tableName="rbac_group">
<column name="id" type="VARCHAR(36)">
<constraints nullable="false"/>
</column>
<column name="update_ts" type="TIMESTAMP">
<constraints nullable="false"/>
</column>
<column name="version" type="INT">
<constraints nullable="false"/>
</column>
<column name="name" type="VARCHAR(255)">
<constraints nullable="false"/>
</column>
<column name="parent_group" type="VARCHAR(36)">
<constraints nullable="true"/>
</column>
</createTable>
<addPrimaryKey tableName="rbac_group" columnNames="id" constraintName="rbac_group_pkey"/>
<addUniqueConstraint tableName="rbac_group" columnNames="name, parent_group" constraintName="rbac_group_uc1"/>

<addForeignKeyConstraint baseTableName="rbac_group" baseColumnNames="parent_group"
referencedTableName="rbac_group" referencedColumnNames="id"
constraintName="FK__rbac_gr__parent_gr"
onDelete="SET NULL"/>

<addForeignKeyConstraint baseTableName="rbac_user" baseColumnNames="parent_group"
referencedTableName="rbac_group" referencedColumnNames="id"
constraintName="FK__rbac_user__parent_group"
onDelete="SET NULL"/>

<createTable tableName="rbac_group_props" remarks="Holds properties of the group">
<column name="id" type="VARCHAR(36)">
<constraints nullable="false"/>
</column>
<column name="update_ts" type="TIMESTAMP">
<constraints nullable="false"/>
</column>
<column name="version" type="INT">
<constraints nullable="false"/>
</column>
<column name="group_ref" type="VARCHAR(36)">
<constraints nullable="false"/>
</column>
<column name="key" type="VARCHAR(255)">
<constraints nullable="false"/>
</column>
<column name="value" type="VARCHAR(255)">
<constraints nullable="false"/>
</column>
</createTable>
<addPrimaryKey tableName="rbac_group_props" columnNames="id" constraintName="rbac_group_props_pkey"/>
<addUniqueConstraint tableName="rbac_group_props" columnNames="group_ref, key"
constraintName="rbac_group_props_uc1"/>

<addForeignKeyConstraint baseTableName="rbac_group_props" baseColumnNames="group_ref"
referencedTableName="rbac_group" referencedColumnNames="id"
constraintName="FK__rbac_group_props__group_ref"
onDelete="CASCADE"/>

<createTable tableName="rbac_change_audit">
<column name="id" type="VARCHAR(36)">
<constraints nullable="false"/>
</column>
<column name="update_ts" type="TIMESTAMP">
<constraints nullable="false"/>
</column>
<column name="actor_user" type="VARCHAR(255)">
<constraints nullable="false"/>
</column>
<column name="change_type" type="VARCHAR(255)">
<constraints nullable="false"/>
</column>
<column name="details" type="VARCHAR(2048)">
<constraints nullable="false"/>
</column>
</createTable>
<addPrimaryKey tableName="rbac_change_audit" columnNames="id" constraintName="rbac_change_audit_pkey"/>

<createTable tableName="rbac_role">
<column name="id" type="VARCHAR(36)">
<constraints nullable="false"/>
</column>
<column name="update_ts" type="TIMESTAMP">
<constraints nullable="false"/>
</column>
<column name="version" type="INT">
<constraints nullable="false"/>
</column>
<column name="name" type="VARCHAR(255)">
<constraints nullable="false"/>
</column>
<column name="group_vis" type="VARCHAR(36)"
remarks="Indicates which group which has visibility on a given role">
<constraints nullable="true"/>
</column>
</createTable>
<addPrimaryKey tableName="rbac_role" columnNames="id" constraintName="rbac_role_pkey"/>
<addUniqueConstraint tableName="rbac_role" columnNames="name, group_vis" constraintName="rbac_role_uc1"/>
<createIndex tableName="rbac_role" indexName="rbac_role__group_vis__idx">
<column name="group_vis"/>
</createIndex>

<addForeignKeyConstraint baseTableName="rbac_role" baseColumnNames="group_vis"
referencedTableName="rbac_group" referencedColumnNames="id"
constraintName="FK__rbac_role__group_vis"
onDelete="CASCADE"/>

<createTable tableName="rbac_role_user_rel"
remarks="Represents 1-n relationship between user and roles">
<column name="id" type="VARCHAR(36)">
<constraints nullable="false"/>
</column>
<column name="update_ts" type="TIMESTAMP">
<constraints nullable="false"/>
</column>
<column name="user_id" type="VARCHAR(36)">
<constraints nullable="false"/>
</column>
<column name="role_id" type="VARCHAR(36)">
<constraints nullable="false"/>
</column>
</createTable>
<addPrimaryKey tableName="rbac_role_user_rel" columnNames="id" constraintName="rbac_role_user_rel_pkey"/>
<addUniqueConstraint tableName="rbac_role_user_rel" columnNames="user_id, role_id"
constraintName="rbac_role_user_rel_uc1"/>

<addForeignKeyConstraint baseTableName="rbac_role_user_rel" baseColumnNames="user_id"
referencedTableName="rbac_user" referencedColumnNames="id"
constraintName="FK__rbac_role_user_rel__user_id"
onDelete="CASCADE"/>

<addForeignKeyConstraint baseTableName="rbac_role_user_rel" baseColumnNames="role_id"
referencedTableName="rbac_role" referencedColumnNames="id"
constraintName="FK__rbac_role_user_rel__role_id"
onDelete="CASCADE"/>

<createTable tableName="rbac_role_group_rel"
remarks="Represents 1-n relationship between group and roles">
<column name="id" type="VARCHAR(36)">
<constraints nullable="false"/>
</column>
<column name="update_ts" type="TIMESTAMP">
<constraints nullable="false"/>
</column>
<column name="group_id" type="VARCHAR(36)">
<constraints nullable="false"/>
</column>
<column name="role_id" type="VARCHAR(36)">
<constraints nullable="false"/>
</column>
</createTable>
<addPrimaryKey tableName="rbac_role_group_rel" columnNames="id" constraintName="rbac_role_group_rel_pkey"/>
<addUniqueConstraint tableName="rbac_role_group_rel" columnNames="group_id, role_id"
constraintName="rbac_role_group_rel_uc1"/>

<addForeignKeyConstraint baseTableName="rbac_role_group_rel" baseColumnNames="group_id"
referencedTableName="rbac_group" referencedColumnNames="id"
constraintName="FK__rbac_role_group_rel__group_id"
onDelete="CASCADE"/>

<addForeignKeyConstraint baseTableName="rbac_role_group_rel" baseColumnNames="role_id"
referencedTableName="rbac_role" referencedColumnNames="id"
constraintName="FK__rbac_role_group_rel__role_id"
onDelete="CASCADE"/>

<createTable tableName="rbac_perm">
<column name="id" type="VARCHAR(36)">
<constraints nullable="false"/>
</column>
<column name="update_ts" type="TIMESTAMP">
<constraints nullable="false"/>
</column>
<column name="version" type="INT">
<constraints nullable="false"/>
</column>
<column name="group_vis" type="VARCHAR(36)"
remarks="Indicates which group which has visibility on a given permission">
<constraints nullable="true"/>
</column>
<column name="virtual_node" type="VARCHAR(255)">
<constraints nullable="true"/>
</column>
<column name="perm_type" type="VARCHAR(255)">
<constraints nullable="false"/>
</column>
<column name="perm_string" type="VARCHAR(1024)">
<constraints nullable="false"/>
</column>
</createTable>
<addPrimaryKey tableName="rbac_perm" columnNames="id" constraintName="rbac_perm_pkey"/>
<createIndex tableName="rbac_perm" indexName="rbac_perm__group_vis__idx">
<column name="group_vis"/>
</createIndex>

<addForeignKeyConstraint baseTableName="rbac_perm" baseColumnNames="group_vis"
referencedTableName="rbac_group" referencedColumnNames="id"
constraintName="FK__rbac_perm__group_vis"
onDelete="CASCADE"/>

<createTable tableName="rbac_role_perm_rel"
remarks="Represents n-n relationship between roles and permissions">
<column name="id" type="VARCHAR(36)">
<constraints nullable="false"/>
</column>
<column name="update_ts" type="TIMESTAMP">
<constraints nullable="false"/>
</column>
<column name="role_id" type="VARCHAR(36)">
<constraints nullable="false"/>
</column>
<column name="perm_id" type="VARCHAR(36)">
<constraints nullable="false"/>
</column>
</createTable>
<addPrimaryKey tableName="rbac_role_perm_rel" columnNames="id" constraintName="rbac_role_perm_rel_pkey"/>
<addUniqueConstraint tableName="rbac_role_perm_rel" columnNames="role_id, perm_id"
constraintName="rbac_role_perm_rel_uc1"/>

<addForeignKeyConstraint baseTableName="rbac_role_perm_rel" baseColumnNames="role_id"
referencedTableName="rbac_role" referencedColumnNames="id"
constraintName="FK__rbac_role_perm_rel__role_id"
onDelete="CASCADE"/>

<addForeignKeyConstraint baseTableName="rbac_role_perm_rel" baseColumnNames="perm_id"
referencedTableName="rbac_perm" referencedColumnNames="id"
constraintName="FK__rbac_role_perm_rel__perm_id"
onDelete="CASCADE"/>

</changeSet>
</databaseChangeLog>