Skip to content

Commit

Permalink
Merge pull request #694 from dolthub/zachmu/commit-schemas
Browse files Browse the repository at this point in the history
Tests for version control operations on new schemas / tables in new schemas
  • Loading branch information
zachmu committed Sep 11, 2024
2 parents 6f18975 + 2aa7d02 commit 9c98006
Show file tree
Hide file tree
Showing 7 changed files with 202 additions and 30 deletions.
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
6 changes: 3 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ 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.20240911224757-01bd3404af99
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
github.com/dolthub/go-mysql-server v0.18.2-0.20240910184443-01d3c5f0e2b9
github.com/dolthub/sqllogictest/go v0.0.0-20240618184124-ca47f9354216
github.com/dolthub/vitess v0.0.0-20240807181005-71d735078e24
github.com/dolthub/vitess v0.0.0-20240910182452-9291457d0a98
github.com/fatih/color v1.13.0
github.com/goccy/go-json v0.10.2
github.com/gogo/protobuf v1.3.2
Expand Down
12 changes: 6 additions & 6 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.20240911224757-01bd3404af99 h1:OlepJCBrG9z1esN3WmOhGn3dISwG791YOMspOOKcROw=
github.com/dolthub/dolt/go v0.40.5-0.20240911224757-01bd3404af99/go.mod h1:kvgmqrHyCZyBMO5sOeQQloIpslPQ1JlufMhHy7ig7c4=
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-20230524105445-af7e7991c97e h1:kPsT4a47cw1+y/N5SSCkma7FhAPw7KeGmD6c9PBZW9Y=
github.com/dolthub/go-icu-regex v0.0.0-20230524105445-af7e7991c97e/go.mod h1:KPUcpx070QOfJK1gNe0zx4pA5sicIK1GMikIGLKC168=
github.com/dolthub/go-mysql-server v0.18.2-0.20240910155935-794fc14e9d02 h1:MNfPsg9Lt2R07nM1sAeScVKx5Bw/sKPmS0Ek73IwoZw=
github.com/dolthub/go-mysql-server v0.18.2-0.20240910155935-794fc14e9d02/go.mod h1:nbdOzd0ceWONE80vbfwoRBjut7z3CIj69ZgDF/cKuaA=
github.com/dolthub/go-mysql-server v0.18.2-0.20240910184443-01d3c5f0e2b9 h1:gD3dWoUy8W1JKUAhJV6BdvKtA7GDAFL6uynPLmKu6Z0=
github.com/dolthub/go-mysql-server v0.18.2-0.20240910184443-01d3c5f0e2b9/go.mod h1:qG/flwaEzJaI/ZvwlEZyNljSU9UOO54r1Yhv0GnxNgk=
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 All @@ -238,8 +238,8 @@ github.com/dolthub/sqllogictest/go v0.0.0-20240618184124-ca47f9354216 h1:JWkKRE4
github.com/dolthub/sqllogictest/go v0.0.0-20240618184124-ca47f9354216/go.mod h1:e/FIZVvT2IR53HBCAo41NjqgtEnjMJGKca3Y/dAmZaA=
github.com/dolthub/swiss v0.1.0 h1:EaGQct3AqeP/MjASHLiH6i4TAmgbG/c4rA6a1bzCOPc=
github.com/dolthub/swiss v0.1.0/go.mod h1:BeucyB08Vb1G9tumVN3Vp/pyY4AMUnr9p7Rz7wJ7kAQ=
github.com/dolthub/vitess v0.0.0-20240807181005-71d735078e24 h1:/zCd98CLZURqK85jQ+qRmEMx/dpXz85F1/Et7gqMGkk=
github.com/dolthub/vitess v0.0.0-20240807181005-71d735078e24/go.mod h1:uBvlRluuL+SbEWTCZ68o0xvsdYZER3CEG/35INdzfJM=
github.com/dolthub/vitess v0.0.0-20240910182452-9291457d0a98 h1:f4Y0ZUO3SPsgS88w5X377tYSHVLlA8JzvKbNu2C5uks=
github.com/dolthub/vitess v0.0.0-20240910182452-9291457d0a98/go.mod h1:uBvlRluuL+SbEWTCZ68o0xvsdYZER3CEG/35INdzfJM=
github.com/dustin/go-humanize v0.0.0-20171111073723-bb3d318650d4/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25KnS6fMYU6eOk=
github.com/dustin/go-humanize v1.0.0/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25KnS6fMYU6eOk=
github.com/dustin/go-humanize v1.0.1 h1:GzkhY7T5VNhEkwH0PVJgjz+fX1rhBrR7pRT3mDkpeCY=
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

0 comments on commit 9c98006

Please sign in to comment.