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

feat: gen multi database #96

Merged
merged 1 commit into from Nov 11, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 3 additions & 3 deletions migrator.go
Expand Up @@ -183,7 +183,7 @@ func (m Migrator) ColumnTypes(value interface{}) ([]gorm.ColumnType, error) {
}
columnTypeSQL += "FROM information_schema.columns WHERE table_schema = ? AND table_name = ? ORDER BY ORDINAL_POSITION"

columns, rowErr := m.DB.Raw(columnTypeSQL, currentDatabase, table).Rows()
columns, rowErr := m.DB.Table(table).Raw(columnTypeSQL, currentDatabase, table).Rows()
if rowErr != nil {
return rowErr
}
Expand Down Expand Up @@ -271,7 +271,7 @@ func (m Migrator) GetIndexes(value interface{}) ([]gorm.Index, error) {

result := make([]*Index, 0)
schema, table := m.CurrentSchema(stmt, stmt.Table)
scanErr := m.DB.Raw(indexSql, schema, table).Scan(&result).Error
scanErr := m.DB.Table(table).Raw(indexSql, schema, table).Scan(&result).Error
if scanErr != nil {
return scanErr
}
Expand Down Expand Up @@ -322,7 +322,7 @@ func (m Migrator) CurrentSchema(stmt *gorm.Statement, table string) (string, str
return tables[0], tables[1]
}
}

m.DB = m.DB.Table(table)
return m.CurrentDatabase(), table
}

Expand Down