mirror of
https://github.com/thousmile/molly-multi-tenant.git
synced 2025-12-30 12:42:26 +00:00
1.移除 master-change-log 和 other-change-log 统一使用 change-log ,根据 context 来区分,哪些表是主库的,哪些是 租户库的
This commit is contained in:
@@ -21,7 +21,7 @@ public class ConfigName {
|
||||
/**
|
||||
* 用户默认密码
|
||||
*/
|
||||
public static final String USER_DEFAULT_PASSWORD = "user_default_password";
|
||||
public static final String USER_DEFAULT_PASSWORD = "default_user_password";
|
||||
|
||||
|
||||
/**
|
||||
|
||||
@@ -20,14 +20,13 @@ spring:
|
||||
|
||||
liquibase:
|
||||
enabled: true
|
||||
change-log: ${multi.tenant.master-change-log}
|
||||
change-log: classpath:db/changelog-master.xml
|
||||
contexts: platform,tenant
|
||||
|
||||
|
||||
# 多租户配置
|
||||
multi:
|
||||
tenant:
|
||||
master-change-log: classpath:db/changelog-master.xml
|
||||
other-change-log: classpath:db/changelog-other.xml
|
||||
prefix: molly_
|
||||
default-tenant-id: master
|
||||
default-project-id: 10001
|
||||
@@ -35,6 +34,8 @@ multi:
|
||||
enable: true
|
||||
enable-project: true
|
||||
create-table: true
|
||||
contexts: tenant
|
||||
change-log: ${spring.liquibase.change-log}
|
||||
|
||||
|
||||
# mybatis-plus 自动配置
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog
|
||||
https://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-latest.xsd">
|
||||
|
||||
|
||||
<include file="db/changelog/sys.xml"/>
|
||||
|
||||
<include file="db/changelog/lms.xml"/>
|
||||
@@ -15,49 +16,49 @@
|
||||
|
||||
|
||||
<!-- 初始化 租户,权限模板 -->
|
||||
<changeSet author="WangChenChen (generated)" id="1699414472275-10">
|
||||
<changeSet context="platform" author="WangChenChen (generated)" id="1699414472275-10">
|
||||
<sqlFile path="db/changelog/sql/tenant_init.sql"/>
|
||||
</changeSet>
|
||||
|
||||
|
||||
<!-- 初始化 用户,角色,部门, -->
|
||||
<changeSet author="WangChenChen (generated)" id="1699414472275-20">
|
||||
<changeSet context="platform" author="WangChenChen (generated)" id="1699414472275-20">
|
||||
<sqlFile path="db/changelog/sql/pms_init.sql"/>
|
||||
</changeSet>
|
||||
|
||||
|
||||
<!-- 初始化 默认的项目 -->
|
||||
<changeSet author="WangChenChen (generated)" id="1699414472275-30">
|
||||
<changeSet context="platform" author="WangChenChen (generated)" id="1699414472275-30">
|
||||
<sqlFile path="db/changelog/sql/cms_init.sql"/>
|
||||
</changeSet>
|
||||
|
||||
|
||||
<!-- 初始化 中国行政区域 -->
|
||||
<changeSet author="WangChenChen (generated)" id="1699414472275-40">
|
||||
<changeSet context="platform" author="WangChenChen (generated)" id="1699414472275-40">
|
||||
<sqlFile path="db/changelog/sql/china_area.sql"/>
|
||||
</changeSet>
|
||||
|
||||
|
||||
<!-- 初始化 全局配置-->
|
||||
<changeSet author="WangChenChen (generated)" id="1699414472275-50">
|
||||
<changeSet context="platform" author="WangChenChen (generated)" id="1699414472275-50">
|
||||
<sqlFile path="db/changelog/sql/sys_config.sql"/>
|
||||
</changeSet>
|
||||
|
||||
|
||||
<!-- 初始化 字典类型表-->
|
||||
<changeSet author="WangChenChen (generated)" id="1699414472275-60">
|
||||
<changeSet context="platform" author="WangChenChen (generated)" id="1699414472275-60">
|
||||
<sqlFile path="db/changelog/sql/sys_dict_type.sql"/>
|
||||
</changeSet>
|
||||
|
||||
|
||||
<!-- 初始化 字典数据表-->
|
||||
<changeSet author="WangChenChen (generated)" id="1699414472275-70">
|
||||
<changeSet context="platform" author="WangChenChen (generated)" id="1699414472275-70">
|
||||
<sqlFile path="db/changelog/sql/sys_dict_data.sql"/>
|
||||
</changeSet>
|
||||
|
||||
|
||||
<!-- 初始化 菜单权限表 -->
|
||||
<changeSet author="WangChenChen (generated)" id="1699414472275-80">
|
||||
<changeSet context="platform" author="WangChenChen (generated)" id="1699414472275-80">
|
||||
<sqlFile path="db/changelog/sql/sys_menu.sql"/>
|
||||
</changeSet>
|
||||
|
||||
|
||||
@@ -1,14 +0,0 @@
|
||||
<?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
|
||||
https://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-latest.xsd">
|
||||
|
||||
<include file="db/changelog/pms.xml"/>
|
||||
|
||||
<include file="db/changelog/lms.xml"/>
|
||||
|
||||
<include file="db/changelog/cms.xml"/>
|
||||
|
||||
</databaseChangeLog>
|
||||
@@ -7,7 +7,7 @@
|
||||
|
||||
|
||||
<!-- [ 核心 ] 项目表 -->
|
||||
<changeSet author="WangChenChen (generated)" id="1699414175082-1">
|
||||
<changeSet context="tenant" author="WangChenChen (generated)" id="1699414175082-1">
|
||||
<createTable remarks="[ 项目 ] 项目表" tableName="cms_project">
|
||||
<column autoIncrement="true" name="project_id" remarks="项目ID" type="BIGINT">
|
||||
<constraints nullable="false" primaryKey="true"/>
|
||||
@@ -57,7 +57,7 @@
|
||||
|
||||
|
||||
<!-- [ 项目 ] 设备表 -->
|
||||
<changeSet author="WangChenChen (generated)" id="1699414177577-1">
|
||||
<changeSet context="tenant" author="WangChenChen (generated)" id="1699414177577-1">
|
||||
<createTable remarks="[ 项目 ] 设备表" tableName="cms_device">
|
||||
<column name="device_id" remarks="设备ID" type="BIGINT">
|
||||
<constraints nullable="false" primaryKey="true"/>
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
|
||||
|
||||
<!-- [ 日志 ] 操作日志 -->
|
||||
<changeSet author="WangChenChen (generated)" id="1699414162182-1">
|
||||
<changeSet context="tenant" author="WangChenChen (generated)" id="1699414162182-1">
|
||||
<createTable remarks="[ 日志 ] 操作日志" tableName="lms_oper_log">
|
||||
<column name="id" remarks="ID" type="VARCHAR(50)">
|
||||
<constraints nullable="false" primaryKey="true"/>
|
||||
@@ -47,7 +47,7 @@
|
||||
|
||||
|
||||
<!-- [ 日志 ] 登录日志 -->
|
||||
<changeSet author="WangChenChen (generated)" id="1699414165075-1">
|
||||
<changeSet context="tenant" author="WangChenChen (generated)" id="1699414165075-1">
|
||||
<createTable remarks="[ 日志 ] 登录日志" tableName="lms_login_log">
|
||||
<column name="id" remarks="ID" type="VARCHAR(50)">
|
||||
<constraints nullable="false" primaryKey="true"/>
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
|
||||
|
||||
<!-- [ 权限 ] 角色表 -->
|
||||
<changeSet author="WangChenChen (generated)" id="1699414131175-1">
|
||||
<changeSet context="tenant" author="WangChenChen (generated)" id="1699414131175-1">
|
||||
<createTable remarks="[ 权限 ] 角色表" tableName="pms_role">
|
||||
<column autoIncrement="true" name="role_id" remarks="角色id" type="BIGINT">
|
||||
<constraints nullable="false" primaryKey="true"/>
|
||||
@@ -39,7 +39,7 @@
|
||||
|
||||
|
||||
<!-- [ 权限 ] 角色和菜单权限表 -->
|
||||
<changeSet author="WangChenChen (generated)" id="1699414131175-2">
|
||||
<changeSet context="tenant" author="WangChenChen (generated)" id="1699414131175-2">
|
||||
<createTable remarks="[ 权限 ] 角色和菜单权限表" tableName="pms_role_menu">
|
||||
<column name="role_id" remarks="角色ID" type="BIGINT">
|
||||
<constraints nullable="false"/>
|
||||
@@ -52,7 +52,7 @@
|
||||
|
||||
|
||||
<!--[ 权限 ] 部门表-->
|
||||
<changeSet author="WangChenChen (generated)" id="1699414139574-1">
|
||||
<changeSet context="tenant" author="WangChenChen (generated)" id="1699414139574-1">
|
||||
<createTable remarks="[ 权限 ] 部门表" tableName="pms_dept">
|
||||
<column autoIncrement="true" name="dept_id" remarks="部门 ID" type="BIGINT">
|
||||
<constraints nullable="false" primaryKey="true"/>
|
||||
@@ -96,7 +96,7 @@
|
||||
|
||||
|
||||
<!-- [ 权限 ] 部门和菜单权限表 -->
|
||||
<changeSet author="WangChenChen (generated)" id="1699414139574-2">
|
||||
<changeSet context="tenant" author="WangChenChen (generated)" id="1699414139574-2">
|
||||
<createTable remarks="[ 权限 ] 部门和菜单权限表" tableName="pms_dept_menu">
|
||||
<column name="dept_id" remarks="部门ID" type="BIGINT">
|
||||
<constraints nullable="false"/>
|
||||
@@ -108,9 +108,8 @@
|
||||
</changeSet>
|
||||
|
||||
|
||||
|
||||
<!-- [ 权限 ] 用户表 -->
|
||||
<changeSet author="WangChenChen (generated)" id="1699414146178-1">
|
||||
<changeSet context="tenant" author="WangChenChen (generated)" id="1699414146178-1">
|
||||
<createTable remarks="[ 权限 ] 用户表" tableName="pms_user">
|
||||
<column name="user_id" remarks="用户ID" type="BIGINT">
|
||||
<constraints nullable="false" primaryKey="true"/>
|
||||
@@ -163,7 +162,7 @@
|
||||
|
||||
|
||||
<!-- [ 权限 ] 用户和角色表 -->
|
||||
<changeSet author="WangChenChen (generated)" id="1699414146178-2">
|
||||
<changeSet context="tenant" author="WangChenChen (generated)" id="1699414146178-2">
|
||||
<createTable remarks="[ 权限 ] 用户和角色表" tableName="pms_user_role">
|
||||
<column name="user_id" remarks="用户ID" type="BIGINT">
|
||||
<constraints nullable="false"/>
|
||||
@@ -176,7 +175,7 @@
|
||||
|
||||
|
||||
<!-- [ 权限 ] 用户社交平台登录 -->
|
||||
<changeSet author="WangChenChen (generated)" id="1699414146178-3">
|
||||
<changeSet context="tenant" author="WangChenChen (generated)" id="1699414146178-3">
|
||||
<createTable remarks="[ 权限 ] 用户社交平台登录" tableName="pms_user_social">
|
||||
<column autoIncrement="true" name="social_id" remarks="用户社交ID" type="BIGINT">
|
||||
<constraints nullable="false" primaryKey="true"/>
|
||||
|
||||
@@ -21,7 +21,7 @@ SET FOREIGN_KEY_CHECKS = 0;
|
||||
-- Records of sys_config
|
||||
-- ----------------------------
|
||||
|
||||
INSERT INTO `sys_config` VALUES (10001, '用户管理-账号初始密码', 'user_default_password', '123456', 1, '2021-07-14 11:48:16', 19980817, '2021-07-14 11:48:16', 19980817);
|
||||
INSERT INTO `sys_config` VALUES (10001, '用户管理-账号初始密码', 'default_user_password', '123456', 1, '2021-07-14 11:48:16', 19980817, '2021-07-14 11:48:16', 19980817);
|
||||
INSERT INTO `sys_config` VALUES (10002, '租户默认logo地址', 'default_tenant_logo', 'https://oss.mhtled.com/avatar/275753151968186368.png', 1, '2021-07-16 14:28:41', 19980817, '2022-09-19 14:47:26', 19980817);
|
||||
INSERT INTO `sys_config` VALUES (10003, '租户默认角色名称', 'default_role_name', '操作员', 1, '2021-07-16 17:26:56', 19980817, '2021-07-16 17:27:06', 19980817);
|
||||
INSERT INTO `sys_config` VALUES (10004, '获取法定节假日的接口', 'get_holiday_url', 'https://timor.tech/api/holiday/year/%s?type=N&week=Y', 1, '2022-05-16 11:50:20', 19980817, '2022-05-16 11:50:25', 19980817);
|
||||
|
||||
@@ -6,9 +6,9 @@
|
||||
https://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-latest.xsd">
|
||||
|
||||
|
||||
<!-- [ 租户 ] 租户表 -->
|
||||
<changeSet author="WangChenChen (generated)" id="1699414015975-1">
|
||||
<createTable remarks="[ 租户 ] 租户表" tableName="sys_tenant">
|
||||
<!-- [ 系统 ] 租户表 -->
|
||||
<changeSet context="platform" author="WangChenChen (generated)" id="1699414015975-1">
|
||||
<createTable remarks="[ 系统 ] 租户表" tableName="sys_tenant">
|
||||
<column name="tenant_id" remarks="租户 ID" type="VARCHAR(20)">
|
||||
<constraints nullable="false" primaryKey="true" unique="true"/>
|
||||
</column>
|
||||
@@ -55,9 +55,9 @@
|
||||
</changeSet>
|
||||
|
||||
|
||||
<!-- [ 租户 ] 租户和权限模板表 -->
|
||||
<changeSet author="WangChenChen (generated)" id="1699414015975-2">
|
||||
<createTable remarks="[ 租户 ] 租户和权限模板表" tableName="sys_tenant_template">
|
||||
<!-- [ 系统 ] 租户和权限模板表 -->
|
||||
<changeSet context="platform" author="WangChenChen (generated)" id="1699414015975-2">
|
||||
<createTable remarks="[ 系统 ] 租户和权限模板表" tableName="sys_tenant_template">
|
||||
<column name="tenant_id" remarks="租户ID" type="VARCHAR(20)">
|
||||
<constraints nullable="false"/>
|
||||
</column>
|
||||
@@ -68,9 +68,9 @@
|
||||
</changeSet>
|
||||
|
||||
|
||||
<!-- [ 租户 ] 用户和租户表 -->
|
||||
<changeSet author="WangChenChen (generated)" id="1699414015975-3">
|
||||
<createTable remarks="[ 租户 ] 用户和租户表" tableName="sys_user_tenant">
|
||||
<!-- [ 系统 ] 用户和租户表 -->
|
||||
<changeSet context="platform" author="WangChenChen (generated)" id="1699414015975-3">
|
||||
<createTable remarks="[ 系统 ] 用户和租户表" tableName="sys_user_tenant">
|
||||
<column name="user_id" remarks="用户 ID" type="BIGINT">
|
||||
<constraints nullable="false"/>
|
||||
</column>
|
||||
@@ -81,9 +81,9 @@
|
||||
</changeSet>
|
||||
|
||||
|
||||
<!-- [ 租户 ] 权限模板表 -->
|
||||
<changeSet author="WangChenChen (generated)" id="1699414015975-4">
|
||||
<createTable remarks="[ 租户 ] 权限模板表" tableName="sys_template">
|
||||
<!-- [ 系统 ] 权限模板表 -->
|
||||
<changeSet context="platform" author="WangChenChen (generated)" id="1699414015975-4">
|
||||
<createTable remarks="[ 系统 ] 权限模板表" tableName="sys_template">
|
||||
<column autoIncrement="true" name="id" remarks="模板ID" type="BIGINT">
|
||||
<constraints nullable="false" primaryKey="true"/>
|
||||
</column>
|
||||
@@ -110,9 +110,9 @@
|
||||
</changeSet>
|
||||
|
||||
|
||||
<!-- [ 租户 ] 模板和菜单权限表 -->
|
||||
<changeSet author="WangChenChen (generated)" id="1699414015975-5">
|
||||
<createTable remarks="[ 租户 ] 模板和菜单权限表" tableName="sys_template_menu">
|
||||
<!-- [ 系统 ] 模板和菜单权限表 -->
|
||||
<changeSet context="platform" author="WangChenChen (generated)" id="1699414015975-5">
|
||||
<createTable remarks="[ 系统 ] 模板和菜单权限表" tableName="sys_template_menu">
|
||||
<column name="template_id" remarks="模板 ID" type="BIGINT">
|
||||
<constraints nullable="false"/>
|
||||
</column>
|
||||
@@ -124,7 +124,7 @@
|
||||
|
||||
|
||||
<!-- 中国行政区域 -->
|
||||
<changeSet author="WangChenChen (generated)" id="1699414053280-1">
|
||||
<changeSet context="platform" author="WangChenChen (generated)" id="1699414053280-1">
|
||||
<createTable remarks="[ 通用 ] 中国行政地区表" tableName="china_area">
|
||||
<column name="area_code" remarks="行政代码 [ 唯一 ]" type="BIGINT UNSIGNED">
|
||||
<constraints nullable="false" primaryKey="true" unique="true"/>
|
||||
@@ -164,7 +164,7 @@
|
||||
|
||||
|
||||
<!--[ 通用 ]全局配置-->
|
||||
<changeSet author="WangChenChen (generated)" id="1699414059273-1">
|
||||
<changeSet context="platform" author="WangChenChen (generated)" id="1699414059273-1">
|
||||
<createTable remarks="[ 通用 ] 参数配置表" tableName="sys_config">
|
||||
<column autoIncrement="true" name="config_id" remarks="参数主键" type="BIGINT">
|
||||
<constraints nullable="false" primaryKey="true"/>
|
||||
@@ -199,7 +199,7 @@
|
||||
|
||||
|
||||
<!--[ 通用 ] 字典类型表-->
|
||||
<changeSet author="WangChenChen (generated)" id="1699412931547-1">
|
||||
<changeSet context="platform" author="WangChenChen (generated)" id="1699412931547-1">
|
||||
<createTable remarks="[ 通用 ] 字典类型表" tableName="sys_dict_type">
|
||||
<column autoIncrement="true" name="type_id" remarks="字典类型 ID" type="BIGINT">
|
||||
<constraints nullable="false" primaryKey="true"/>
|
||||
@@ -231,7 +231,7 @@
|
||||
|
||||
|
||||
<!--[ 通用 ] 字典数据表-->
|
||||
<changeSet author="WangChenChen (generated)" id="1699414089273-1">
|
||||
<changeSet context="platform" author="WangChenChen (generated)" id="1699414089273-1">
|
||||
<createTable remarks="[ 通用 ] 字典数据表" tableName="sys_dict_data">
|
||||
<column autoIncrement="true" name="dict_code" remarks="字典编码" type="BIGINT">
|
||||
<constraints nullable="false" primaryKey="true"/>
|
||||
@@ -269,7 +269,7 @@
|
||||
|
||||
|
||||
<!--[ 通用 ] 菜单权限表-->
|
||||
<changeSet author="WangChenChen (generated)" id="1699414100077-1">
|
||||
<changeSet context="platform" author="WangChenChen (generated)" id="1699414100077-1">
|
||||
<createTable remarks="[ 通用 ] 菜单权限表" tableName="sys_menu">
|
||||
<column autoIncrement="true" name="menu_id" remarks="菜单ID" type="BIGINT">
|
||||
<constraints nullable="false" primaryKey="true"/>
|
||||
@@ -301,7 +301,8 @@
|
||||
<column defaultValueNumeric="1" name="visible" remarks="菜单状态(1.显示 0.隐藏)" type="TINYINT(4)">
|
||||
<constraints nullable="false"/>
|
||||
</column>
|
||||
<column defaultValueNumeric="2" name="target" remarks="0.租户用户 1. 系统用户 2.全部用户" type="TINYINT(4)">
|
||||
<column defaultValueNumeric="2" name="target" remarks="0.租户用户 1. 系统用户 2.全部用户"
|
||||
type="TINYINT(4)">
|
||||
<constraints nullable="false"/>
|
||||
</column>
|
||||
<column defaultValueNumeric="0" name="keep_alive" remarks="保持状态(1.保持 0.不保持)" type="TINYINT(4)">
|
||||
@@ -325,7 +326,7 @@
|
||||
|
||||
|
||||
<!--[ 通用 ] 文件记录表 -->
|
||||
<changeSet author="WangChenChen (generated)" id="1699414106974-1">
|
||||
<changeSet context="platform" author="WangChenChen (generated)" id="1699414106974-1">
|
||||
<createTable remarks="[ 通用 ] 文件记录表" tableName="sys_file_detail">
|
||||
<column name="id" remarks="文件id" type="VARCHAR(32)">
|
||||
<constraints nullable="false" primaryKey="true"/>
|
||||
|
||||
@@ -38,7 +38,8 @@ public class LiquibaseConfig {
|
||||
var liquibase1 = new MultiTenantSpringLiquibase();
|
||||
liquibase1.setDataSource(dataSource);
|
||||
liquibase1.setResourceLoader(new DefaultResourceLoader());
|
||||
liquibase1.setChangeLog(multiTenantProperties.getOtherChangeLog());
|
||||
liquibase1.setChangeLog(multiTenantProperties.getChangeLog());
|
||||
liquibase1.setContexts(multiTenantProperties.getContexts());
|
||||
return liquibase1;
|
||||
}
|
||||
|
||||
|
||||
@@ -27,9 +27,9 @@ public class MultiTenantProperties {
|
||||
private Boolean enable = true;
|
||||
|
||||
/**
|
||||
* 是否开启租户模式
|
||||
* 是否开启项目模式
|
||||
*/
|
||||
private Boolean enableProject = false;
|
||||
private Boolean enableProject = true;
|
||||
|
||||
/**
|
||||
* 数据库名称前缀
|
||||
@@ -54,16 +54,16 @@ public class MultiTenantProperties {
|
||||
/**
|
||||
* 创建表结构
|
||||
*/
|
||||
private Boolean createTable = Boolean.TRUE;
|
||||
private Boolean createTable = true;
|
||||
|
||||
/**
|
||||
* 其他 数据库 创建表结构的 Liquibase 文件地址
|
||||
* Liquibase contexts
|
||||
*/
|
||||
private String otherChangeLog = "classpath:db/changelog-other.xml";
|
||||
private String contexts = "tenant";
|
||||
|
||||
/**
|
||||
* 主 数据库 创建表结构的 Liquibase 文件地址
|
||||
* Liquibase 创建表结构的 Liquibase 文件地址
|
||||
*/
|
||||
private String masterChangeLog = "classpath:db/changelog-master.xml";
|
||||
private String changeLog = "classpath:db/changelog-master.xml";
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user