From 84891fec6b2f8a82b07433d890cdc1cc6b8e2d3e Mon Sep 17 00:00:00 2001 From: Stas Lysikov Date: Wed, 21 Aug 2024 14:22:11 +0300 Subject: [PATCH] Add test for starrocks (#29) Co-authored-by: Stanislav Lysikov --- Makefile | 23 +++++++++++++++++-- driver/goose/driver.go | 3 +++ tests/convert_test.go | 2 +- .../goose_starrocks/00001_users.sql | 12 ++++++++++ .../goose_starrocks/00002_wallets.sql | 10 ++++++++ .../goose_starrocks/00003_add_users_email.sql | 5 ++++ .../migrations/goose_starrocks/00004_text.sql | 5 ++++ .../goose_starrocks/00101_wrong.sql | 5 ++++ .../goose_starrocks/00102_never.sql | 7 ++++++ tests/migrations_test.go | 6 +++++ tests/vars.go | 3 ++- 11 files changed, 77 insertions(+), 4 deletions(-) create mode 100644 tests/migrations/goose_starrocks/00001_users.sql create mode 100644 tests/migrations/goose_starrocks/00002_wallets.sql create mode 100644 tests/migrations/goose_starrocks/00003_add_users_email.sql create mode 100644 tests/migrations/goose_starrocks/00004_text.sql create mode 100644 tests/migrations/goose_starrocks/00101_wrong.sql create mode 100644 tests/migrations/goose_starrocks/00102_never.sql diff --git a/Makefile b/Makefile index 5dc6694..7dc13a8 100644 --- a/Makefile +++ b/Makefile @@ -4,6 +4,7 @@ PG_CONTAINER_NAME = miga-pg MYSQL_CONTAINER_NAME = miga-mysql CLICKHOUSE_CONTAINER_NAME = miga-clickhouse VERTICA_CONTAINER_NAME = miga-vertica +STARROCKS_CONTAINER_NAME = miga-starrocks IMAGE_NAME = chapsuk/$(NAME) TRAVIS_POSTGRES = postgres://postgres:@127.0.0.1:5432/miga?sslmode=disable @@ -29,10 +30,10 @@ test: go test -v -race ./... .PHONY: db_up -db_up: vertica_up postgres_up mysql_up clickhouse_up +db_up: vertica_up postgres_up mysql_up clickhouse_up starrocks_up .PHONY: db_down -db_down: postgres_down mysql_down clickhouse_down vertica_down +db_down: postgres_down mysql_down clickhouse_down vertica_down starrocks_down .PHONY: postgres_up postgres_up: postgres_down @@ -79,3 +80,21 @@ vertica_up: vertica_down -p 5433:5433 \ --name=$(VERTICA_CONTAINER_NAME) \ dataplatform/docker-vertica + +.PHONY: starrocks_down +starrocks_down: + -docker rm -f $(STARROCKS_CONTAINER_NAME) + +.PHONY: starrocks_up +starrocks_up: starrocks_down + docker run -d \ + -p 9030:9030 \ + --name=$(STARROCKS_CONTAINER_NAME) \ + starrocks/allin1-ubuntu:3.2-latest + sleep 15 + docker exec -i $(STARROCKS_CONTAINER_NAME) \ + mysql -P 9030 -h 127.0.0.1 -u root \ + -e "CREATE DATABASE IF NOT EXISTS miga" + docker exec -i $(STARROCKS_CONTAINER_NAME) \ + mysql -P 9030 -h 127.0.0.1 -u root \ + -e 'ADMIN SET FRONTEND CONFIG ("enable_fast_schema_evolution" = "true")' diff --git a/driver/goose/driver.go b/driver/goose/driver.go index e065202..d05a869 100644 --- a/driver/goose/driver.go +++ b/driver/goose/driver.go @@ -26,6 +26,9 @@ func New(dialect, dsn, tableName, dir string) (*Goose, error) { if dialect == "clickhouse-replicated" { driverName = "clickhouse" } + if dialect == "starrocks" { + driverName = "mysql" + } db, err := sql.Open(driverName, dsn) if err != nil { diff --git a/tests/convert_test.go b/tests/convert_test.go index e835f81..ff23158 100644 --- a/tests/convert_test.go +++ b/tests/convert_test.go @@ -17,7 +17,7 @@ import ( func TestConvert(t *testing.T) { for driverName, dialects := range drivers { for _, dialect := range dialects { - if dialect == "clickhouse" || dialect == "clickhouse-replicated" || dialect == "vertica" { + if dialect == "clickhouse" || dialect == "clickhouse-replicated" || dialect == "vertica" || dialect == "starrocks" { continue } for tdriverName := range drivers { diff --git a/tests/migrations/goose_starrocks/00001_users.sql b/tests/migrations/goose_starrocks/00001_users.sql new file mode 100644 index 0000000..59c00db --- /dev/null +++ b/tests/migrations/goose_starrocks/00001_users.sql @@ -0,0 +1,12 @@ +-- +goose Up +CREATE TABLE IF NOT EXISTS users ( + id BIGINT, + name STRING, + migastas BIGINT DEFAULT "0" +) +PRIMARY KEY (id) +DISTRIBUTED BY HASH (id) +ORDER BY (id); + +-- +goose Down +DROP TABLE IF EXISTS users; diff --git a/tests/migrations/goose_starrocks/00002_wallets.sql b/tests/migrations/goose_starrocks/00002_wallets.sql new file mode 100644 index 0000000..e862fbb --- /dev/null +++ b/tests/migrations/goose_starrocks/00002_wallets.sql @@ -0,0 +1,10 @@ +-- +goose Up +CREATE TABLE IF NOT EXISTS wallets ( + id BIGINT, + user_id BIGINT +) +PRIMARY KEY (id) +DISTRIBUTED BY HASH (id); + +-- +goose Down +DROP TABLE IF EXISTS wallets; diff --git a/tests/migrations/goose_starrocks/00003_add_users_email.sql b/tests/migrations/goose_starrocks/00003_add_users_email.sql new file mode 100644 index 0000000..ea3d469 --- /dev/null +++ b/tests/migrations/goose_starrocks/00003_add_users_email.sql @@ -0,0 +1,5 @@ +-- +goose Up +ALTER TABLE users ADD COLUMN email STRING; + +-- +goose Down +ALTER TABLE users DROP COLUMN email; diff --git a/tests/migrations/goose_starrocks/00004_text.sql b/tests/migrations/goose_starrocks/00004_text.sql new file mode 100644 index 0000000..99743d3 --- /dev/null +++ b/tests/migrations/goose_starrocks/00004_text.sql @@ -0,0 +1,5 @@ +-- +goose Up +INSERT INTO users (id, name) VALUES (1, 'Abib;Rabib'); + +-- +goose Down +DELETE FROM users WHERE id = 1; diff --git a/tests/migrations/goose_starrocks/00101_wrong.sql b/tests/migrations/goose_starrocks/00101_wrong.sql new file mode 100644 index 0000000..95c932f --- /dev/null +++ b/tests/migrations/goose_starrocks/00101_wrong.sql @@ -0,0 +1,5 @@ +-- +goose Up +ALTER TABLE users ADD COLUMN email VARCHAR; + +-- +goose Down +ALTER TABLE users DROP COLUMN IF EXISTS email; diff --git a/tests/migrations/goose_starrocks/00102_never.sql b/tests/migrations/goose_starrocks/00102_never.sql new file mode 100644 index 0000000..6e2abee --- /dev/null +++ b/tests/migrations/goose_starrocks/00102_never.sql @@ -0,0 +1,7 @@ +-- +goose Up +CREATE TABLE never ( + id INT +) engine=Memory; + +-- +goose Down +DROP TABLE IF EXISTS never; diff --git a/tests/migrations_test.go b/tests/migrations_test.go index b24f5f7..1c956b2 100644 --- a/tests/migrations_test.go +++ b/tests/migrations_test.go @@ -297,6 +297,9 @@ func TestMigrations(t *testing.T) { tableName = "clickhouse_replicated_db_version" tableSuffix = "_replicated" } + if dialect == "starrocks" { + dir += "_starrocks" + } driverInst, err := driver.New(&config.Config{ Miga: config.MigaConfig{ @@ -316,6 +319,9 @@ func TestMigrations(t *testing.T) { if dialect == "clickhouse-replicated" { dbDriver = "clickhouse" } + if dialect == "starrocks" { + dbDriver = "mysql" + } db, err := sql.Open(dbDriver, string(dsns[dialect])) So(err, ShouldBeNil) defer db.Close() diff --git a/tests/vars.go b/tests/vars.go index 63219ef..398cfaa 100644 --- a/tests/vars.go +++ b/tests/vars.go @@ -21,7 +21,7 @@ type ( var ( drivers = map[driverName]dialects{ - "goose": []string{"mysql", "postgres", "clickhouse", "vertica", "clickhouse-replicated"}, + "goose": []string{"mysql", "postgres", "clickhouse", "vertica", "clickhouse-replicated","starrocks"}, "migrate": []string{"mysql", "postgres"}, "impg": []string{"postgres"}, } @@ -32,5 +32,6 @@ var ( "clickhouse": "tcp://user:password@127.0.0.1:9000/miga", "clickhouse-replicated": "tcp://user:password@127.0.0.1:9000/miga", "vertica": "vertica://dbadmin:@127.0.0.1:5433/docker", + "starrocks": "root@tcp(127.0.0.1:9030)/miga?interpolateParams=true", } )