Skip to content

Commit

Permalink
Add test for starrocks (#29)
Browse files Browse the repository at this point in the history
Co-authored-by: Stanislav Lysikov <s.lysikov@space307.com>
  • Loading branch information
barloc and Stanislav Lysikov authored Aug 21, 2024
1 parent 159e638 commit 84891fe
Show file tree
Hide file tree
Showing 11 changed files with 77 additions and 4 deletions.
23 changes: 21 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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")'
3 changes: 3 additions & 0 deletions driver/goose/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion tests/convert_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
12 changes: 12 additions & 0 deletions tests/migrations/goose_starrocks/00001_users.sql
Original file line number Diff line number Diff line change
@@ -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;
10 changes: 10 additions & 0 deletions tests/migrations/goose_starrocks/00002_wallets.sql
Original file line number Diff line number Diff line change
@@ -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;
5 changes: 5 additions & 0 deletions tests/migrations/goose_starrocks/00003_add_users_email.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
-- +goose Up
ALTER TABLE users ADD COLUMN email STRING;

-- +goose Down
ALTER TABLE users DROP COLUMN email;
5 changes: 5 additions & 0 deletions tests/migrations/goose_starrocks/00004_text.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
-- +goose Up
INSERT INTO users (id, name) VALUES (1, 'Abib;Rabib');

-- +goose Down
DELETE FROM users WHERE id = 1;
5 changes: 5 additions & 0 deletions tests/migrations/goose_starrocks/00101_wrong.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
-- +goose Up
ALTER TABLE users ADD COLUMN email VARCHAR;

-- +goose Down
ALTER TABLE users DROP COLUMN IF EXISTS email;
7 changes: 7 additions & 0 deletions tests/migrations/goose_starrocks/00102_never.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
-- +goose Up
CREATE TABLE never (
id INT
) engine=Memory;

-- +goose Down
DROP TABLE IF EXISTS never;
6 changes: 6 additions & 0 deletions tests/migrations_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand All @@ -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()
Expand Down
3 changes: 2 additions & 1 deletion tests/vars.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"},
}
Expand All @@ -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",
}
)

0 comments on commit 84891fe

Please sign in to comment.