historicization for UserRoleAssinment
This commit is contained in:
		@@ -0,0 +1,15 @@
 | 
				
			|||||||
 | 
					<?xml version="1.0" encoding="utf-8"?>
 | 
				
			||||||
 | 
					<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-3.5.xsd">
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    <!-- the natural key used by the historical view must be unique -->
 | 
				
			||||||
 | 
					    <changeSet id="201905061856-1" author="mhoennig">
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        <!-- must match the GROUP BY clause in user_role_assignment_history_view -->
 | 
				
			||||||
 | 
					        <addUniqueConstraint constraintName="ux_user_role_assignment" tableName="user_role_assignment"
 | 
				
			||||||
 | 
					                             columnNames="entity_type_id, entity_object_id, assigned_role, user_id"/>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    </changeSet>
 | 
				
			||||||
 | 
					</databaseChangeLog>
 | 
				
			||||||
@@ -0,0 +1,87 @@
 | 
				
			|||||||
 | 
					<?xml version="1.0" encoding="utf-8"?>
 | 
				
			||||||
 | 
					<databaseChangeLog
 | 
				
			||||||
 | 
					    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 http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.5.xsd
 | 
				
			||||||
 | 
					                        http://www.liquibase.org/xml/ns/dbchangelog-ext http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-ext.xsd">
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    <!-- Table for historical user_role_assignment data. -->
 | 
				
			||||||
 | 
					    <changeSet id="20190506150000-1" author="mhierweck,mhoennig" dbms="postgresql">
 | 
				
			||||||
 | 
					        <createTable tableName="user_role_assignment_history">
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            <!-- history-related columns -->
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            <column name="history_id" type="bigint" autoIncrement="true">
 | 
				
			||||||
 | 
					                <constraints primaryKey="true" unique="true" nullable="false"/>
 | 
				
			||||||
 | 
					            </column>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            <column name="history_transaction" type="bigint">
 | 
				
			||||||
 | 
					                <constraints nullable="false" />
 | 
				
			||||||
 | 
					            </column>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            <column name="history_tombstone" type="bool">
 | 
				
			||||||
 | 
					                <constraints nullable="false" />
 | 
				
			||||||
 | 
					            </column>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            <!-- id-column like in base table, but no primary key nor unique -->
 | 
				
			||||||
 | 
					            <column name="id" type="bigint">
 | 
				
			||||||
 | 
					                <constraints primaryKey="true" nullable="false"/>
 | 
				
			||||||
 | 
					            </column>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            <!-- all following columns like in base table, dropping unique constraints -->
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            <column name="entity_type_id" type="varchar(255)">
 | 
				
			||||||
 | 
					                <constraints nullable="true" />
 | 
				
			||||||
 | 
					            </column>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            <column name="entity_object_id" type="bigint">
 | 
				
			||||||
 | 
					                <constraints nullable="true" />
 | 
				
			||||||
 | 
					            </column>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            <column name="assigned_role" type="varchar(255)">
 | 
				
			||||||
 | 
					                <constraints nullable="false" />
 | 
				
			||||||
 | 
					            </column>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            <column name="user_id" type="bigint">
 | 
				
			||||||
 | 
					                <constraints nullable="true" />
 | 
				
			||||||
 | 
					            </column>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        </createTable>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    </changeSet>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    <changeSet id="20190506150000-2" author="mhierweck,mhoennig" dbms="postgresql">
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        <addForeignKeyConstraint baseColumnNames="history_transaction"
 | 
				
			||||||
 | 
					                                 baseTableName="user_role_assignment_history"
 | 
				
			||||||
 | 
					                                 constraintName="fk_user_role_assignment_history_transaction"
 | 
				
			||||||
 | 
					                                 referencedColumnNames="history_transaction"
 | 
				
			||||||
 | 
					                                 referencedTableName="history"/>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    </changeSet>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    <changeSet id="20190506150000-3" author="mhierweck,mhoennig" dbms="postgresql">
 | 
				
			||||||
 | 
					        <createProcedure>
 | 
				
			||||||
 | 
					            CREATE TRIGGER user_role_assignment_historicize
 | 
				
			||||||
 | 
					            AFTER INSERT OR DELETE OR UPDATE ON user_role_assignment
 | 
				
			||||||
 | 
					            FOR EACH ROW EXECUTE PROCEDURE historicize();
 | 
				
			||||||
 | 
					        </createProcedure>
 | 
				
			||||||
 | 
					        <rollback>
 | 
				
			||||||
 | 
					            DROP TRIGGER user_role_assignment_historicize
 | 
				
			||||||
 | 
					        </rollback>
 | 
				
			||||||
 | 
					    </changeSet>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    <changeSet id="20190506150000-4" author="mhierweck,mhoennig" dbms="postgresql">
 | 
				
			||||||
 | 
					        <createView viewName="user_role_assignment_history_view" replaceIfExists="true">
 | 
				
			||||||
 | 
					            SELECT *
 | 
				
			||||||
 | 
					              FROM user_role_assignment_history
 | 
				
			||||||
 | 
					             WHERE history_id IN (
 | 
				
			||||||
 | 
					                SELECT max(history_id) AS history_id
 | 
				
			||||||
 | 
					                  FROM user_role_assignment_history
 | 
				
			||||||
 | 
					                 WHERE history_transaction <= current_setting('history.transaction')::bigint
 | 
				
			||||||
 | 
					                 GROUP BY entity_type_id, entity_object_id, assigned_role, user_id) -- must have a unique constraint
 | 
				
			||||||
 | 
					        </createView>
 | 
				
			||||||
 | 
					    </changeSet>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					</databaseChangeLog>
 | 
				
			||||||
@@ -23,10 +23,12 @@
 | 
				
			|||||||
    <!-- jhipster-needle-liquibase-add-constraints-changelog - JHipster will add liquibase constraints changelogs here -->
 | 
					    <!-- jhipster-needle-liquibase-add-constraints-changelog - JHipster will add liquibase constraints changelogs here -->
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    <!-- additional changesets, not generated by JHipster -->
 | 
					    <!-- additional changesets, not generated by JHipster -->
 | 
				
			||||||
 | 
					    <include file="config/liquibase/changelog/constraints_UserRoleAssignment.xml" relativeToChangelogFile="false"/>
 | 
				
			||||||
    <include file="config/liquibase/changelog/constraints_Membership.xml" relativeToChangelogFile="false"/>
 | 
					    <include file="config/liquibase/changelog/constraints_Membership.xml" relativeToChangelogFile="false"/>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    <!-- historicization -->
 | 
					    <!-- historicization -->
 | 
				
			||||||
    <include file="config/liquibase/historicization/historicization.xml" relativeToChangelogFile="false"/>
 | 
					    <include file="config/liquibase/historicization/historicization.xml" relativeToChangelogFile="false"/>
 | 
				
			||||||
 | 
					    <include file="config/liquibase/historicization/historicization_UserRoleAssignment.xml" relativeToChangelogFile="false"/>
 | 
				
			||||||
    <include file="config/liquibase/historicization/historicization_Customer.xml" relativeToChangelogFile="false"/>
 | 
					    <include file="config/liquibase/historicization/historicization_Customer.xml" relativeToChangelogFile="false"/>
 | 
				
			||||||
    <include file="config/liquibase/historicization/historicization_Membership.xml" relativeToChangelogFile="false"/>
 | 
					    <include file="config/liquibase/historicization/historicization_Membership.xml" relativeToChangelogFile="false"/>
 | 
				
			||||||
    <include file="config/liquibase/historicization/historicization_SepaMandate.xml" relativeToChangelogFile="false"/>
 | 
					    <include file="config/liquibase/historicization/historicization_SepaMandate.xml" relativeToChangelogFile="false"/>
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user