server:
  port: 8080
  tomcat:
    uri-encoding: UTF-8

spring:
  application:
    name: boot-shard
  # 分库分表配置
  shardingsphere:
    datasource:
      # 默认数据源
      sharding:
        default-data-source-name: db_master
      names: db_master,db_0,db_1
      db_master:
        type: com.zaxxer.hikari.HikariDataSource
        driver-class-name: com.mysql.cj.jdbc.Driver
        jdbc-url: jdbc:mysql://localhost:3306/shard_db?useUnicode=true&characterEncoding=UTF8&zeroDateTimeBehavior=convertToNull&useSSL=true
        username: root
        password: 123456
      db_0:
        type: com.zaxxer.hikari.HikariDataSource
        driver-class-name: com.mysql.cj.jdbc.Driver
        jdbc-url: jdbc:mysql://localhost:3306/shard_db_0?useUnicode=true&characterEncoding=UTF8&zeroDateTimeBehavior=convertToNull&useSSL=true
        username: root
        password: 123456
      db_1:
        type: com.zaxxer.hikari.HikariDataSource
        driver-class-name: com.mysql.cj.jdbc.Driver
        jdbc-url: jdbc:mysql://localhost:3306/shard_db_1?useUnicode=true&characterEncoding=UTF8&zeroDateTimeBehavior=convertToNull&useSSL=true
        username: root
        password: 123456
    rules:
      sharding:
        tables:
          # tb_order逻辑
          tb_order:
            actual-data-nodes: db_${0..1}.tb_order_${0..2}
            # tb_order库路由
            database-strategy:
              standard:
                sharding-column: order_id
                sharding-algorithm-name: database_inline
            # tb_order表路由
            table-strategy:
              standard:
                sharding-column: order_id
                sharding-algorithm-name: table_inline
        sharding-algorithms:
          # tb_order库路由算法
          database_inline:
            type: INLINE
            props:
              algorithm-expression: db_${order_id % 2}
          # tb_order表路由算法
          table_inline:
            type: INLINE
            props:
              algorithm-expression: tb_order_${order_id % 3}
    props:
      sql-show: true
      sql-comment-parse-enabled: true

# mybatis 配置
mybatis-plus:
    configuration:
        map-underscore-to-camel-case: true
