#端口号
server.port=561000
#实例名称
spring.application.name= sharding_order
#表示后发现的bean会覆盖之前相同名称的bean
spring.main.allow-bean-definition-overriding=true
#该配置项就是指将带有下划线的表字段映射为驼峰格式的实体类属性
mybatis.configuration.map-underscore-to-camel-case=true

#以下是分片规则配置

##定义数据源
spring.shardingsphere.datasource.names=m1,m2,s1,s2
#------------------------------------------------------------------------
#定义order_db_1数据源主库
spring.shardingsphere.datasource.m1.type=com.alibaba.druid.pool.DruidDataSource
spring.shardingsphere.datasource.m1.driver-class-name =com.mysql.jdbc.Driver
spring.shardingsphere.datasource.m1.url=jdbc:mysql://localhost:3306/order_db_1?useUnicode=true
spring.shardingsphere.datasource.m1.username=root
spring.shardingsphere.datasource.m1.password=root

#定义order_db_1数据源从库
spring.shardingsphere.datasource.s1.type=com.alibaba.druid.pool.DruidDataSource
spring.shardingsphere.datasource.s1.driver-class-name =com.mysql.jdbc.Driver
spring.shardingsphere.datasource.s1.url=jdbc:mysql://localhost:3307/order_db_1?useUnicode=true
spring.shardingsphere.datasource.s1.username=root
spring.shardingsphere.datasource.s1.password=root

#读写分离，主库和从库绑定
spring.shardingsphere.sharding.master-slave-rules.ds1.masterDataSourceName=m1
spring.shardingsphere.sharding.master-slave-rules.ds1.slaveDataSourceNames=s1

#-------------------------------------------------------------------------------------

#定义order_db_2数据源主库
spring.shardingsphere.datasource.m2.type=com.alibaba.druid.pool.DruidDataSource
spring.shardingsphere.datasource.m2.driver-class-name =com.mysql.jdbc.Driver
spring.shardingsphere.datasource.m2.url=jdbc:mysql://localhost:3306/order_db_2?useUnicode=true
spring.shardingsphere.datasource.m2.username=root
spring.shardingsphere.datasource.m2.password=root

#定义order_db_2数据源从库
spring.shardingsphere.datasource.s2.type=com.alibaba.druid.pool.DruidDataSource
spring.shardingsphere.datasource.s2.driver-class-name =com.mysql.jdbc.Driver
spring.shardingsphere.datasource.s2.url=jdbc:mysql://localhost:3307/order_db_2?useUnicode=true
spring.shardingsphere.datasource.s2.username=root
spring.shardingsphere.datasource.s2.password=root

#读写分离，主库和从库绑定
spring.shardingsphere.sharding.master-slave-rules.ds2.masterDataSourceName=m2
spring.shardingsphere.sharding.master-slave-rules.ds2.slaveDataSourceNames=s2


#指定t_order表的数据分布情况，配置数据节点
#spring.shardingsphere.sharding.tables.t_order.actualDataNodes=m$->{1..2}.t_order_$->{1..2}
spring.shardingsphere.sharding.tables.t_order.actualDataNodes=ds$->{1..2}.t_order_$->{1..2}

#指定t_order表的主键生成策略为SNOWFLAKE
spring.shardingsphere.sharding.tables.t_order.keyGenerator.column=order_id
spring.shardingsphere.sharding.tables.t_order.keyGenerator.type=SNOWFLAKE

#t_order分表策略，指定t_order表的分片策略，分片策略包括分片键和分片算法
spring.shardingsphere.sharding.tables.t_order.tableStrategy.inline.shardingColumn=order_id
spring.shardingsphere.sharding.tables.t_order.tableStrategy.inline.algorithmExpression=t_order_$->{order_id % 2+1}

#分库策略，以user_id为分片键，分片策略为user_id%2+1，user_id为偶数操作m1数据源，否则操作m2。
spring.shardingsphere.sharding.tables.t_order.databaseStrategy.inline.shardingColumn=user_id
spring.shardingsphere.sharding.tables.t_order.databaseStrategy.inline.algorithmExpression=ds$->{user_id % 2+1 }

#打开sql输出日志
spring.shardingsphere.props.sql.show=true

#日志级别
logging.level.root=info
logging.level.org.springframework.web=info
logging.level.com.itheima=debug
logging.level.druid.sql=debug
