Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tests for version control operations on new schemas / tables in new schemas #694

Merged
merged 17 commits into from
Sep 11, 2024
11 changes: 11 additions & 0 deletions core/rootvalue.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,17 @@ func (root *RootValue) DebugString(ctx context.Context, transitive bool) string

return false, nil
})

buf.WriteString("\nSchemas:")
schemas, err := root.GetDatabaseSchemas(ctx)
if err != nil {
return ""
}

for _, schema := range schemas {
buf.WriteString("\nSchema ")
buf.WriteString(schema.Name)
}
}

return buf.String()
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ 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.20240910164014-9450b292cecb
github.com/dolthub/dolt/go v0.40.5-0.20240911010519-635952ea8b02
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-mysql-server v0.18.2-0.20240910155935-794fc14e9d02
Expand Down
4 changes: 2 additions & 2 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.20240910164014-9450b292cecb h1:s60+aSIc9g8NqlMr4kkUjwTSeuoO5Eq43i5m540+UOs=
github.com/dolthub/dolt/go v0.40.5-0.20240910164014-9450b292cecb/go.mod h1:g+p8vcX/PJxVQ6cXMWkkhmI6KoEMgV+u/ar4/kg79XM=
github.com/dolthub/dolt/go v0.40.5-0.20240911010519-635952ea8b02 h1:70dp7RdTnR5yIOGsey/6lr+VjAgjqlTpBgPUdWcI1/Y=
github.com/dolthub/dolt/go v0.40.5-0.20240911010519-635952ea8b02/go.mod h1:v8Ja5if8o9f5HbX6rf34elmMM61x7EQHktCzcBmLfdE=
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 Down
6 changes: 3 additions & 3 deletions testing/go/dolt_functions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,19 +35,19 @@ func TestDoltFunctions(t *testing.T) {
},
},
{
Query: "select dolt_commit('-am', 'initial commit')",
Query: "select dolt_commit('-am', 'new table')",
SkipResultsCheck: true,
},
{
Query: "select count(*) from dolt_log",
Expected: []sql.Row{
{2},
{3}, // initial commit, CREATE DATABASE commit, CREATE TABLE commit
},
},
{
Query: "select message from dolt_log order by date desc limit 1",
Expected: []sql.Row{
{"initial commit"},
{"new table"},
},
},
},
Expand Down
189 changes: 175 additions & 14 deletions testing/go/schemas_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -483,17 +483,19 @@ var SchemaTests = []ScriptTest{
},
{
Name: "create new database and new schema",
Skip: true,
SetUpScript: []string{
"CREATE DATABASE db2;",
"USE db2;", // TODO: not a real postgres statement
"USE db2;",
"create schema schema2;",
"use postgres",
},
Assertions: []ScriptTestAssertion{
{
Query: "CREATE TABLE db2.schema2.test (pk BIGINT PRIMARY KEY, v1 BIGINT);",
},
{
Query: "INSERT INTO db2.schema2.test VALUES (1, 1), (2, 2);",
},
{
Query: "SELECT * FROM db2.schema2.test;",
Expected: []sql.Row{
Expand Down Expand Up @@ -543,9 +545,162 @@ var SchemaTests = []ScriptTest{
},
},
{
Name: "with branches", // TODO: Use `use db/branch` instead of dolt_checkout for these tests
Name: "add new table in new schema, commit, status",
SetUpScript: []string{
"CREATE SCHEMA myschema",
"Create table myschema.mytbl (pk BIGINT PRIMARY KEY, v1 BIGINT);",
},
Assertions: []ScriptTestAssertion{
{
Query: "SELECT * FROM dolt_status;",
Expected: []sql.Row{
{"mytbl", 0, "new table"},
{"myschema", 0, "new schema"},
},
},
{
Query: "select dolt_add('.')",
Expected: []sql.Row{
{"{0}"},
},
},
{
Query: "SELECT * FROM dolt_status;",
Expected: []sql.Row{
{"mytbl", 1, "new table"},
{"myschema", 1, "new schema"},
},
},
{
Query: "select dolt_commit('-m', 'new table in new schema')",
SkipResultsCheck: true,
},
{
Query: "SELECT * FROM dolt_status;",
Expected: []sql.Row{},
},
{
Query: "select message from dolt_log order by date desc limit 1",
Expected: []sql.Row{
{"new table in new schema"},
},
},
},
},
{
Name: "add new table in new schema, commit -Am",
SetUpScript: []string{
"CREATE SCHEMA myschema",
"Create table myschema.mytbl (pk BIGINT PRIMARY KEY, v1 BIGINT);",
},
Assertions: []ScriptTestAssertion{
{
Query: "SELECT * FROM dolt_status;",
Expected: []sql.Row{
{"mytbl", 0, "new table"},
{"myschema", 0, "new schema"},
},
},
{
Query: "select dolt_commit('-Am', 'new table in new schema')",
SkipResultsCheck: true,
},
{
Query: "SELECT * FROM dolt_status;",
Expected: []sql.Row{},
},
{
Query: "select message from dolt_log order by date desc limit 1",
Expected: []sql.Row{
{"new table in new schema"},
},
},
},
},
{
Name: "merge new table in new schema",
SetUpScript: []string{
"call dolt_checkout('-b', 'branch1')",
"CREATE SCHEMA branchschema",
"Create table branchschema.mytbl (pk BIGINT PRIMARY KEY, v1 BIGINT);",
"INSERT INTO branchschema.mytbl VALUES (1, 1), (2, 2)",
"Create table branchschema.mytbl2 (pk BIGINT PRIMARY KEY, v1 BIGINT);",
"INSERT INTO branchschema.mytbl2 VALUES (3, 3), (4, 4)",
"select dolt_commit('-Am', 'new table in new schema')",
"call dolt_checkout('main')",
"create schema mainschema",
"create table mainschema.maintable (pk BIGINT PRIMARY KEY, v1 BIGINT);",
"insert into mainschema.maintable values (5, 5), (6, 6)",
"select dolt_commit('-Am', 'new table in main')",
},
Assertions: []ScriptTestAssertion{
{
Query: "call dolt_merge('branch1')",
},
{
Query: "SELECT * from mainschema.maintable",
Expected: []sql.Row{
{5, 5},
{6, 6},
},
},
{
Query: "SELECT * from branchschema.mytbl",
Expected: []sql.Row{
{1, 1},
{2, 2},
},
},
{
Query: "SELECT * from branchschema.mytbl2",
Expected: []sql.Row{
{3, 3},
{4, 4},
},
},
},
},
{
Name: "create new schema with no tables, add and commit",
SetUpScript: []string{
"CREATE SCHEMA myschema",
},
Assertions: []ScriptTestAssertion{
{
Query: "SELECT * FROM dolt_status;",
Expected: []sql.Row{{"myschema", 0, "new schema"}},
},
{
Query: "select dolt_add('.')",
Expected: []sql.Row{
{"{0}"},
},
},
{
Query: "SELECT * FROM dolt_status;",
Expected: []sql.Row{{"myschema", 1, "new schema"}},
},
{
Query: "select dolt_commit('-m', 'new schema')",
SkipResultsCheck: true,
},
{
Query: "SELECT * FROM dolt_status;",
Expected: []sql.Row{},
},
{
Query: "select message from dolt_log order by date desc limit 1",
Expected: []sql.Row{
{"new schema"},
},
},
},
},
{
Name: "USE branches",
SetUpScript: []string{
`USE "postgres/main"`,
"CREATE SCHEMA myschema",
"SET search_path = 'myschema'",
"CREATE TABLE mytbl (pk BIGINT PRIMARY KEY, v1 BIGINT);",
"set dolt_show_branch_databases to 1;",
Expand Down Expand Up @@ -602,32 +757,38 @@ var SchemaTests = []ScriptTest{
},
},
{
Query: "SELECT dolt_checkout('-b', 'newbranch')",
Expected: []sql.Row{{"{0,\"Switched to branch 'newbranch'\"}"}},
Query: "SELECT * FROM dolt_status;",
Expected: []sql.Row{
{"mytbl", 0, "new table"},
{"myschema", 0, "new schema"},
},
},
{
Skip: true, // TODO: ERROR: no schema has been selected to create in
Query: "CREATE TABLE mytbl2 (pk BIGINT PRIMARY KEY, v1 BIGINT);",
Expected: []sql.Row{},
Query: "SELECT dolt_commit('-A', '-m', 'Add mytbl');",
SkipResultsCheck: true,
},
{
Query: "CREATE SCHEMA newbranchschema;",
Query: "SELECT * FROM dolt_status;",
Expected: []sql.Row{},
},
{
Query: "SET search_path = 'newbranchschema';",
Expected: []sql.Row{},
Query: "SELECT dolt_branch('newbranch')",
Expected: []sql.Row{{"{0}"}},
},
{
Query: "CREATE TABLE mytbl2 (pk BIGINT PRIMARY KEY, v1 BIGINT);",
Query: "USE 'postgres/newbranch'",
Expected: []sql.Row{},
},
{
Query: "SELECT current_schemas(true)",
Query: "SELECT current_schemas(true);",
Expected: []sql.Row{
{"{pg_catalog,newbranchschema}"},
{"{pg_catalog,myschema}"},
},
},
{
Query: "CREATE TABLE mytbl2 (pk BIGINT PRIMARY KEY, v1 BIGINT);",
Expected: []sql.Row{},
},
{
Skip: true, // TODO: pg_catalog and public are not showing up
Query: "SELECT schema_name FROM information_schema.schemata WHERE catalog_name = 'postgres/newbranch';",
Expand Down
4 changes: 2 additions & 2 deletions testing/postgres-client-tests/java/PostgresTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,13 @@ public String[] getExpectedResults() {
new PostgresTest("select * from test", null, "c1", new String[]{"hi ","hello "}),
new PostgresTest("call dolt_add('-A')", 0, null, null),
new PostgresTest("call dolt_commit('-m', 'my commit')", 0, null, null),
new PostgresTest("select COUNT(*) FROM dolt_log", null, 1, new String[]{"2"}),
new PostgresTest("select COUNT(*) FROM dolt_log", null, 1, new String[]{"3"}),
new PostgresTest("call dolt_checkout('-b', 'mybranch')", 0, null, null),
new PostgresTest("insert into test (pk, value, d1, c1) values (1,1,12.34,'bye')", 1, null, null),
new PostgresTest("call dolt_commit('-a', '-m', 'my commit2')", 0, null, null),
new PostgresTest("call dolt_checkout('main')", 0, null, null),
new PostgresTest("call dolt_merge('mybranch')", 0, null, null),
new PostgresTest("select COUNT(*) FROM dolt_log", null, "COUNT", new String[]{"3"}), // returns res
new PostgresTest("select COUNT(*) FROM dolt_log", null, "COUNT", new String[]{"4"}), // returns res
};

public static void main(String[] args) {
Expand Down
4 changes: 2 additions & 2 deletions testing/postgres-client-tests/node/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ const tests = [
command: "SELECT",
rowCount: 1,
oid: null,
rows: [{ count: "2" }],
rows: [{ count: "3" }],
fields: [
{
name: "count",
Expand Down Expand Up @@ -214,7 +214,7 @@ const tests = [
command: "SELECT",
rowCount: 1,
oid: null,
rows: [{ count: "3" }],
rows: [{ count: "4" }],
fields: [
{
name: "count",
Expand Down
Loading