Skip to content

Commit

Permalink
Merge #1418 (#1426)
Browse files Browse the repository at this point in the history
* bug #1417: Fix exclude constraint by name

* Update sql/internal/sqlx/exclude.go

Co-authored-by: Ariel Mashraki <7413593+a8m@users.noreply.github.com>

* Update sql/internal/sqlx/exclude_test.go

Co-authored-by: Ariel Mashraki <7413593+a8m@users.noreply.github.com>

* Revert go.work.sum

* sql/internal/sqlx: fix typo in var names

Co-authored-by: Andrei Miulescu <lusu777@gmail.com>
Co-authored-by: Andrei Miulescu <andreimc@users.noreply.github.com>
  • Loading branch information
3 people authored Jan 25, 2023
1 parent ee7c64c commit dfc5d2d
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
11 changes: 11 additions & 0 deletions sql/internal/sqlx/exclude.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,17 @@ func excludeT(t *schema.Table, pattern string) (err error) {
}
return filepath.Match(pattern, fk.Symbol)
})
t.Attrs, err = filter(t.Attrs, func(a schema.Attr) (bool, error) {
c, ok := a.(*schema.Check)
if !ok {
return false, nil
}
match, err := filepath.Match(pattern, c.Name)
if !match || err != nil {
return false, err
}
return true, nil
})
return
}

Expand Down
10 changes: 10 additions & 0 deletions sql/internal/sqlx/exclude_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,16 @@ func TestExcludeRealm_Tables(t *testing.T) {
require.Empty(t, r.Schemas[2].Tables)
}

func TestExcludeRealm_Checks(t *testing.T) {
r := schema.NewRealm(
schema.New("s1").AddTables(
schema.NewTable("t1").AddChecks(schema.NewCheck().SetName("c1")),
),
)
r, err := ExcludeRealm(r, []string{"s1.t1.c1"})
require.NoError(t, err)
require.Len(t, r.Schemas[0].Tables[0].Attrs, 0)
}
func TestExcludeRealm_Columns(t *testing.T) {
r := schema.NewRealm(
schema.New("s1").AddTables(
Expand Down

0 comments on commit dfc5d2d

Please sign in to comment.