dataSources:
  ds-0:
    dataSourceClassName: com.zaxxer.hikari.HikariDataSource
    driverClassName: com.mysql.jdbc.Driver
    jdbcUrl: jdbc:mysql://localhost:3306/ds_1?serverTimezone=GMT%2B8&useUnicode=true&characterEncoding=UTF-8
    username: root
    password: apijson
  ds-1:
    dataSourceClassName: com.zaxxer.hikari.HikariDataSource
    driverClassName: com.mysql.jdbc.Driver
    jdbcUrl: jdbc:mysql://localhost:3306/ds_2?serverTimezone=GMT%2B8&useUnicode=true&characterEncoding=UTF-8
    username: root
    password: apijson

rules:
  - !SHARDING
    tables: # Sharding table configuration
      apijson_user:
        actualDataNodes: ds-$->{0..1}.apijson_user  # 分库 shading databases/schemas
        databaseStrategy:
          standard:
            shardingColumn: id
            shardingAlgorithmName: user-sharding-ds
      Moment: # Logic table name
        actualDataNodes: ds-0.Moment_$->{0..1}  # 分表 shading tables
        tableStrategy:
          standard:
            shardingColumn: userId
            shardingAlgorithmName: moment-sharding-table
      Comment: # Logic table name
        actualDataNodes: ds-$->{0..1}.Comment_$->{0..1}  # 分库*分表 shading both databases/schemas and tables
        databaseStrategy:
          standard:
            shardingColumn: userId
            shardingAlgorithmName: comment-sharding-ds
        tableStrategy:
          standard:
            shardingColumn: momentId
            shardingAlgorithmName: comment-sharding-table

    shardingAlgorithms:
      user-sharding-ds:
        type: INLINE
        props:
          algorithm-expression: ds-${id % 2}
      moment-sharding-table:
        type: INLINE
        props:
          algorithm-expression: Moment_${userId % 2}
      comment-sharding-ds:
        type: INLINE
        props:
          algorithm-expression: ds-${userId % 2}
      comment-sharding-table:
        type: INLINE
        props:
          algorithm-expression: Comment_${momentId % 2}
