Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ require (
github.com/PuerkitoBio/goquery v1.8.1
github.com/cockroachdb/apd/v2 v2.0.3-0.20200518165714-d020e156310a
github.com/cockroachdb/errors v1.7.5
github.com/dolthub/dolt/go v0.40.5-0.20241022005459-1290f6a902c8
github.com/dolthub/dolt/go v0.40.5-0.20241025002354-1bf5606b7e23
github.com/dolthub/dolt/go/gen/proto/dolt/services/eventsapi v0.0.0-20240827111219-e4bb9ca3442d
github.com/dolthub/flatbuffers/v23 v23.3.3-dh.2
github.com/dolthub/go-icu-regex v0.0.0-20240916130659-0118adc6b662
github.com/dolthub/go-mysql-server v0.18.2-0.20241022002146-c5725b1bf340
github.com/dolthub/go-mysql-server v0.18.2-0.20241024233927-96a484368bea
github.com/dolthub/sqllogictest/go v0.0.0-20240618184124-ca47f9354216
github.com/dolthub/vitess v0.0.0-20241016191424-d14e107a654e
github.com/fatih/color v1.13.0
Expand Down
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -214,8 +214,8 @@ github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZm
github.com/dgryski/go-farm v0.0.0-20190423205320-6a90982ecee2/go.mod h1:SqUrOPUnsFjfmXRMNPybcSiG0BgUW2AuFH8PAnS2iTw=
github.com/docker/go-connections v0.4.0/go.mod h1:Gbd7IOopHjR8Iph03tsViu4nIes5XhDvyHbTtUxmeec=
github.com/docker/go-units v0.4.0/go.mod h1:fgPhTUdO+D/Jk86RDLlptpiXQzgHJF7gydDDbaIK4Dk=
github.com/dolthub/dolt/go v0.40.5-0.20241022005459-1290f6a902c8 h1:N0V3lAnC7vWscLYDg3ZNVjIYoOJWeQxlOd/kvwBJhIM=
github.com/dolthub/dolt/go v0.40.5-0.20241022005459-1290f6a902c8/go.mod h1:24J7n/VGWEwl5EM8qLBDxaAJBxRt0rraOcoYRBVFIYg=
github.com/dolthub/dolt/go v0.40.5-0.20241025002354-1bf5606b7e23 h1:R/isZppGvXrUIujDnYblRvdfGJxgsNSbnNwG6Bu2BSY=
github.com/dolthub/dolt/go v0.40.5-0.20241025002354-1bf5606b7e23/go.mod h1:Dlf8rNaNwRfW+RRcsGxDxxpkwB616hrh5Gqr2YJGQOg=
github.com/dolthub/dolt/go/gen/proto/dolt/services/eventsapi v0.0.0-20240827111219-e4bb9ca3442d h1:RZkQeYOrDrOWzCxaP2ttkvg4E2TM9n8lnEsIBLKjqkM=
github.com/dolthub/dolt/go/gen/proto/dolt/services/eventsapi v0.0.0-20240827111219-e4bb9ca3442d/go.mod h1:L5RDYZbC9BBWmoU2+TjTekeqqhFXX5EqH9ln00O0stY=
github.com/dolthub/flatbuffers/v23 v23.3.3-dh.2 h1:u3PMzfF8RkKd3lB9pZ2bfn0qEG+1Gms9599cr0REMww=
Expand All @@ -224,8 +224,8 @@ github.com/dolthub/fslock v0.0.3 h1:iLMpUIvJKMKm92+N1fmHVdxJP5NdyDK5bK7z7Ba2s2U=
github.com/dolthub/fslock v0.0.3/go.mod h1:QWql+P17oAAMLnL4HGB5tiovtDuAjdDTPbuqx7bYfa0=
github.com/dolthub/go-icu-regex v0.0.0-20240916130659-0118adc6b662 h1:aC17hZD6iwzBwwfO5M+3oBT5E5gGRiQPdn+vzpDXqIA=
github.com/dolthub/go-icu-regex v0.0.0-20240916130659-0118adc6b662/go.mod h1:KPUcpx070QOfJK1gNe0zx4pA5sicIK1GMikIGLKC168=
github.com/dolthub/go-mysql-server v0.18.2-0.20241022002146-c5725b1bf340 h1:OJkZTo67Ikm6Tz6ml4Mn9qbC6he49X9dZfYqIwaZrNM=
github.com/dolthub/go-mysql-server v0.18.2-0.20241022002146-c5725b1bf340/go.mod h1:z/GGuH2asedC+lkJA4sx+C3oyRH1HRx8ET6N9AGBVms=
github.com/dolthub/go-mysql-server v0.18.2-0.20241024233927-96a484368bea h1:bqHfelpj4LTC4RQnnFeC8KiXda90E0YfG0Elg5AqV0w=
github.com/dolthub/go-mysql-server v0.18.2-0.20241024233927-96a484368bea/go.mod h1:z/GGuH2asedC+lkJA4sx+C3oyRH1HRx8ET6N9AGBVms=
github.com/dolthub/gozstd v0.0.0-20240423170813-23a2903bca63 h1:OAsXLAPL4du6tfbBgK0xXHZkOlos63RdKYS3Sgw/dfI=
github.com/dolthub/gozstd v0.0.0-20240423170813-23a2903bca63/go.mod h1:lV7lUeuDhH5thVGDCKXbatwKy2KW80L4rMT46n+Y2/Q=
github.com/dolthub/ishell v0.0.0-20240701202509-2b217167d718 h1:lT7hE5k+0nkBdj/1UOSFwjWpNxf+LCApbRHgnCA17XE=
Expand Down
237 changes: 230 additions & 7 deletions testing/go/foreign_keys_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,13 +134,66 @@ func TestForeignKeys(t *testing.T) {
},
{
Name: "foreign key in another schema with search path",
Skip: true, // no GMS support for schemas in foreign key defns
SetUpScript: []string{
"create schema parent",
"create schema child",
"create schema fake",
"call dolt_commit('-Am', 'create schemas')",
"set search_path to 'parent, child'",
"create table parent.parent (pk int, \"value\" int, primary key(pk));",
`create table parent.parent (pk int, val int, primary key(pk));`,
`create table fake.parent (pk int, val int, primary key(pk));`,
"CREATE TABLE child.child (id int, info varchar(255), test_pk int, primary key(id), foreign key (test_pk) references parent(pk))",
"INSERT INTO parent VALUES (0, 0), (1, 1), (2,2)",
"SELECT DOLT_ADD('.')",
},
Assertions: []ScriptTestAssertion{
{
Query: "SELECT * FROM dolt_status",
Expected: []sql.Row{
{"child.child", 1, "new table"},
{"fake.parent", 1, "new table"},
{"parent.parent", 1, "new table"},
},
},
{
Query: "SELECT dolt_commit('-am', 'new tables')",
SkipResultsCheck: true,
},
{
Query: "SELECT * FROM dolt_status",
Expected: []sql.Row{},
},
{
Query: "SELECT * FROM dolt_schema_diff('HEAD', 'WORKING', 'child')",
Expected: []sql.Row{},
},
{
Query: "INSERT INTO child VALUES (2, 'two', 2)",
Expected: []sql.Row{},
},
{
Query: "INSERT INTO child VALUES (3, 'three', 3)",
ExpectedErr: "Foreign key violation",
},
{
Query: "SELECT * FROM child.child",
Expected: []sql.Row{
{2, "two", 2},
},
},
},
},
{
Name: "foreign key in another schema with search path, parent table not on search path",
SetUpScript: []string{
"create schema parent",
"create schema child",
"create schema fake",
"call dolt_commit('-Am', 'create schemas')",
"set search_path to 'child, fake'",
`create table parent.parent (pk int, val int, primary key(pk));`,
`create table fake.parent (pk int, val int, primary key(pk));`,
"CREATE TABLE child.child (id int, info varchar(255), test_pk int, primary key(id), foreign key (test_pk) references parent.parent(pk))",
"INSERT INTO parent.parent VALUES (0, 0), (1, 1), (2,2)",
"SELECT DOLT_ADD('.')",
},
Expand All @@ -149,6 +202,7 @@ func TestForeignKeys(t *testing.T) {
Query: "SELECT * FROM dolt_status",
Expected: []sql.Row{
{"child.child", 1, "new table"},
{"fake.parent", 1, "new table"},
{"parent.parent", 1, "new table"},
},
},
Expand All @@ -165,11 +219,11 @@ func TestForeignKeys(t *testing.T) {
Expected: []sql.Row{},
},
{
Query: "INSERT INTO child.child VALUES (2, 'two', 2)",
Query: "INSERT INTO child VALUES (2, 'two', 2)",
Expected: []sql.Row{},
},
{
Query: "INSERT INTO child.child VALUES (3, 'three', 3)",
Query: "INSERT INTO child VALUES (3, 'three', 3)",
ExpectedErr: "Foreign key violation",
},
{
Expand All @@ -181,12 +235,14 @@ func TestForeignKeys(t *testing.T) {
},
},
{
Name: "foreign key in another schema",
Skip: true, // no GMS support for schemas in foreign key defns
Name: "foreign key in another schema, no search path",
SetUpScript: []string{
"create schema parent",
"create schema child",
"create table parent.parent (pk int, \"value\" int, primary key(pk));",
"create schema fake",
"call dolt_commit('-Am', 'create schemas')",
`create table parent.parent (pk int, val int, primary key(pk));`,
`create table fake.parent (pk int, val int, primary key(pk));`,
"CREATE TABLE child.child (id int, info varchar(255), test_pk int, primary key(id), foreign key (test_pk) references parent.parent(pk))",
"INSERT INTO parent.parent VALUES (0, 0), (1, 1), (2,2)",
"SELECT DOLT_ADD('.')",
Expand All @@ -196,6 +252,7 @@ func TestForeignKeys(t *testing.T) {
Query: "SELECT * FROM dolt_status",
Expected: []sql.Row{
{"child.child", 1, "new table"},
{"fake.parent", 1, "new table"},
{"parent.parent", 1, "new table"},
},
},
Expand Down Expand Up @@ -227,6 +284,172 @@ func TestForeignKeys(t *testing.T) {
},
},
},
{
Name: "add foreign key in another schema on search path",
SetUpScript: []string{
"create schema parent",
"create schema child",
"create schema fake",
"call dolt_commit('-Am', 'create schemas')",
"set search_path to 'child, parent'",
`create table parent.parent (pk int, val int, primary key(pk));`,
`create table fake.parent (pk int, val int, primary key(pk));`,
"CREATE TABLE child.child (id int, info varchar(255), test_pk int, primary key(id))",
"INSERT INTO parent.parent VALUES (0, 0), (1, 1), (2,2)",
"SELECT DOLT_COMMIT('-Am', 'new tables')",
},
Assertions: []ScriptTestAssertion{
{
Query: "INSERT INTO child.child VALUES (2, 'two', 2)",
Expected: []sql.Row{},
},
{
Query: "ALTER TABLE child ADD FOREIGN KEY (test_pk) REFERENCES parent(pk)",
SkipResultsCheck: true,
},
{
Query: "INSERT INTO child VALUES (3, 'three', 3)",
ExpectedErr: "Foreign key violation",
},
{
Query: "SELECT * FROM child",
Expected: []sql.Row{
{2, "two", 2},
},
},
},
},
{
Name: "add foreign key in another schema, parent table not on search path",
SetUpScript: []string{
"create schema parent",
"create schema child",
"create schema fake",
"call dolt_commit('-Am', 'create schemas')",
"set search_path to 'child, fake'",
`create table parent.parent (pk int, val int, primary key(pk));`,
`create table fake.parent (pk int, val int, primary key(pk));`,
"CREATE TABLE child.child (id int, info varchar(255), test_pk int, primary key(id))",
"INSERT INTO parent.parent VALUES (0, 0), (1, 1), (2,2)",
"SELECT DOLT_COMMIT('-Am', 'new tables')",
},
Assertions: []ScriptTestAssertion{
{
Query: "INSERT INTO child.child VALUES (2, 'two', 2)",
Expected: []sql.Row{},
},
{
Query: "ALTER TABLE child ADD FOREIGN KEY (test_pk) REFERENCES parent.parent(pk)",
SkipResultsCheck: true,
},
{
Query: "INSERT INTO child VALUES (3, 'three', 3)",
ExpectedErr: "Foreign key violation",
},
{
Query: "SELECT * FROM child",
Expected: []sql.Row{
{2, "two", 2},
},
},
},
},
{
Name: "add foreign key in another schema, no search path",
SetUpScript: []string{
"create schema parent",
"create schema child",
"create schema fake",
"call dolt_commit('-Am', 'create schemas')",
`create table parent.parent (pk int, val int, primary key(pk));`,
`create table fake.parent (pk int, val int, primary key(pk));`,
"CREATE TABLE child.child (id int, info varchar(255), test_pk int, primary key(id))",
"INSERT INTO parent.parent VALUES (0, 0), (1, 1), (2,2)",
"SELECT DOLT_COMMIT('-Am', 'new tables')",
},
Assertions: []ScriptTestAssertion{
{
Query: "INSERT INTO child.child VALUES (2, 'two', 2)",
Expected: []sql.Row{},
},
{
Query: "ALTER TABLE child.child ADD FOREIGN KEY (test_pk) REFERENCES parent.parent(pk)",
SkipResultsCheck: true,
},
{
Query: "INSERT INTO child.child VALUES (3, 'three', 3)",
ExpectedErr: "Foreign key violation",
},
{
Query: "SELECT * FROM child.child",
Expected: []sql.Row{
{2, "two", 2},
},
},
},
},
{
Name: "drop foreign key in another schema, on search path",
SetUpScript: []string{
"create schema parent",
"create schema child",
"create schema fake",
"call dolt_commit('-Am', 'create schemas')",
"set search_path to 'child, parent'",
`create table parent.parent (pk int, val int, primary key(pk));`,
`create table fake.parent (pk int, val int, primary key(pk));`,
"CREATE TABLE child.child (id int, info varchar(255), test_pk int, primary key(id))",
"INSERT INTO parent.parent VALUES (0, 0), (1, 1), (2,2)",
"SELECT DOLT_COMMIT('-Am', 'new tables')",
"INSERT INTO child.child VALUES (2, 'two', 2)",
"ALTER TABLE child.child ADD FOREIGN KEY (test_pk) REFERENCES parent(pk)",
},
Assertions: []ScriptTestAssertion{
{
Query: "INSERT INTO child.child VALUES (3, 'three', 3)",
ExpectedErr: "Foreign key violation",
},
{
Query: "alter table child DROP constraint child_ibfk_1",
SkipResultsCheck: true,
},
{
Query: "INSERT INTO child.child VALUES (3, 'three', 3)",
Expected: []sql.Row{},
},
},
},
{
Name: "drop foreign key in another schema, no search path",
Skip: true, // not getting the explicit schema name passed to the node
SetUpScript: []string{
"create schema parent",
"create schema child",
"create schema fake",
"call dolt_commit('-Am', 'create schemas')",
`create table parent.parent (pk int, val int, primary key(pk));`,
`create table fake.parent (pk int, val int, primary key(pk));`,
"CREATE TABLE child.child (id int, info varchar(255), test_pk int, primary key(id))",
"INSERT INTO parent.parent VALUES (0, 0), (1, 1), (2,2)",
"SELECT DOLT_COMMIT('-Am', 'new tables')",
"INSERT INTO child.child VALUES (2, 'two', 2)",
"ALTER TABLE child.child ADD FOREIGN KEY (test_pk) REFERENCES parent.parent(pk)",
},
Assertions: []ScriptTestAssertion{
{
Query: "INSERT INTO child.child VALUES (3, 'three', 3)",
ExpectedErr: "Foreign key violation",
},
{
Query: "alter table child.child DROP constraint child_ibfk_1",
SkipResultsCheck: true,
},
{
Query: "INSERT INTO child.child VALUES (3, 'three', 3)",
Expected: []sql.Row{},
},
},
},
},
)
}
Loading