-- 10.0.init.sql

/*
将 paas.example.com 替换为 paas.学校域名.edu.cn
*/


use admin_center;


insert into TB_MGT_ROUTE (ID, DELETED, CODE, NAME, STATUS, PATH_PREFIX, URL, STRIP_PREFIX) 
values ('1', 0, 'bff-admin-api', '管理门户 - 聚合接口', '1', '/api/v1/admin', 'http://localhost:8081', 0);
insert into TB_MGT_ROUTE (ID, DELETED, CODE, NAME, STATUS, PATH_PREFIX, URL, STRIP_PREFIX) 
values ('2', 0, 'bff-me-api', '管理门户 - 聚合接口（当前用户）', '1', '/api/v1/me', 'http://localhost:8081', 0);
insert into TB_MGT_ROUTE (ID, DELETED, CODE, NAME, STATUS, PATH_PREFIX, URL, STRIP_PREFIX) 
values ('3', 0, 'bff-open-api', '管理门户 - 聚合接口（公开）', '1', '/api/v1/open', 'http://localhost:8081', 0);

update TB_MGT_ROUTE set URL='http://admin-platform-admin-center-bff.admin-platform.svc.cluster.local:8080' where ID='1';
update TB_MGT_ROUTE set URL='http://admin-platform-admin-center-bff.admin-platform.svc.cluster.local:8080' where ID='2';
update TB_MGT_ROUTE set URL='http://admin-platform-admin-center-bff.admin-platform.svc.cluster.local:8080' where ID='3';

commit;


insert into TB_MGT_ROUTE (ID, DELETED, CODE, NAME, STATUS, PATH_PREFIX, URL, STRIP_PREFIX) 
values ('9', 0, 'management-api', '管理门户 - 管理接口', '1', '/api/v1/mgt', 'http://localhost:8080/v1/admin', 1);

commit;

update TB_MGT_ROUTE set URL='http://admin-platform-admin-center-sa.admin-platform.svc.cluster.local:8080/v1/admin' where ID='9';

commit;


-- 更新 admin-center 下菜单的访问域
update TB_MGT_PERMISSION
set 
  ORIGIN='http://admin-center.paas.example.com'
where APPLICATION_ID='00000'
;

commit;


-- 更新 admin-platform 下菜单的访问域
update TB_MGT_PERMISSION
set 
  ORIGIN='http://admin-platform.paas.example.com'
where APPLICATION_ID='1'
;

commit;


use cas_server;

-- 更新 服务 admin-center 的信息（废弃）
update TB_SERVICE 
set 
  INFORMATION_URL='http://admin-center.paas.example.com', 
  LOGOUT_URL='https://admin-center.paas.example.com/slo?redirect_uri=https://admin-platform.paas.example.com?clearCertification=Admin-Token',
  SERVICE_ID='http://admin-center.paas.example.com/cas/(.*)'
where ID='1';  -- todo, modify

commit;


-- admin-management 的认证对接信息
INSERT INTO `TB_SERVICE` (`ID`, `COMPANY_ID`, `DELETED`, `ADD_ACCOUNT`, `ADD_TIME`, 
  `NAME`, `DESCRIPTION`, `INFORMATION_URL`, `LOGOUT_URL`, 
  `RESPONSE_TYPE`, `LOGOUT_TYPE`, 
  `EVALUATION_ORDER`, `FRIENDLY_NAME`, `REGISTERED_SERVICE_ID`, `SERVICE_ID`, 
  `ENABLED`, `SSO_ENABLED`, `REQUIRE_ALL_ATTRIBUTES`, 
  `APPLICATION_ID`, `EXTERNAL_ID`)
VALUES ('20', '1', 0, 'admin', '2020-07-01 00:00:00',
  '基础管理', '基础管理', 'https://admin-center.paas.example.com', 'https://admin-center.paas.example.com/?clearToken=clearToken', 
  'REDIRECT', 'FRONT_CHANNEL', 
  20, '基础管理', 20, 'https://admin-center.paas.example.com/(.*)', 
  1, 1, 1, 
  '20', '20');

commit;

-- 修改根域名
update TB_SERVICE 
set 
  INFORMATION_URL='http://admin-center.paas.example.com', 
  LOGOUT_URL='http://admin-center.paas.example.com/?clearToken=clearToken', 
  SERVICE_ID='http://admin-center.paas.example.com/(.*)', 
  ID_TOKEN_ENABLED=1,
  JWT_AS_SERVICE_TICKET=1,
  APPLICATION_DOMAIN='admin-center.paas.example.com'
where ID='20';  -- todo, modify

commit;


-- admin-platform 的认证对接信息
INSERT INTO `TB_SERVICE` (`ID`, `COMPANY_ID`, `DELETED`, `ADD_ACCOUNT`, `ADD_TIME`, 
  `NAME`, `DESCRIPTION`, `INFORMATION_URL`, `LOGOUT_URL`, 
  `RESPONSE_TYPE`, `LOGOUT_TYPE`, 
  `EVALUATION_ORDER`, `FRIENDLY_NAME`, `REGISTERED_SERVICE_ID`, `SERVICE_ID`, 
  `ENABLED`, `SSO_ENABLED`, `REQUIRE_ALL_ATTRIBUTES`, 
  `APPLICATION_ID`, `EXTERNAL_ID`)
VALUES ('21', '1', 0, 'admin', '2020-07-01 00:00:00',
  '云平台', '云平台', 'https://admin-platform.paas.example.com', 'https://admin-platform.paas.example.com/?clearToken=clearToken', 
  'REDIRECT', 'FRONT_CHANNEL', 
  21, '云平台', 21, 'https://admin-platform.paas.example.com/(.*)', 
  1, 1, 1, 
  '21', '21');

commit;

-- 修改根域名
update TB_SERVICE 
set 
  INFORMATION_URL='http://admin-platform.paas.example.com', 
  LOGOUT_URL='http://admin-platform.paas.example.com/?clearToken=clearToken', 
  SERVICE_ID='http://admin-platform.paas.example.com/(.*)', 
  ID_TOKEN_ENABLED=1,
  JWT_AS_SERVICE_TICKET=1,
  APPLICATION_DOMAIN='admin-platform.paas.example.com'
where ID='21';  -- todo, modify

commit;



use user_authz;

-- 更新 admin-center 下的角色同步地址
update TB_APPLICATION
set
  SYNC_URL='http://admin-center.paas.example.com/api/v1/open/sync/roles'
where ID='1';  -- todo, modify

commit;

