com.foreach.across.modules.user.installers.UserSchemaInstaller.xml Maven / Gradle / Ivy
<?xml version="1.0" encoding="UTF-8"?> <!-- ~ Copyright 2014 the original author or authors ~ ~ Licensed under the Apache License, Version 2.0 (the "License"); ~ you may not use this file except in compliance with the License. ~ You may obtain a copy of the License at ~ ~ http://www.apache.org/licenses/LICENSE-2.0 ~ ~ Unless required by applicable law or agreed to in writing, software ~ distributed under the License is distributed on an "AS IS" BASIS, ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. ~ See the License for the specific language governing permissions and ~ limitations under the License. --> <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.1.xsd"> <!-- Default table names --> <property name="table.permission" value="um_permission"/> <property name="table.permission_group" value="um_permission_group"/> <property name="table.role" value="um_role"/> <property name="table.role_permission" value="um_role_permission"/> <property name="table.user" value="um_user"/> <property name="table.user_directory" value="um_user_directory"/> <property name="table.user_properties" value="um_user_properties"/> <property name="table.principal" value="um_principal"/> <property name="table.principal_role" value="um_principal_role"/> <property name="table.group" value="um_group"/> <property name="table.principal_group" value="um_principal_group"/> <property name="table.machine" value="um_machine"/> <changeSet id="201406141719" author="arne" runAlways="true" dbms="oracle"> <sql> ALTER session SET nls_length_semantics=CHAR; </sql> </changeSet> <changeSet id="201406141557C" author="arne"> <preConditions onFail="MARK_RAN"> <not> <tableExists tableName="${table.permission_group}"/> </not> </preConditions> <comment>Creates permission group table</comment> <createTable tableName="${table.permission_group}"> <column name="id" type="java.sql.Types.BIGINT"> <constraints nullable="false" primaryKey="true" primaryKeyName="pk_um_perm_grp"/> </column> <column name="name" type="java.sql.Types.VARCHAR(255)"/> <column name="title" type="java.sql.Types.NVARCHAR(255)"/> <column name="description" type="java.sql.Types.NVARCHAR(2000)"/> </createTable> </changeSet> <changeSet id="201407310854" author="arne" dbms="mysql"> <comment>Set character set for mysql</comment> <sql> ALTER TABLE ${table.permission_group} MODIFY name VARCHAR(255) CHARACTER SET utf8 COLLATE utf8_unicode_ci </sql> </changeSet> <changeSet id="201407310855" author="arne"> <preConditions onFail="MARK_RAN"> <not> <indexExists tableName="${table.permission_group}" columnNames="name"/> </not> </preConditions> <comment>Create name index on permission group table</comment> <createIndex tableName="${table.permission_group}" indexName="ix_um_perm_grp_name" unique="true"> <column name="name"/> </createIndex> </changeSet> <changeSet id="201406141558C" author="arne"> <preConditions onFail="MARK_RAN"> <not> <tableExists tableName="${table.permission}"/> </not> </preConditions> <comment>Creates permission table</comment> <createTable tableName="${table.permission}"> <column name="id" type="java.sql.Types.BIGINT"> <constraints nullable="false" primaryKey="true" primaryKeyName="pk_um_perm"/> </column> <column name="name" type="java.sql.Types.VARCHAR(255)"/> <column name="description" type="java.sql.Types.NVARCHAR(2000)"/> <column name="permission_group_id" type="java.sql.Types.BIGINT"> <constraints nullable="false" referencedTableName="${table.permission_group}" referencedColumnNames="id" foreignKeyName="fk_um_p_pg"/> </column> </createTable> </changeSet> <changeSet id="201407310856" author="arne" dbms="mysql"> <comment>Set character set on permission name for mysql</comment> <sql> ALTER TABLE ${table.permission} MODIFY name VARCHAR(255) CHARACTER SET utf8 COLLATE utf8_unicode_ci </sql> </changeSet> <changeSet id="201407310857" author="arne"> <preConditions onFail="MARK_RAN"> <not> <indexExists tableName="${table.permission}" columnNames="name"/> </not> </preConditions> <comment>Create name index on permission table</comment> <createIndex tableName="${table.permission}" indexName="ix_um_perm_name" unique="true"> <column name="name"/> </createIndex> </changeSet> <changeSet id="201406141559C" author="arne"> <preConditions onFail="MARK_RAN"> <not> <tableExists tableName="${table.role}"/> </not> </preConditions> <comment>Creates role and role_permission table</comment> <createTable tableName="${table.role}"> <column name="id" type="java.sql.Types.BIGINT"> <constraints nullable="false" primaryKey="true" primaryKeyName="pk_um_role"/> </column> <column name="name" type="java.sql.Types.VARCHAR(255)"/> <column name="description" type="java.sql.Types.NVARCHAR(2000)"/> </createTable> <createTable tableName="${table.role_permission}"> <column name="role_id" type="java.sql.Types.BIGINT"> <constraints nullable="false" primaryKey="true" primaryKeyName="pk_um_role_perm"/> </column> <column name="permission_id" type="java.sql.Types.BIGINT"> <constraints nullable="false" primaryKey="true" primaryKeyName="pk_um_role_perm"/> </column> </createTable> <addForeignKeyConstraint baseTableName="${table.role_permission}" baseColumnNames="role_id" constraintName="fk_um_rp_role_id" referencedTableName="${table.role}" referencedColumnNames="id"/> <addForeignKeyConstraint baseTableName="${table.role_permission}" baseColumnNames="permission_id" constraintName="fk_um_rp_permission_id" referencedTableName="${table.permission}" referencedColumnNames="id"/> </changeSet> <changeSet id="201407310858" author="arne" dbms="mysql"> <comment>Set character set on role name for mysql</comment> <sql> ALTER TABLE ${table.role} MODIFY name VARCHAR(255) CHARACTER SET utf8 COLLATE utf8_unicode_ci </sql> </changeSet> <changeSet id="201407310859" author="arne"> <preConditions onFail="MARK_RAN"> <not> <indexExists tableName="${table.role}" columnNames="name"/> </not> </preConditions> <comment>Create name index on role table</comment> <createIndex tableName="${table.role}" indexName="ix_um_role_name" unique="true"> <column name="name"/> </createIndex> </changeSet> <changeSet id="201408221210" author="arne"> <preConditions onFail="MARK_RAN"> <not> <tableExists tableName="${table.principal}"/> </not> </preConditions> <comment>Create principal table</comment> <createTable tableName="${table.principal}"> <column name="id" type="java.sql.Types.BIGINT"> <constraints nullable="false" primaryKey="true" primaryKeyName="pk_um_principal"/> </column> <column name="principal_type" type="java.sql.Types.VARCHAR(100)"> <constraints nullable="false"/> </column> </createTable> </changeSet> <changeSet id="201408221214" author="arne"> <preConditions onFail="MARK_RAN"> <tableExists tableName="${table.user}"/> </preConditions> <comment>Migrating old user records</comment> <sql> INSERT INTO ${table.principal} SELECT id, 'user' FROM ${table.user} </sql> <addForeignKeyConstraint baseTableName="${table.user}" baseColumnNames="id" constraintName="fk_um_uid_pid" referencedTableName="${table.principal}" referencedColumnNames="id"/> </changeSet> <changeSet id="201408221216" author="arne"> <preConditions onFail="MARK_RAN"> <tableExists tableName="${table.user}"/> </preConditions> <comment>Migrating old user records</comment> <sql> UPDATE across_sequences SET seq_name = 'seq_um_principal_id' WHERE seq_name = 'seq_um_user_id' </sql> </changeSet> <changeSet id="201406141600CD" author="arne"> <preConditions onFail="MARK_RAN"> <not> <tableExists tableName="${table.user}"/> </not> </preConditions> <comment>Create user table</comment> <createTable tableName="${table.user}"> <column name="id" type="java.sql.Types.BIGINT"> <constraints nullable="false" primaryKey="true" primaryKeyName="pk_um_user"/> </column> <column name="username" type="java.sql.Types.VARCHAR(255)"/> <column name="email" type="java.sql.Types.VARCHAR(255)"/> <column name="password" type="java.sql.Types.NVARCHAR(255)"/> </createTable> <addNotNullConstraint tableName="${table.user}" columnName="username" columnDataType="java.sql.Types.VARCHAR(255)"/> <addForeignKeyConstraint baseTableName="${table.user}" baseColumnNames="id" constraintName="fk_um_uid_pid" referencedTableName="${table.principal}" referencedColumnNames="id"/> </changeSet> <changeSet id="201407310860" author="arne" dbms="mysql"> <comment>Set character set on username and email for mysql</comment> <sql> ALTER TABLE ${table.user} MODIFY username VARCHAR(255) CHARACTER SET utf8 COLLATE utf8_unicode_ci </sql> <sql> ALTER TABLE ${table.user} MODIFY email VARCHAR(255) CHARACTER SET utf8 COLLATE utf8_unicode_ci </sql> </changeSet> <changeSet id="201407310861" author="arne"> <preConditions onFail="MARK_RAN"> <not> <indexExists tableName="${table.user}" columnNames="username"/> </not> </preConditions> <comment>Create name index on user table</comment> <createIndex tableName="${table.user}" indexName="ix_um_user_username" unique="true"> <column name="username"/> </createIndex> </changeSet> <changeSet id="201407310862" author="arne"> <preConditions onFail="MARK_RAN"> <not> <indexExists tableName="${table.user}" columnNames="email"/> </not> </preConditions> <comment>Create email index on user table</comment> <createIndex tableName="${table.user}" indexName="ix_um_user_email"> <column name="email"/> </createIndex> </changeSet> <changeSet id="201408261116" author="arne"> <preConditions onFail="MARK_RAN"> <not> <columnExists tableName="${table.principal}" columnName="principal_name"/> </not> </preConditions> <comment>Add unique name to principal table</comment> <addColumn tableName="${table.principal}"> <column name="principal_name" type="java.sql.Types.VARCHAR(255)"> <constraints nullable="true"/> </column> </addColumn> <sql> UPDATE ${table.principal} SET principal_name = (SELECT username FROM ${table.user} WHERE id = ${table.principal}.id) </sql> <sql dbms="mysql"> ALTER TABLE ${table.principal} MODIFY principal_name VARCHAR(255) CHARACTER SET utf8 COLLATE utf8_unicode_ci </sql> <createIndex tableName="${table.principal}" indexName="ix_um_p_pname" unique="true"> <column name="principal_name"/> </createIndex> </changeSet> <changeSet id="201408221203" author="arne"> <preConditions onFail="MARK_RAN"> <tableExists tableName="um_user_role"/> </preConditions> <comment>Rename old user role table</comment> <dropForeignKeyConstraint baseTableName="um_user_role" constraintName="fk_um_ur_user_id"/> <renameColumn tableName="um_user_role" oldColumnName="user_id" newColumnName="principal_id" columnDataType="java.sql.Types.BIGINT"/> <renameTable oldTableName="um_user_role" newTableName="${table.principal_role}"/> <addForeignKeyConstraint baseTableName="${table.principal_role}" baseColumnNames="principal_id" constraintName="fk_um_pr_principal_id" referencedTableName="${table.principal}" referencedColumnNames="id"/> </changeSet> <changeSet id="201408221204" author="arne"> <preConditions onFail="MARK_RAN"> <not> <tableExists tableName="${table.principal_role}"/> </not> </preConditions> <comment>Create principal role table</comment> <createTable tableName="${table.principal_role}"> <column name="principal_id" type="java.sql.Types.BIGINT"> <constraints nullable="false" primaryKey="true" primaryKeyName="pk_um_principal_role"/> </column> <column name="role_id" type="java.sql.Types.BIGINT"> <constraints nullable="false" primaryKey="true" primaryKeyName="pk_um_principal_role"/> </column> </createTable> <addForeignKeyConstraint baseTableName="${table.principal_role}" baseColumnNames="principal_id" constraintName="fk_um_pr_principal_id" referencedTableName="${table.principal}" referencedColumnNames="id"/> <addForeignKeyConstraint baseTableName="${table.principal_role}" baseColumnNames="role_id" constraintName="fk_um_pr_role_id" referencedTableName="${table.role}" referencedColumnNames="id"/> </changeSet> <changeSet id="201408221351" author="arne"> <preConditions onFail="MARK_RAN"> <not> <tableExists tableName="${table.group}"/> </not> </preConditions> <comment>Create group table</comment> <createTable tableName="${table.group}"> <column name="id" type="java.sql.Types.BIGINT"> <constraints nullable="false" primaryKey="true" primaryKeyName="pk_um_group"/> </column> <column name="name" type="java.sql.Types.NVARCHAR(255)"> <constraints nullable="false" unique="true"/> </column> </createTable> <addForeignKeyConstraint baseTableName="${table.group}" baseColumnNames="id" constraintName="fk_um_group_pid" referencedTableName="${table.principal}" referencedColumnNames="id"/> </changeSet> <changeSet id="201409121508" author="arne"> <preConditions onFail="MARK_RAN"> <tableExists tableName="${table.principal_group}"/> </preConditions> <comment>Drop existing principal_group table</comment> <dropTable tableName="${table.principal_group}"/> </changeSet> <changeSet id="201408221354B" author="arne"> <preConditions onFail="MARK_RAN"> <not> <tableExists tableName="${table.principal_group}"/> </not> </preConditions> <comment>Create principal_group table</comment> <createTable tableName="${table.principal_group}"> <column name="principal_id" type="java.sql.Types.BIGINT"> <constraints nullable="false" primaryKey="true" primaryKeyName="pk_um_pgrp"/> </column> <column name="group_id" type="java.sql.Types.BIGINT"> <constraints nullable="false" primaryKey="true" primaryKeyName="pk_um_pgrp"/> </column> </createTable> <addForeignKeyConstraint baseTableName="${table.principal_group}" baseColumnNames="principal_id" constraintName="fk_um_pgrp_pid" referencedTableName="${table.principal}" referencedColumnNames="id"/> <addForeignKeyConstraint baseTableName="${table.principal_group}" baseColumnNames="group_id" constraintName="fk_um_pgrp_gid" referencedTableName="${table.group}" referencedColumnNames="id"/> </changeSet> <changeSet id="201407071223C" author="marc"> <preConditions onFail="MARK_RAN"> <not> <columnExists tableName="${table.user}" columnName="first_name"/> </not> </preConditions> <comment>Add some core columns to the user table</comment> <addColumn tableName="${table.user}"> <column name="first_name" type="java.sql.Types.NVARCHAR(255)"/> <column name="last_name" type="java.sql.Types.NVARCHAR(255)"/> <column name="display_name" type="java.sql.Types.NVARCHAR(255)"/> <column name="email_confirmed" type="java.sql.Types.BOOLEAN" defaultValueBoolean="false"> <constraints nullable="false"/> </column> <column name="deleted" type="java.sql.Types.BOOLEAN" defaultValueBoolean="false"> <constraints nullable="false"/> </column> <column name="restrictions" type="java.sql.Types.BIGINT" defaultValueNumeric="0"> <constraints nullable="false"/> </column> </addColumn> </changeSet> <changeSet id="201407251127B" author="marc"> <comment>Update email on admin user</comment> <update tableName="${table.user}"> <column name="email" type="java.sql.Types.VARCHAR(255)" value="admin@localhost"/> <where>username='admin'</where> </update> </changeSet> <changeSet id="201407301347" author="arne"> <comment>Add referential key between user properties and user table</comment> <addForeignKeyConstraint baseTableName="${table.user_properties}" baseColumnNames="user_id" constraintName="fk_um_up_u" referencedTableName="${table.user}" referencedColumnNames="id"/> </changeSet> <changeSet id="201407301415" author="arne"> <comment>Update existing sequences to work with new generator</comment> <sql> update across_sequences set seq_number = (select max(id) + 1 from ${table.role}) where seq_name = 'seq_um_role_id' </sql> <sql> update across_sequences set seq_number = (select max(id) + 1 from ${table.permission}) where seq_name = 'seq_um_permission_id' </sql> <sql> update across_sequences set seq_number = (select max(id) + 1 from ${table.user}) where seq_name = 'seq_um_user_id' </sql> <sql> update across_sequences set seq_number = (select max(id) + 1 from ${table.permission_group}) where seq_name = 'seq_um_permission_group_id' </sql> <sql> update across_sequences set seq_number = 1 where seq_number is null </sql> </changeSet> <changeSet id="201408281110" author="arne"> <preConditions onFail="MARK_RAN"> <not> <tableExists tableName="${table.machine}"/> </not> </preConditions> <comment>Create machine principal table</comment> <createTable tableName="${table.machine}"> <column name="id" type="java.sql.Types.BIGINT"> <constraints nullable="false" primaryKey="true" primaryKeyName="pk_um_machine"/> </column> <column name="name" type="java.sql.Types.VARCHAR(100)"> <constraints nullable="false" unique="true"/> </column> </createTable> <addForeignKeyConstraint baseTableName="${table.machine}" baseColumnNames="id" constraintName="fk_um_machine_pid" referencedTableName="${table.principal}" referencedColumnNames="id"/> </changeSet> <changeSet id="201501291601" author="arne"> <preConditions onFail="MARK_RAN"> <indexExists tableName="${table.role}" indexName="ix_um_role_name"/> </preConditions> <dropIndex tableName="${table.role}" indexName="ix_um_role_name"/> </changeSet> <changeSet id="201501291602" author="arne"> <preConditions onFail="MARK_RAN"> <not> <columnExists tableName="${table.role}" columnName="authority"/> </not> </preConditions> <addColumn tableName="${table.role}"> <column name="authority" type="java.sql.Types.VARCHAR(100)"> <constraints nullable="true"/> </column> </addColumn> <sql> UPDATE ${table.role} SET authority = name </sql> <sql> UPDATE ${table.role} SET name = description </sql> <addNotNullConstraint tableName="${table.role}" columnName="authority" columnDataType="java.sql.Types.VARCHAR(100)"/> <createIndex tableName="${table.role}" indexName="ix_um_role_auth" unique="true"> <column name="authority"/> </createIndex> </changeSet> <!-- AXUM-14 support user directories --> <changeSet id="201603171102" author="arne"> <preConditions onFail="MARK_RAN"> <not> <tableExists tableName="${table.user_directory}"/> </not> </preConditions> <comment>Create user_directory table and default user directory</comment> <createTable tableName="${table.user_directory}"> <column name="id" type="java.sql.Types.BIGINT"> <constraints nullable="false" primaryKey="true" primaryKeyName="pk_um_user_dir"/> </column> <column name="name" type="java.sql.Types.NVARCHAR(255)"> <constraints nullable="false" unique="true"/> </column> <column name="directory_type" type="java.sql.Types.VARCHAR(100)" defaultValue="internal"> <constraints nullable="false" /> </column> <column name="authentication_order" type="java.sql.Types.INTEGER" defaultValue="1"> <constraints nullable="false" /> </column> <column name="active" type="java.sql.Types.BOOLEAN" defaultValueBoolean="true"> <constraints nullable="false"/> </column> <column name="settings_id" type="java.sql.Types.BIGINT" /> <column name="settings_key" type="java.sql.Types.VARCHAR(255)" /> </createTable> <insert tableName="${table.user_directory}"> <column name="id">1</column> <column name="name">Default internal directory</column> <column name="directory_type">internal</column> <column name="authentication_order">0</column> </insert> <!-- Ensure that sequence starts higher --> <insert tableName="across_sequences"> <column name="seq_name">seq_um_user_directory_id</column> <column name="seq_number">2</column> </insert> </changeSet> <!-- AXUM-14 Add user directory to principals --> <changeSet id="201603171258" author="arne"> <preConditions onFail="MARK_RAN"> <not> <columnExists tableName="${table.principal}" columnName="user_directory_id"/> </not> </preConditions> <comment>Add user directory to principal table with default value</comment> <addColumn tableName="${table.principal}"> <column name="user_directory_id" type="java.sql.Types.BIGINT" defaultValue="1"/> </addColumn> <addForeignKeyConstraint baseTableName="${table.principal}" baseColumnNames="user_directory_id" constraintName="fk_um_principal_did" referencedTableName="${table.user_directory}" referencedColumnNames="id"/> </changeSet> <!-- AXUM-14 remove unique name constraint of group --> <changeSet id="201603181405" author="arne"> <preConditions onFail="MARK_RAN"> <not> <indexExists tableName="${table.group}" indexName="ix_um_grp_name"/> </not> </preConditions> <comment>Drop constraints on group name and recreate as regular index</comment> <addColumn tableName="${table.group}"> <column name="new_name" type="java.sql.Types.NVARCHAR(255)"/> </addColumn> <sql> update ${table.group} set new_name = name </sql> <sql splitStatements="false" dbms="mssql"> DECLARE @Cons_Name NVARCHAR(100) DECLARE @Str NVARCHAR(500) SELECT @Cons_Name=name FROM sys.objects WHERE type='UQ' AND OBJECT_NAME(parent_object_id) = N'${table.group}'; ---- Delete the unique constraint. SET @Str='ALTER TABLE ${table.group} DROP CONSTRAINT ' + @Cons_Name; Exec (@Str) </sql> <dropColumn tableName="${table.group}" columnName="name"/> <renameColumn tableName="${table.group}" oldColumnName="new_name" newColumnName="name" columnDataType="java.sql.Types.NVARCHAR(255)"/> <addNotNullConstraint tableName="${table.group}" columnName="name" columnDataType="java.sql.Types.NVARCHAR(255)"/> <createIndex tableName="${table.group}" indexName="ix_um_grp_name" unique="false"> <column name="name"/> </createIndex> </changeSet> <!-- AXUM-14 remove unique name constraint of machine principal --> <changeSet id="201603181427" author="arne"> <preConditions onFail="MARK_RAN"> <not> <indexExists tableName="${table.machine}" indexName="ix_um_machine_name"/> </not> </preConditions> <comment>Drop constraints on machine principal name and recreate as regular index</comment> <addColumn tableName="${table.machine}"> <column name="new_name" type="java.sql.Types.NVARCHAR(255)"/> </addColumn> <sql> update ${table.machine} set new_name = name </sql> <sql splitStatements="false" dbms="mssql"> DECLARE @Cons_Name NVARCHAR(100) DECLARE @Str NVARCHAR(500) SELECT @Cons_Name=name FROM sys.objects WHERE type='UQ' AND OBJECT_NAME(parent_object_id) = N'${table.machine}'; ---- Delete the unique constraint. SET @Str='ALTER TABLE ${table.machine} DROP CONSTRAINT ' + @Cons_Name; Exec (@Str) </sql> <dropColumn tableName="${table.machine}" columnName="name"/> <renameColumn tableName="${table.machine}" oldColumnName="new_name" newColumnName="name" columnDataType="java.sql.Types.NVARCHAR(255)"/> <addNotNullConstraint tableName="${table.machine}" columnName="name" columnDataType="java.sql.Types.NVARCHAR(255)"/> <createIndex tableName="${table.machine}" indexName="ix_um_machine_name" unique="false"> <column name="name"/> </createIndex> </changeSet> <!-- AX-57 Liquibase upgrade to 3.5.3 introduced quoting of columns on reserved keywords, this broke the "password" column --> <changeSet id="201611080826" author="marc"> <preConditions onFail="MARK_RAN"> <not> <columnExists tableName="${table.user}" columnName="user_pwd"/> </not> </preConditions> <comment>Rename the password column to user_pwd, as this is a reserved keyword in Oracle</comment> <renameColumn tableName="${table.user}" oldColumnName="password" newColumnName="user_pwd" columnDataType="java.sql.Types.NVARCHAR(255)"/> </changeSet> </databaseChangeLog>
© 2015 - 2024 Weber Informatics LLC | Privacy Policy