Skip to content

Commit 5c199f0

Browse files
authored
Merge pull request #1643 from ydb-platform/driver-value
Fixed compatibility of propose database/sql driver after drop-in replacement from legacy database/sql driver
2 parents a0ae0f1 + e40553c commit 5c199f0

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

74 files changed

+1412
-723
lines changed

.github/workflows/slo.yml

Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -32,42 +32,42 @@ jobs:
3232
strategy:
3333
matrix:
3434
sdk:
35-
- id: database_sql_legacy
36-
name: database-sql-legacy
37-
path: ./database/sql/legacy
38-
label: database/sql/legacy
39-
- id: database_sql_propose
40-
name: database-sql-propose
41-
path: ./database/sql/propose
42-
label: database/sql/propose
35+
- id: database_sql_table
36+
name: database-sql-table
37+
path: ./database/sql/table
38+
label: database/sql/table
39+
- id: database_sql_query
40+
name: database-sql-query
41+
path: ./database/sql/query
42+
label: database/sql/query
4343
- id: native_query
4444
name: native-query
4545
path: ./native/query
4646
label: native/query
47-
- id: native_table_legacy
48-
name: native-table-legacy
49-
path: ./native/table/legacy
50-
label: native/table/legacy
51-
- id: native_table_propose
52-
name: native-table-propose
53-
path: ./native/table/propose
54-
label: native/table/propose
55-
- id: gorm_legacy
56-
name: gorm-legacy
57-
path: ./gorm/legacy
58-
label: gorm/legacy
59-
- id: gorm_propose
60-
name: gorm-propose
61-
path: ./gorm/propose
62-
label: gorm/propose
63-
- id: xorm_legacy
64-
name: xorm-legacy
65-
path: ./xorm/legacy
66-
label: xorm/legacy
67-
- id: xorm_propose
68-
name: xorm-propose
69-
path: ./xorm/propose
70-
label: xorm/propose
47+
- id: native_table
48+
name: native-table
49+
path: ./native/table
50+
label: native/table
51+
- id: native_table_over_query_service
52+
name: native-table-over-query-service
53+
path: ./native/table/over/query/service
54+
label: native/table/over/query/service
55+
- id: gorm_table
56+
name: gorm-table
57+
path: ./gorm/table
58+
label: gorm/table
59+
- id: gorm_query
60+
name: gorm-query
61+
path: ./gorm/query
62+
label: gorm/query
63+
- id: xorm_table
64+
name: xorm-table
65+
path: ./xorm/table
66+
label: xorm/table
67+
- id: xorm_query
68+
name: xorm-query
69+
path: ./xorm/query
70+
label: xorm/query
7171

7272
concurrency:
7373
group: slo-${{ github.ref }}-${{ matrix.sdk.name }}

dsn_test.go

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ import (
99
"github.com/ydb-platform/ydb-go-sdk/v3/config"
1010
"github.com/ydb-platform/ydb-go-sdk/v3/internal/bind"
1111
"github.com/ydb-platform/ydb-go-sdk/v3/internal/xsql"
12-
"github.com/ydb-platform/ydb-go-sdk/v3/internal/xsql/legacy"
13-
"github.com/ydb-platform/ydb-go-sdk/v3/internal/xsql/propose"
12+
"github.com/ydb-platform/ydb-go-sdk/v3/internal/xsql/xquery"
13+
"github.com/ydb-platform/ydb-go-sdk/v3/internal/xsql/xtable"
1414
)
1515

1616
func TestParse(t *testing.T) {
@@ -26,11 +26,11 @@ func TestParse(t *testing.T) {
2626

2727
return c
2828
}
29-
newLegacyConn := func(opts ...legacy.Option) *legacy.Conn {
30-
return legacy.New(context.Background(), nil, nil, opts...)
29+
newLegacyConn := func(opts ...xtable.Option) *xtable.Conn {
30+
return xtable.New(context.Background(), nil, nil, opts...)
3131
}
32-
newQueryConn := func(opts ...propose.Option) *propose.Conn {
33-
return propose.New(context.Background(), nil, nil, opts...)
32+
newQueryConn := func(opts ...xquery.Option) *xquery.Conn {
33+
return xquery.New(context.Background(), nil, nil, opts...)
3434
}
3535
compareConfigs := func(t *testing.T, lhs, rhs *config.Config) {
3636
require.Equal(t, lhs.Secure(), rhs.Secure())
@@ -71,7 +71,7 @@ func TestParse(t *testing.T) {
7171
config.WithDatabase("/local"),
7272
},
7373
connectorOpts: []xsql.Option{
74-
xsql.WithDefaultQueryMode(legacy.ScriptingQueryMode),
74+
xsql.WithDefaultQueryMode(xtable.ScriptingQueryMode),
7575
},
7676
err: nil,
7777
},
@@ -83,7 +83,7 @@ func TestParse(t *testing.T) {
8383
config.WithDatabase("/local"),
8484
},
8585
connectorOpts: []xsql.Option{
86-
xsql.WithDefaultQueryMode(legacy.ScriptingQueryMode),
86+
xsql.WithDefaultQueryMode(xtable.ScriptingQueryMode),
8787
xsql.WithQueryBind(bind.TablePathPrefix("path/to/tables")),
8888
},
8989
err: nil,
@@ -96,7 +96,7 @@ func TestParse(t *testing.T) {
9696
config.WithDatabase("/local"),
9797
},
9898
connectorOpts: []xsql.Option{
99-
xsql.WithDefaultQueryMode(legacy.ScriptingQueryMode),
99+
xsql.WithDefaultQueryMode(xtable.ScriptingQueryMode),
100100
xsql.WithQueryBind(bind.TablePathPrefix("path/to/tables")),
101101
xsql.WithQueryBind(bind.NumericArgs{}),
102102
},
@@ -110,7 +110,7 @@ func TestParse(t *testing.T) {
110110
config.WithDatabase("/local"),
111111
},
112112
connectorOpts: []xsql.Option{
113-
xsql.WithDefaultQueryMode(legacy.ScriptingQueryMode),
113+
xsql.WithDefaultQueryMode(xtable.ScriptingQueryMode),
114114
xsql.WithQueryBind(bind.TablePathPrefix("path/to/tables")),
115115
xsql.WithQueryBind(bind.PositionalArgs{}),
116116
},
@@ -124,7 +124,7 @@ func TestParse(t *testing.T) {
124124
config.WithDatabase("/local"),
125125
},
126126
connectorOpts: []xsql.Option{
127-
xsql.WithDefaultQueryMode(legacy.ScriptingQueryMode),
127+
xsql.WithDefaultQueryMode(xtable.ScriptingQueryMode),
128128
xsql.WithQueryBind(bind.TablePathPrefix("path/to/tables")),
129129
xsql.WithQueryBind(bind.AutoDeclare{}),
130130
},
@@ -138,7 +138,7 @@ func TestParse(t *testing.T) {
138138
config.WithDatabase("/local"),
139139
},
140140
connectorOpts: []xsql.Option{
141-
xsql.WithDefaultQueryMode(legacy.ScriptingQueryMode),
141+
xsql.WithDefaultQueryMode(xtable.ScriptingQueryMode),
142142
xsql.WithQueryBind(bind.TablePathPrefix("path/to/tables")),
143143
},
144144
err: nil,
@@ -151,7 +151,7 @@ func TestParse(t *testing.T) {
151151
config.WithDatabase("/local"),
152152
},
153153
connectorOpts: []xsql.Option{
154-
xsql.WithDefaultQueryMode(legacy.ScriptingQueryMode),
154+
xsql.WithDefaultQueryMode(xtable.ScriptingQueryMode),
155155
xsql.WithQueryBind(bind.TablePathPrefix("path/to/tables")),
156156
xsql.WithQueryBind(bind.PositionalArgs{}),
157157
xsql.WithQueryBind(bind.AutoDeclare{}),
@@ -183,15 +183,15 @@ func TestParse(t *testing.T) {
183183
exp := newConnector(tt.connectorOpts...)
184184
act := newConnector(d.databaseSQLOptions...)
185185
t.Run("tableOptions", func(t *testing.T) {
186-
require.Equal(t, newLegacyConn(exp.LegacyOpts...), newLegacyConn(act.LegacyOpts...))
186+
require.Equal(t, newLegacyConn(exp.TableOpts...), newLegacyConn(act.TableOpts...))
187187
})
188188
t.Run("queryOptions", func(t *testing.T) {
189-
require.Equal(t, newQueryConn(exp.Options...), newQueryConn(act.Options...))
189+
require.Equal(t, newQueryConn(exp.QueryOpts...), newQueryConn(act.QueryOpts...))
190190
})
191-
exp.LegacyOpts = nil
192-
exp.Options = nil
193-
act.LegacyOpts = nil
194-
act.Options = nil
191+
exp.TableOpts = nil
192+
exp.QueryOpts = nil
193+
act.TableOpts = nil
194+
act.QueryOpts = nil
195195
require.Equal(t, exp.Bindings(), act.Bindings())
196196
require.Equal(t, exp, act)
197197
compareConfigs(t, config.New(tt.opts...), d.config)

examples/migrations/goose/main.go

Lines changed: 39 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"database/sql"
88
"embed"
99
"log"
10+
"net/url"
1011
"os"
1112

1213
"github.com/pressly/goose/v3"
@@ -20,16 +21,18 @@ func main() {
2021
ctx, cancel := context.WithCancel(context.Background())
2122
defer cancel()
2223

23-
nativeDriver, err := ydb.Open(ctx, os.Getenv("YDB_CONNECTION_STRING"))
24+
connectionString := os.Getenv("YDB_CONNECTION_STRING")
25+
26+
nativeDriver, err := ydb.Open(ctx, connectionString)
2427
if err != nil {
2528
panic(err)
2629
}
2730

2831
defer nativeDriver.Close(ctx)
2932

3033
connector, err := ydb.Connector(nativeDriver,
31-
ydb.WithDefaultQueryMode(ydb.ScriptingQueryMode),
32-
ydb.WithFakeTx(ydb.ScriptingQueryMode),
34+
ydb.WithQueryService(true),
35+
ydb.WithFakeTx(ydb.QueryExecuteQueryMode),
3336
ydb.WithAutoDeclare(),
3437
ydb.WithNumericArgs(),
3538
)
@@ -46,9 +49,40 @@ func main() {
4649
panic(err)
4750
}
4851

49-
for _, command := range []string{"status", "up", "status"} {
52+
dsn := func() string {
53+
dsn, err := url.Parse(connectionString)
54+
if err != nil {
55+
panic(err)
56+
}
57+
58+
q := dsn.Query()
59+
q.Set("go_query_mode", "query")
60+
q.Set("go_fake_tx", "query")
61+
q.Set("go_query_bind", "declare")
62+
q.Add("go_query_bind", "numeric")
63+
dsn.RawQuery = q.Encode()
64+
65+
return dsn.String()
66+
}()
67+
68+
for _, command := range []string{
69+
"version",
70+
"up-by-one",
71+
"status",
72+
"up",
73+
"status",
74+
"version",
75+
"down",
76+
"version",
77+
"down",
78+
"version",
79+
"reset",
80+
"version",
81+
"status",
82+
} {
83+
log.Printf("try to run command `goose ydb \"%s\" %s`...", dsn, command)
5084
if err := goose.RunContext(ctx, command, db, "schema"); err != nil {
51-
log.Fatalf("goose %v: %v", "", err)
85+
log.Fatalf("goose %v: %v", command, err)
5286
}
5387
}
5488
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
-- +goose Up
2+
CREATE TABLE `goose/orders` (
3+
id String,
4+
doc String,
5+
PRIMARY KEY(id)
6+
);
7+
8+
CREATE TABLE `goose/events` (
9+
id String,
10+
name Utf8,
11+
service String,
12+
channel Int64,
13+
created Timestamp,
14+
state Json,
15+
INDEX sample_index GLOBAL ON (service, channel, created),
16+
PRIMARY KEY(id, name)
17+
);
18+
19+
-- +goose Down
20+
DROP TABLE `goose/events`;
21+
DROP TABLE `goose/orders`;
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
-- +goose Up
2+
CREATE TABLE `goose/records` (
3+
id Utf8,
4+
name Utf8,
5+
str String,
6+
num Uint64,
7+
PRIMARY KEY(id, name)
8+
);
9+
10+
ALTER TABLE `goose/records` ADD CHANGEFEED `changefeed` WITH (
11+
FORMAT = 'JSON',
12+
MODE = 'NEW_AND_OLD_IMAGES'
13+
);
14+
15+
-- ALTER TOPIC `goose/records/changefeed` ADD CONSUMER `sample-consumer`;
16+
17+
-- +goose Down
18+
-- ALTER TOPIC `goose/records/changefeed` DROP CONSUMER `sample-consumer`;
19+
ALTER TABLE `goose/records` DROP CHANGEFEED `changefeed`;
20+
DROP TABLE `goose/records`;
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
-- +goose Up
2+
CREATE TABLE `goose/tbl_with_pk_uuid` (
3+
id Uuid,
4+
value Double,
5+
PRIMARY KEY(id)
6+
);
7+
UPSERT INTO `goose/tbl_with_pk_uuid` (id, value) VALUES (CAST('00000000-0000-0000-0000-000000000001' AS Uuid), 1.0);
8+
9+
-- +goose Down
10+
DELETE FROM `goose/tbl_with_pk_uuid` WHERE id=CAST('00000000-0000-0000-0000-000000000001' AS Uuid);
11+
DROP TABLE `goose/tbl_with_pk_uuid`;

internal/node/id.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package node
2+
3+
type ID interface {
4+
NodeID() uint32
5+
}

internal/pool/pool.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111

1212
"github.com/ydb-platform/ydb-go-sdk/v3/internal/closer"
1313
"github.com/ydb-platform/ydb-go-sdk/v3/internal/endpoint"
14+
"github.com/ydb-platform/ydb-go-sdk/v3/internal/node"
1415
"github.com/ydb-platform/ydb-go-sdk/v3/internal/stack"
1516
"github.com/ydb-platform/ydb-go-sdk/v3/internal/xcontext"
1617
"github.com/ydb-platform/ydb-go-sdk/v3/internal/xerrors"
@@ -22,9 +23,9 @@ import (
2223
type (
2324
Item interface {
2425
closer.Closer
26+
node.ID
2527

2628
IsAlive() bool
27-
NodeID() uint32
2829
}
2930
ItemConstraint[T any] interface {
3031
*T

internal/query/execute_query.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ type executeSettings interface {
2525
ExecMode() options.ExecMode
2626
StatsMode() options.StatsMode
2727
StatsCallback() func(stats stats.QueryStats)
28-
TxControl() *query.TransactionControl
28+
TxControl() options.TxControl
2929
Syntax() options.Syntax
3030
Params() params.Parameters
3131
CallOptions() []grpc.CallOption

0 commit comments

Comments
 (0)