Skip to content

Commit

Permalink
dialect/sql/schema: prefix sqlite unique indexes with table name (#2433)
Browse files Browse the repository at this point in the history
Fixed #2421
  • Loading branch information
a8m committed Mar 28, 2022
1 parent 92ff734 commit 317594e
Show file tree
Hide file tree
Showing 16 changed files with 715 additions and 11 deletions.
6 changes: 3 additions & 3 deletions dialect/sql/schema/sqlite.go
Expand Up @@ -408,15 +408,15 @@ func (d *SQLite) atTypeC(c1 *Column, c2 *schema.Column) error {

func (d *SQLite) atUniqueC(t1 *Table, c1 *Column, t2 *schema.Table, c2 *schema.Column) {
// For UNIQUE columns, SQLite create an implicit index named
// "sqlite_autoindex_<table>_<i>". Ent uses the MySQL approach
// in its migration, and name these indexes as the columns.
// "sqlite_autoindex_<table>_<i>". Ent uses the PostgreSQL approach
// in its migration, and name these indexes as "<table>_<column>_key".
for _, idx := range t1.Indexes {
// Index also defined explicitly, and will be add in atIndexes.
if idx.Unique && d.atImplicitIndexName(idx, t1, c1) {
return
}
}
t2.AddIndexes(schema.NewUniqueIndex(c1.Name).AddColumns(c2))
t2.AddIndexes(schema.NewUniqueIndex(fmt.Sprintf("%s_%s_key", t2.Name, c1.Name)).AddColumns(c2))
}

func (d *SQLite) atImplicitIndexName(idx *Index, t1 *Table, c1 *Column) bool {
Expand Down
14 changes: 13 additions & 1 deletion entc/integration/migrate/entv2/car.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions entc/integration/migrate/entv2/car/car.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

132 changes: 132 additions & 0 deletions entc/integration/migrate/entv2/car/where.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 22 additions & 0 deletions entc/integration/migrate/entv2/car_create.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 24 additions & 0 deletions entc/integration/migrate/entv2/car_query.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

66 changes: 66 additions & 0 deletions entc/integration/migrate/entv2/car_update.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 317594e

Please sign in to comment.