Skip to content

Commit

Permalink
Merge pull request #3 from art22m/support_ydb
Browse files Browse the repository at this point in the history
YDB Support
  • Loading branch information
asmyasnikov authored Jan 6, 2025
2 parents c378583 + b5aa72f commit 3835934
Show file tree
Hide file tree
Showing 14 changed files with 547 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
SOURCE ?= file go_bindata github github_ee bitbucket aws_s3 google_cloud_storage godoc_vfs gitlab
DATABASE ?= postgres mysql redshift cassandra spanner cockroachdb yugabytedb clickhouse mongodb sqlserver firebird neo4j pgx pgx5 rqlite
DATABASE ?= postgres mysql redshift cassandra spanner cockroachdb yugabytedb clickhouse mongodb sqlserver firebird neo4j pgx pgx5 rqlite ydb
DATABASE_TEST ?= $(DATABASE) sqlite sqlite3 sqlcipher
VERSION ?= $(shell git describe --tags 2>/dev/null | cut -c 2-)
TEST_FLAGS ?=
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ Database drivers run migrations. [Add a new database?](database/driver.go)
* [Firebird](database/firebird)
* [MS SQL Server](database/sqlserver)
* [rqlite](database/rqlite)
* [YDB](database/ydb)

### Database URLs

Expand Down
40 changes: 40 additions & 0 deletions database/ydb/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# [YDB](https://ydb.tech/docs/)

`ydb://[user:password@]host:port/database?QUERY_PARAMS`

| URL Query | Description |
|:----------:|:---------------------------------------:|
| `user` | The user to sign in as. |
| `password` | The user's password. |
| `host` | The host to connect to. |
| `port` | The port to bind to. |
| `database` | The name of the database to connect to. |

| URL Query Params | Description |
|:----------------------------:|:--------------------------------------------------------------------------------------------:|
| `x-auth-token` | Authentication token. |
| `x-migrations-table` | Name of the migrations table (default `schema_migrations`). |
| `x-use-grpcs` | Enables gRPCS protocol for YDB connections (default grpc). |
| `x-tls-ca` | The location of the CA (certificate authority) file. |
| `x-tls-insecure-skip-verify` | Controls whether a client verifies the server's certificate chain and host name. |
| `x-tls-min-version` | Controls the minimum TLS version that is acceptable, use 1.0, 1.1, 1.2 or 1.3 (default 1.2). |

### Secure connection

Query param `x-use-grpcs` enables secure TLS connection that requires certificates.
You can declare root certificate using ENV
variable: `export YDB_SSL_ROOT_CERTIFICATES_FILE=/path/to/ydb/certs/CA.pem` or
by using `x-tls-ca` query param: `?x-tls-ca=/path/to/ydb/certs/CA.pem`.

### Authentication

By default, golang-migrate connects to YDB
using [anonymous credentials](https://ydb.tech/docs/en/recipes/ydb-sdk/auth-anonymous). \
Through the url query, you can change the default behavior:

- To connect to YDB using [static credentials](https://ydb.tech/docs/en/recipes/ydb-sdk/auth-static) you need to specify
username and password:
`ydb://user:password@host:port/database`
- To connect to YDB using [token](https://ydb.tech/docs/en/recipes/ydb-sdk/auth-access-token) you need to specify token
as query parameter:
`ydb://host:port/database?x-auth-token=<YDB_TOKEN>`
1 change: 1 addition & 0 deletions database/ydb/examples/migrations/001_create_users.down.yql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
DROP TABLE `test/users`;
6 changes: 6 additions & 0 deletions database/ydb/examples/migrations/001_create_users.up.yql
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
CREATE TABLE `test/users` (
id Uint64,
name String,
email String,
PRIMARY KEY (id)
);
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
DROP TABLE `test/cities`;

ALTER TABLE `test/users`
DROP COLUMN city;
8 changes: 8 additions & 0 deletions database/ydb/examples/migrations/002_add_city_to_users.up.yql
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
CREATE TABLE `test/cities` (
id Uint64,
name String,
PRIMARY KEY (id)
);

ALTER TABLE `test/users`
ADD COLUMN city Uint64;
1 change: 1 addition & 0 deletions database/ydb/examples/migrations/003_create_topic.down.yql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
DROP TOPIC `test/topic`;
1 change: 1 addition & 0 deletions database/ydb/examples/migrations/003_create_topic.up.yql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
CREATE TOPIC `test/topic`;
Loading

0 comments on commit 3835934

Please sign in to comment.