Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use sharding with AutoMigrate failed #142

Open
mtcoafun opened this issue Dec 14, 2023 · 0 comments
Open

Use sharding with AutoMigrate failed #142

mtcoafun opened this issue Dec 14, 2023 · 0 comments
Assignees

Comments

@mtcoafun
Copy link

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

  1. 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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants