Skip to content

Commit

Permalink
Merge pull request #1 from ydb-platform/feature/add-ydb-support
Browse files Browse the repository at this point in the history
Feature/add ydb support
  • Loading branch information
gingersamurai authored Aug 29, 2023
2 parents 7011525 + 1778ea5 commit dd28509
Show file tree
Hide file tree
Showing 24 changed files with 841 additions and 8 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/e2e.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
strategy:
max-parallel: 2
matrix:
dialect: ["postgres", "mysql", "vertica", "clickhouse"]
dialect: ["postgres", "mysql", "vertica", "clickhouse", "ydb"]

steps:
- name: Checkout code
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]
- Added YDB support

## [v3.15.0] - 2023-08-12

Expand Down
5 changes: 4 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ tools:
test-packages:
go test $(GO_TEST_FLAGS) $$(go list ./... | grep -v -e /tests -e /bin -e /cmd -e /examples)

test-e2e: test-e2e-postgres test-e2e-mysql test-e2e-clickhouse test-e2e-vertica
test-e2e: test-e2e-postgres test-e2e-mysql test-e2e-clickhouse test-e2e-vertica test-e2e-ydb

test-e2e-postgres:
go test $(GO_TEST_FLAGS) ./tests/e2e -dialect=postgres
Expand All @@ -47,6 +47,9 @@ test-e2e-clickhouse:
test-e2e-vertica:
go test $(GO_TEST_FLAGS) ./tests/vertica

test-e2e-ydb:
go test $(GO_TEST_FLAGS) ./tests/ydb

docker-cleanup:
docker stop -t=0 $$(docker ps --filter="label=goose_test" -aq)

Expand Down
10 changes: 6 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# goose [![Goose CI](https://github.com/pressly/goose/actions/workflows/ci.yaml/badge.svg)](https://github.com/pressly/goose/actions/workflows/ci.yaml) [![Go Reference](https://pkg.go.dev/badge/github.com/pressly/goose/v3.svg)](https://pkg.go.dev/github.com/pressly/goose/v3)

<p align="center">
<img src="assets/goose_logo.png" width="125"">
<img src="assets/goose_logo.png" width="125">
</p>

Goose is a database migration tool. Manage your database schema by creating incremental SQL changes or Go functions.
Expand Down Expand Up @@ -30,7 +30,7 @@ Goose supports [embedding SQL migrations](#embedded-sql-migrations), which means
thus no driver `panic()` conflict within your codebase!
- goose pkg doesn't have any vendor dependencies anymore
- We use timestamped migrations by default but recommend a hybrid approach of using timestamps in the development process and sequential versions in production.
- Supports missing (out-of-order) migrations with the `-allow-missing` flag, or if using as a library supply the functional option `goose.WithAllowMissing()` to Up, UpTo or UpByOne.
- Supports missing (out-of-order) migrations with the `-allow-missing` flag, or if using as a library supply the functional option `goose.WithAllowMissing()` to Up, UpTo or UpByOne. YDB Doesn't support this feature.
- Supports applying ad-hoc migrations without tracking them in the schema table. Useful for seeding a database after migrations have been applied. Use `-no-versioning` flag or the functional option `goose.WithNoVersioning()`.

# Install
Expand All @@ -41,7 +41,7 @@ This will install the `goose` binary to your `$GOPATH/bin` directory.

For a lite version of the binary without DB connection dependent commands, use the exclusive build tags:

$ go build -tags='no_postgres no_mysql no_sqlite3' -o goose ./cmd/goose
$ go build -tags='no_postgres no_mysql no_sqlite3 no_ydb' -o goose ./cmd/goose

For macOS users `goose` is available as a [Homebrew Formulae](https://formulae.brew.sh/formula/goose#default):

Expand All @@ -63,6 +63,7 @@ Drivers:
tidb
clickhouse
vertica
ydb
Examples:
goose sqlite3 ./foo.db status
Expand All @@ -78,6 +79,7 @@ Examples:
goose mssql "sqlserver://user:password@dbname:1433?database=master" status
goose clickhouse "tcp://127.0.0.1:9000" status
goose vertica "vertica://user:password@localhost:5433/dbname?connection_load_balance=1" status
goose ydb "grpc://localhost:2136/local?query_mode=scripting&go_fake_tx=scripting&go_query_bind=declare,numeric" status
Options:
Expand Down Expand Up @@ -123,7 +125,7 @@ Create a new SQL migration.
$ goose create add_some_column sql
$ Created new file: 20170506082420_add_some_column.sql

Edit the newly created file to define the behavior of your migration.
Edit the newly created file to define the behavior of your migration.

You can also create a Go migration, if you then invoke it with [your own goose binary](#go-migrations):

Expand Down
8 changes: 8 additions & 0 deletions cmd/goose/driver_ydb.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
//go:build !no_ydb
// +build !no_ydb

package main

import (
_ "github.com/ydb-platform/ydb-go-sdk/v3"
)
2 changes: 2 additions & 0 deletions cmd/goose/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,7 @@ Drivers:
tidb
clickhouse
vertica
ydb
Examples:
goose sqlite3 ./foo.db status
Expand All @@ -219,6 +220,7 @@ Examples:
goose mssql "sqlserver://user:password@dbname:1433?database=master" status
goose clickhouse "tcp://127.0.0.1:9000" status
goose vertica "vertica://user:password@localhost:5433/dbname?connection_load_balance=1" status
goose ydb "grpcs://localhost:2135/local?query_mode=scripting&go_fake_tx=scripting&go_query_bind=declare,numeric" status
GOOSE_DRIVER=sqlite3 GOOSE_DBSTRING=./foo.db goose status
GOOSE_DRIVER=sqlite3 GOOSE_DBSTRING=./foo.db goose create init sql
Expand Down
2 changes: 1 addition & 1 deletion db.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ func OpenDBWithDriver(driver string, dbstring string) (*sql.DB, error) {
}

switch driver {
case "postgres", "pgx", "sqlite3", "sqlite", "mysql", "sqlserver", "clickhouse", "vertica", "azuresql":
case "postgres", "pgx", "sqlite3", "sqlite", "mysql", "sqlserver", "clickhouse", "vertica", "ydb", "azuresql":
return sql.Open(driver, dbstring)
default:
return nil, fmt.Errorf("unsupported driver %s", driver)
Expand Down
2 changes: 2 additions & 0 deletions dialect.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ func SetDialect(s string) error {
d = dialect.Clickhouse
case "vertica":
d = dialect.Vertica
case "ydb":
d = dialect.Ydb
default:
return fmt.Errorf("%q: unknown dialect", s)
}
Expand Down
10 changes: 10 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ require (
github.com/microsoft/go-mssqldb v1.5.0
github.com/ory/dockertest/v3 v3.10.0
github.com/vertica/vertica-sql-go v1.3.3
github.com/ydb-platform/ydb-go-sdk/v3 v3.51.0
github.com/ziutek/mymysql v1.5.4
modernc.org/sqlite v1.25.0
)
Expand All @@ -31,14 +32,17 @@ require (
github.com/go-faster/city v1.0.1 // indirect
github.com/go-faster/errors v0.6.1 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang-jwt/jwt/v4 v4.5.0 // indirect
github.com/golang-sql/civil v0.0.0-20220223132316-b832511892a9 // indirect
github.com/golang-sql/sqlexp v0.1.0 // indirect
github.com/golang/protobuf v1.5.2 // indirect
github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510 // indirect
github.com/google/uuid v1.3.0 // indirect
github.com/imdario/mergo v0.3.16 // indirect
github.com/jackc/pgpassfile v1.0.0 // indirect
github.com/jackc/pgservicefile v0.0.0-20221227161230-091c0ba34f0a // indirect
github.com/joeshaw/multierror v0.0.0-20140124173710-69b34d4ec901 // indirect
github.com/jonboulle/clockwork v0.3.0 // indirect
github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51 // indirect
github.com/klauspost/compress v1.16.7 // indirect
github.com/lib/pq v1.10.9 // indirect
Expand All @@ -59,13 +63,19 @@ require (
github.com/xeipuuv/gojsonpointer v0.0.0-20190905194746-02993c407bfb // indirect
github.com/xeipuuv/gojsonreference v0.0.0-20180127040603-bd5ef7bd5415 // indirect
github.com/xeipuuv/gojsonschema v1.2.0 // indirect
github.com/ydb-platform/ydb-go-genproto v0.0.0-20230801151335-81e01be38941 // indirect
go.opentelemetry.io/otel v1.16.0 // indirect
go.opentelemetry.io/otel/trace v1.16.0 // indirect
golang.org/x/crypto v0.10.0 // indirect
golang.org/x/mod v0.12.0 // indirect
golang.org/x/net v0.11.0 // indirect
golang.org/x/sync v0.3.0 // indirect
golang.org/x/sys v0.10.0 // indirect
golang.org/x/text v0.11.0 // indirect
golang.org/x/tools v0.10.0 // indirect
google.golang.org/genproto v0.0.0-20230110181048-76db0878b65f // indirect
google.golang.org/grpc v1.53.0 // indirect
google.golang.org/protobuf v1.28.1 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
howett.net/plist v1.0.0 // indirect
Expand Down
Loading

0 comments on commit dd28509

Please sign in to comment.