Commit 9afc12f5 authored by Maxym Borodenko's avatar Maxym Borodenko
Browse files

Liquibase changes

parent 091507a5
......@@ -8181,3 +8181,232 @@ databaseChangeLog:
name: is_exempt
type: nvarchar(1)
tableName: taxonomy_regulation_map
- changeSet:
id: 1618393601951-1
author: mborodenko
comment: Assure acl_sid records for each sys_group entry
changes:
- sql:
splitStatements: false
sql: >-
declare @max_sid bigint;
select @max_sid = max(id) from acl_sid;
set identity_insert acl_sid on;
insert into acl_sid (id, sid, type, version, active, principal, created_date, last_modified_date, created_by, last_modified_by) (select sg.sys_group_id + @max_sid, concat('GROUP_', sg.group_tag), 5, 1, iif(is_enabled = 'Y', 1, 0), 0, sg.created_date, sg.modified_date, sg.created_by, sg.modified_by from sys_group sg left join acl_sid sid on sid.sid = concat('GROUP_', sg.group_tag) where sid.id is null);
set identity_insert acl_sid off;
- sql:
comment: Update current sys_group entries in acl_sid where type is 0
sql: >-
update sid set sid.type=5 from acl_sid sid inner join sys_group sg on sid.sid = concat('GROUP_', sg.group_tag) where sid.type = 0;
- changeSet:
id: 1618393601951-2
author: mborodenko
comment: Add 'id' column to sys_group
changes:
- preConditions:
- onFail: HALT
- sqlCheck:
expectedResult: 0
sql: select count(*) from sys_group sg left join acl_sid sid on sid.sid = concat('GROUP_', sg.group_tag) where sid.id is null;
- addColumn:
tableName: sys_group
columns:
- column:
name: id
type: bigint
beforeColumn: sys_group_id
- sql:
sql: update sys_group set id=sys_group_id;
- changeSet:
id: 1618393601951-3
author: mborodenko
changes:
# SysUser: Making obsolete columns owned_by, owned_date, created_by, created_date nullable. Some are in acl_sid.
- dropForeignKeyConstraint:
baseTableName: sys_group
constraintName: ndx_fk_sg_created
- dropForeignKeyConstraint:
baseTableName: sys_group
constraintName: ndx_fk_sg_modified
- dropForeignKeyConstraint:
baseTableName: sys_group
constraintName: ndx_fk_sg_owned
- dropNotNullConstraint:
tableName: sys_group
columnName: created_date
columnDataType: datetime2
- dropNotNullConstraint:
tableName: sys_group
columnName: owned_date
columnDataType: datetime2
- dropNotNullConstraint:
tableName: sys_group
columnName: owned_by
columnDataType: int
- dropNotNullConstraint:
tableName: sys_group
columnName: created_by
columnDataType: int
# Drop columns. Some are in acl_sid.
- dropColumn:
columnName: created_by
tableName: sys_group
- dropColumn:
columnName: created_date
tableName: sys_group
- dropColumn:
columnName: modified_by
tableName: sys_group
- dropColumn:
columnName: modified_date
tableName: sys_group
- dropColumn:
columnName: owned_by
tableName: sys_group
- dropColumn:
columnName: owned_date
tableName: sys_group
- changeSet:
id: 1618393601951-4
author: mborodenko
comment: Make sys_group ID the primary key
changes:
# Need to remove existing FKs, can't change PK without that
- sql:
comment: >-
select distinct 'alter table ' + OBJECT_NAME(f.parent_object_id) + ' drop constraint if exists ' + f.name + ';' as sql
FROM sys.foreign_keys AS f
INNER JOIN sys.foreign_key_columns AS fc ON f.object_id = fc.constraint_object_id
where OBJECT_NAME (f.referenced_object_id) = 'sys_group';
sql: >-
alter table sys_group_lang drop constraint if exists fk_sgl_sg;
alter table sys_group_permission_map drop constraint if exists fk_sgpm_sg;
alter table sys_group_user_map drop constraint if exists fk_sgum_sg;
- dropIndex:
indexName: ndx_uniq_sgl
tableName: sys_group_lang
- dropIndex:
indexName: ndx_uniq_sgpm
tableName: sys_group_permission_map
- dropIndex:
indexName: ndx_uniq_sgum
tableName: sys_group_user_map
- sql:
comment: >-
select distinct 'alter table ' + OBJECT_NAME(f.parent_object_id) + '
alter column ' + COL_NAME(fc.parent_object_id, fc.parent_column_id) + ' bigint not null;' as sql
FROM sys.foreign_keys AS f
INNER JOIN sys.foreign_key_columns AS fc ON f.object_id = fc.constraint_object_id
where OBJECT_NAME (f.referenced_object_id) = 'sys_group';
sql: >-
alter table sys_group_lang alter column sys_group_id bigint not null;
alter table sys_group_permission_map alter column sys_group_id bigint not null;
alter table sys_group_user_map alter column sys_group_id bigint not null;
- sql:
comment: Update sys_group_id in sys_group_lang
sql: >-
drop table if exists sys_group2;
select sg.sys_group_id, sid.id, sg.group_tag into sys_group2 from sys_group sg inner join acl_sid sid on sid.sid = concat('GROUP_', sg.group_tag);
update sgl set sgl.sys_group_id=sg2.id from sys_group_lang sgl inner join sys_group2 sg2 on sg2.sys_group_id=sgl.sys_group_id;
drop table sys_group2;
- sql:
comment: Update sys_group_id in sys_group_permission_map
sql: >-
drop table if exists sys_group2;
select sg.sys_group_id, sid.id, sg.group_tag into sys_group2 from sys_group sg inner join acl_sid sid on sid.sid = concat('GROUP_', sg.group_tag);
update sgpm set sgpm.sys_group_id=sg2.id from sys_group_permission_map sgpm inner join sys_group2 sg2 on sg2.sys_group_id=sgpm.sys_group_id;
drop table sys_group2;
- sql:
comment: Update sys_group_id in sys_group_user_map
sql: >-
drop table if exists sys_group2;
select sg.sys_group_id, sid.id, sg.group_tag into sys_group2 from sys_group sg inner join acl_sid sid on sid.sid = concat('GROUP_', sg.group_tag);
update sgum set sgum.sys_group_id=sg2.id from sys_group_user_map sgum inner join sys_group2 sg2 on sg2.sys_group_id=sgum.sys_group_id;
drop table sys_group2;
- sql:
comment: Update sys_group_id in sys_group
sql: >-
drop table if exists sys_group2;
select sg.sys_group_id, sid.id, sg.group_tag into sys_group2 from sys_group sg inner join acl_sid sid on sid.sid = concat('GROUP_', sg.group_tag);
update sg set sg.id=sg2.id from sys_group sg inner join sys_group2 sg2 on sg2.sys_group_id=sg.sys_group_id;
drop table sys_group2;
- dropPrimaryKey:
tableName: sys_group
- addNotNullConstraint:
columnDataType: bigint
columnName: id
tableName: sys_group
- addPrimaryKey:
tableName: sys_group
columnNames: id
constraintName: PK_sys_group
- addForeignKeyConstraint:
baseTableName: sys_group
baseColumnNames: id
constraintName: fk_sg_sid
referencedTableName: acl_sid
referencedColumnNames: id
# Get rid of IDENTITY
- dropColumn:
tableName: sys_group
columnName: sys_group_id
- addColumn:
tableName: sys_group
columns:
- column:
name: sys_group_id
type: int
afterColumn: id
constraints:
nullable: true
- sql:
sql: update sys_group set sys_group_id=id;
- changeSet:
id: 1618393601951-5
author: mborodenko
comment: Recreate FKs and indices
changes:
- sql:
comment: >-
select distinct 'alter table ' + OBJECT_NAME(f.parent_object_id) + '
add constraint ' + f.name + ' foreign key (' + COL_NAME(fc.parent_object_id, fc.parent_column_id) + ')
references ' + OBJECT_NAME (f.referenced_object_id) + ' (id);' as sql
FROM sys.foreign_keys AS f
INNER JOIN sys.foreign_key_columns AS fc ON f.object_id = fc.constraint_object_id
where OBJECT_NAME (f.referenced_object_id) = 'sys_group';
sql: >-
alter table sys_group_lang add constraint fk_sgl_sg foreign key (sys_group_id) references sys_group (id);
alter table sys_group_permission_map add constraint fk_sgpm_sg foreign key (sys_group_id) references sys_group (id);
alter table sys_group_user_map add constraint fk_sgum_sg foreign key (sys_group_id) references sys_group (id);
- createIndex:
columns:
- column:
name: sys_group_id
- column:
name: sys_lang_id
indexName: ndx_uniq_sgl
tableName: sys_group_lang
unique: true
- createIndex:
columns:
- column:
name: sys_group_id
- column:
name: sys_permission_id
indexName: ndx_uniq_sgpm
tableName: sys_group_permission_map
unique: true
- createIndex:
columns:
- column:
name: sys_group_id
- column:
name: sys_user_id
indexName: ndx_uniq_sgum
tableName: sys_group_user_map
unique: true
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment