go-gorm / sharding

High performance table sharding plugin for Gorm.
MIT License
255 stars 48 forks source link

Use sharding with AutoMigrate failed #142

Open mtcoafun opened 7 months ago

mtcoafun commented 7 months ago

Description

  1. when a dataobject use sharding, and automigrate when connect to Mysql server, it will just appear a tabel, and sharding aljust like this

    ShardingAlgorithm: func(columnValue interface{}) (suffix string, err error) {
    if id, ok := columnValue.(uint); ok {
        return fmt.Sprintf("_%02d", id%shardingNum), nil
    }
    return "", fmt.Errorf("invalid column value type")
    }

    and just migrate table {table_name}_00

  2. when override TableName(), and just like this

    func (d *dataobject) TableName() string {
    return fmt.Sprintf("table_name_%02d", d.ID%shardingNum)
    }

    and just migrate table {table_name}_00 and didnot creat any new table