Skip to content

Commit

Permalink
CheckSchema: unique vs unique index improvement
Browse files Browse the repository at this point in the history
  • Loading branch information
kataras committed Sep 19, 2023
1 parent ca8162d commit 8888b82
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 9 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:

services:
postgres:
image: postgres:15-alpine
image: postgres:16-alpine
env:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: admin!123
Expand Down
1 change: 1 addition & 0 deletions db_information.go
Original file line number Diff line number Diff line change
Expand Up @@ -469,6 +469,7 @@ func (db *DB) ListColumns(ctx context.Context, tableNames ...string) ([]*desc.Co
if uniqueIndex.TableName == column.TableName {
for _, columnName := range uniqueIndex.Columns {
if columnName == column.Name {
column.Unique = false
column.UniqueIndex = uniqueIndex.IndexName
break uniqueIndexLoop
}
Expand Down
2 changes: 1 addition & 1 deletion db_information_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
)

// This should match the CI's postgres version.
const expectedDBVersion = "15"
const expectedDBVersion = "16.0"

func TestInformation_GetVersion(t *testing.T) {
db, err := openEmptyTestConnection()
Expand Down
14 changes: 7 additions & 7 deletions desc/constraint.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,13 +125,13 @@ func (c *Constraint) BuildColumn(column *Column) error {
case PrimaryKeyConstraintType:
column.PrimaryKey = true
case UniqueConstraintType:
// if len(c.Unique.Columns) == 0 {
// // simple unique to itself.
// column.Unique = true
// } else {
// column.UniqueIndex = c.ConstraintName
// }
column.Unique = true
if len(c.Unique.Columns) == 0 || (len(c.Unique.Columns) == 1 && c.Unique.Columns[0] == c.ColumnName) {
// simple unique to itself.
column.Unique = true
} else {
column.UniqueIndex = c.ConstraintName
}
// column.Unique = true
case CheckConstraintType:
column.CheckConstraint = c.Check.Expression
case ForeignKeyConstraintType:
Expand Down

0 comments on commit 8888b82

Please sign in to comment.