Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
52 commits
Select commit Hold shift + click to select a range
b350c1d
add skeleton
art22m Oct 19, 2024
77c02b4
implement methods
art22m Oct 22, 2024
259ebbe
makefile, cli build
art22m Oct 23, 2024
3d8b94d
go mod tidy
art22m Oct 23, 2024
adaaedf
some fixes
art22m Oct 23, 2024
991b8e4
refactor
art22m Nov 4, 2024
dff1f87
fix drop func
art22m Nov 4, 2024
a4119b6
update readme
art22m Nov 4, 2024
ce199c1
add auth methods
art22m Nov 4, 2024
9762f6b
refactor
art22m Nov 4, 2024
82c064a
update readme
art22m Nov 4, 2024
31344bc
add tests
art22m Nov 4, 2024
5bcca96
fix test
art22m Nov 9, 2024
b055c93
rm logs
art22m Nov 9, 2024
5f88b99
refactor test files
art22m Nov 9, 2024
9bb90d8
add tls options
art22m Nov 15, 2024
db20d1e
change readme
art22m Nov 15, 2024
1f60913
support min tls version
art22m Nov 19, 2024
6c56695
fix reviews #1
art22m Dec 8, 2024
1e44d1a
fix reviews #2
art22m Dec 8, 2024
3e191cb
migrate to database/sql
art22m Dec 15, 2024
cff2c84
Apply suggestions from code review
asmyasnikov Jan 6, 2025
bc98e58
fixes
asmyasnikov Jan 6, 2025
66ab108
reverted dependencies
asmyasnikov Jan 6, 2025
6203dcb
fixed env
asmyasnikov Jan 6, 2025
d7ef548
go mod tidy
asmyasnikov Jan 6, 2025
360c51f
rename yql to sql
asmyasnikov Jan 6, 2025
b2d6be9
more sql-migrations
asmyasnikov Jan 6, 2025
2f9a824
add params, table creation
art22m Jan 16, 2025
8d6e897
implement locks
art22m Jan 16, 2025
02a74be
multiple images testing
art22m Jan 16, 2025
5611405
fix tests
art22m Jan 17, 2025
7fbf016
rm query mode selection
art22m Jan 17, 2025
a72611a
fix tests
art22m Jan 20, 2025
a6a6af6
rm force lock
art22m Jan 20, 2025
b475a55
bump ydb-go-sdk
asmyasnikov Jan 30, 2025
b48a0a0
exclude ydb 24.2 from specs
asmyasnikov Jan 31, 2025
2aaee07
bump ydb-go-sdk
asmyasnikov Feb 7, 2025
1fdc67a
update ydb-go-sdk/v3
asmyasnikov Feb 27, 2025
8e8166d
Apply suggestions from code review
asmyasnikov Nov 26, 2025
6935997
Update database/ydb/ydb.go
asmyasnikov Nov 26, 2025
5b8cbf1
Update database/ydb/ydb.go
asmyasnikov Nov 26, 2025
85f840a
Update database/ydb/ydb.go
asmyasnikov Nov 26, 2025
107396f
Update database/ydb/ydb.go
asmyasnikov Nov 26, 2025
8a3ce39
go mod tidy
asmyasnikov Nov 26, 2025
4458c7d
Apply suggestions from code review
asmyasnikov Nov 26, 2025
8a5ab0d
ydb-go-sdk/v3.120.0
asmyasnikov Nov 26, 2025
b73871e
replaced uber/atomic to sync/atomic
asmyasnikov Nov 26, 2025
f3696b5
context.TODO() => context.Background()
asmyasnikov Nov 26, 2025
5106026
go mod tidy
asmyasnikov Jan 12, 2026
c405f36
go.mod
asmyasnikov Jan 13, 2026
59abe42
removed +build
asmyasnikov Jan 13, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
47 changes: 47 additions & 0 deletions database/ydb/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# [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-lock-table` | Name of the table which maintains the migration lock (default `schema_lock`). |
| `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>`

### Locks

If golang-migrate fails to acquire the lock when no migrations are currently running, this may indicate that one of the migrations did not complete successfully.
In this case, you need to analyze the previous migrations, rollback if necessary, and manually remove the lock from the
`x-lock-table`.
1 change: 1 addition & 0 deletions database/ydb/examples/migrations/001_create_users.down.sql
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.sql
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,3 @@
DROP TABLE `test/cities`;

ALTER TABLE `test/users` DROP COLUMN city;
7 changes: 7 additions & 0 deletions database/ydb/examples/migrations/002_add_city_to_users.up.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
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.sql
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.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
CREATE TOPIC `test/topic`;
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ALTER TABLE `test/users` DROP INDEX `users_email_index`;
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ALTER TABLE `test/users` ADD INDEX `users_email_index` GLOBAL UNIQUE ON (`email`);
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
DROP TABLE `test/books`;
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
CREATE TABLE `test/books` (
user_id Uint64,
name Text,
author Text,
PRIMARY KEY (user_id)
);
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
DROP TABLE `test/movies`;
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
CREATE TABLE `test/movies` (
user_id Uint64,
name Text,
director Text,
PRIMARY KEY (user_id)
);
Loading
Loading