Skip to content

Commit

Permalink
init db version before executing diff (#2440)
Browse files Browse the repository at this point in the history
What's the problem: Under versioned migration on MySQL 8.0, unique string field would be generated as type varchar(191) instead of varchar(255). This is because in generating migration files by NamedDiff(), sqlDialect's init() method is not called. 

Further concern: For init() function, MySQL and Postgres's implementation checks the database version which is what I want. But SQLite's implementation checks the foreign_keys support. So I think there might be a better may to check the database version before doing Diff().
  • Loading branch information
CharlesGe129 committed Apr 6, 2022
1 parent 05246cb commit e463cbc
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions dialect/sql/schema/migrate.go
Expand Up @@ -173,6 +173,9 @@ func (m *Migrate) NamedDiff(ctx context.Context, name string, tables ...*Table)
if m.atlas.dir == nil {
return errors.New("no migration directory given")
}
if err := m.init(ctx, m); err != nil {
return err
}
plan, err := m.atDiff(ctx, m, name, tables...)
if err != nil {
return err
Expand Down

0 comments on commit e463cbc

Please sign in to comment.