diff --git a/core/rootvalue.go b/core/rootvalue.go index d939ecd623..8c2f5ce402 100644 --- a/core/rootvalue.go +++ b/core/rootvalue.go @@ -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() diff --git a/go.mod b/go.mod index dff484662a..7dd7915316 100644 --- a/go.mod +++ b/go.mod @@ -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 diff --git a/go.sum b/go.sum index 6eec183f06..a8e1ca337f 100644 --- a/go.sum +++ b/go.sum @@ -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= @@ -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= @@ -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= diff --git a/testing/go/dolt_functions_test.go b/testing/go/dolt_functions_test.go index 533be8a30a..8575c663af 100755 --- a/testing/go/dolt_functions_test.go +++ b/testing/go/dolt_functions_test.go @@ -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"}, }, }, }, diff --git a/testing/go/schemas_test.go b/testing/go/schemas_test.go index b1a6bb3d2b..a4b52c68f3 100755 --- a/testing/go/schemas_test.go +++ b/testing/go/schemas_test.go @@ -483,10 +483,9 @@ 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", }, @@ -494,6 +493,9 @@ var SchemaTests = []ScriptTest{ { 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{ @@ -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;", @@ -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';", diff --git a/testing/postgres-client-tests/java/PostgresTest.java b/testing/postgres-client-tests/java/PostgresTest.java index 97a92760fe..bc53e481e2 100644 --- a/testing/postgres-client-tests/java/PostgresTest.java +++ b/testing/postgres-client-tests/java/PostgresTest.java @@ -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) { diff --git a/testing/postgres-client-tests/node/index.js b/testing/postgres-client-tests/node/index.js index 404416242d..0fe4bbd6a9 100644 --- a/testing/postgres-client-tests/node/index.js +++ b/testing/postgres-client-tests/node/index.js @@ -126,7 +126,7 @@ const tests = [ command: "SELECT", rowCount: 1, oid: null, - rows: [{ count: "2" }], + rows: [{ count: "3" }], fields: [ { name: "count", @@ -214,7 +214,7 @@ const tests = [ command: "SELECT", rowCount: 1, oid: null, - rows: [{ count: "3" }], + rows: [{ count: "4" }], fields: [ { name: "count",