Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
masseelch committed Jun 15, 2022
1 parent 73492f5 commit d93b55d
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
9 changes: 3 additions & 6 deletions dialect/sql/schema/atlas.go
Expand Up @@ -583,19 +583,16 @@ func (m *Migrate) ensureTypeTable(next Differ) Differ {
if err := m.aColumns(m, et, at); err != nil {
return nil, err
}
if err := m.aIndexes(m, et, at); err != nil {
return nil, err
}
desired.Tables = append(desired.Tables, at)
}
changes, err := next.Diff(current, desired)
if err != nil {
return nil, err
}
if len(m.dbTypeRanges) > 0 && len(m.fileTypeRanges) == 0 {
// Check if all types added by the diff process are present in the "old" types table.
for _, t := range m.typeRanges {
if indexOf(m.dbTypeRanges, t) < 0 {
return nil, fmt.Errorf("unexpected missing type range for %q", t)
}
}
// Override the types file created in the diff process with the "old" allocated types ranges.
if err := m.typeStore.(*dirTypeStore).save(m.dbTypeRanges); err != nil {
return nil, err
Expand Down
13 changes: 10 additions & 3 deletions entc/integration/migrate/migrate_test.go
Expand Up @@ -67,7 +67,10 @@ func TestMySQL(t *testing.T) {
require.NoError(t, err, root.Exec(ctx, "DROP DATABASE IF EXISTS versioned_migrate", []interface{}{}, new(sql.Result)))
require.NoError(t, root.Exec(ctx, "CREATE DATABASE IF NOT EXISTS versioned_migrate", []interface{}{}, new(sql.Result)))
defer root.Exec(ctx, "DROP DATABASE IF EXISTS versioned_migrate", []interface{}{}, new(sql.Result))
Versioned(t, drv, versioned.NewClient(versioned.Driver(drv)))
vdrv, err := sql.Open("mysql", fmt.Sprintf("root:pass@tcp(localhost:%d)/versioned_migrate?parseTime=True", port))
require.NoError(t, err, "connecting to versioned migrate database")
defer vdrv.Close()
Versioned(t, vdrv, versioned.NewClient(versioned.Driver(vdrv)))
})
}
}
Expand Down Expand Up @@ -228,7 +231,11 @@ func Versioned(t *testing.T, drv sql.ExecQuerier, client *versioned.Client) {
template.Must(template.New("name").Parse(`{{ range .Changes }}{{ printf "%s;\n" .Cmd }}{{ end }}`)),
)
require.NoError(t, err)
opts := []schema.MigrateOption{schema.WithDir(dir), schema.WithDeterministicGlobalUniqueID(), schema.WithFormatter(format)}
opts := []schema.MigrateOption{
schema.WithDir(dir),
schema.WithDeterministicGlobalUniqueID(),
schema.WithFormatter(format),
}

// Compared to empty database.
require.NoError(t, client.Schema.NamedDiff(ctx, "first", opts...))
Expand All @@ -242,7 +249,7 @@ func Versioned(t *testing.T, drv sql.ExecQuerier, client *versioned.Client) {
for sc.Scan() {
if sc.Text() != "" {
_, err := drv.ExecContext(ctx, sc.Text())
require.NoError(t, err)
require.NoError(t, err, sc.Text())
}
}
}
Expand Down

0 comments on commit d93b55d

Please sign in to comment.