Skip to content

Commit c0190d2

Browse files
committed
feat(ydbcp): make db schema initialization and migration via goose
1 parent c5f7b99 commit c0190d2

File tree

6 files changed

+53
-26
lines changed

6 files changed

+53
-26
lines changed

init_db/create_tables.sh renamed to cmd/integration/scripts/create_test_tables.sh

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
# create ydbcp tables
2-
./ydb -e ${YDB_ENDPOINT} -d /local scripting yql -f init_db/schema/create_tables.yql
3-
41
# create and fill user table kv_test
52
./ydb -e ${YDB_ENDPOINT} -d /local workload kv init
63
./ydb -e ${YDB_ENDPOINT} -d /local workload kv run upsert --rows 100

docker-compose.yaml

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,20 +21,41 @@ services:
2121
networks:
2222
- ydbcp-net
2323

24+
init_ydb_schema:
25+
image: golang:1.23-bullseye
26+
platform: linux/amd64
27+
container_name: ${YDB_NAME}-init-schema
28+
volumes:
29+
- ./migrations:/migrations
30+
environment:
31+
- YDB_ENDPOINT=grpc://${YDB_NAME}:2136
32+
- YDB_DATABASE=/local
33+
- GOOSE_YDB_PARAMS=go_query_mode=scripting&go_fake_tx=scripting&go_query_bind=declare,numeric
34+
depends_on:
35+
ydb:
36+
condition: service_healthy
37+
restart: "no"
38+
command: >
39+
bash -c "go install github.com/pressly/goose/v3/cmd/goose@latest &&
40+
goose -dir /migrations/yql ydb \"$$YDB_ENDPOINT/$$YDB_DATABASE?$$GOOSE_YDB_PARAMS\" up"
41+
networks:
42+
- ydbcp-net
43+
2444
setup_ydb:
2545
image: cr.yandex/yc/yandex-docker-local-ydb:24.1
2646
platform: linux/amd64
2747
container_name: ${YDB_NAME}-setup
2848
volumes:
29-
- ./init_db:/init_db
30-
- ./internal/connectors/db/yql/schema:/init_db/schema
49+
- ./cmd/integration/scripts:/scripts
3150
environment:
3251
- YDB_ENDPOINT=grpc://${YDB_NAME}:2136
3352
depends_on:
3453
ydb:
3554
condition: service_healthy
55+
init_ydb_schema:
56+
condition: service_completed_successfully
3657
restart: "no"
37-
command: bash -c "chmod +x ./init_db/create_tables.sh && ./init_db/create_tables.sh"
58+
command: bash -c "chmod +x ./scripts/create_test_tables.sh && ./scripts/create_test_tables.sh"
3859
networks:
3960
- ydbcp-net
4061

internal/connectors/db/yql/schema/drop_tables.yql

Lines changed: 0 additions & 3 deletions
This file was deleted.

internal/connectors/db/yql/schema/fill_tables.yql

Lines changed: 0 additions & 14 deletions
This file was deleted.

internal/connectors/db/yql/schema/create_tables.yql renamed to migrations/yql/20251126000000_init_schema.sql

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
-- +goose Up
12
CREATE TABLE Backups (
23
id String NOT NULL,
34
container_id String NOT NULL,
@@ -51,7 +52,6 @@ CREATE TABLE Operations (
5152
status String,
5253
message String,
5354

54-
root_path String,
5555
paths String,
5656
paths_to_exclude String,
5757
operation_id String,
@@ -80,7 +80,6 @@ CREATE TABLE BackupSchedules (
8080

8181
crontab String NOT NULL,
8282
ttl Interval,
83-
root_path String,
8483
paths String,
8584
paths_to_exclude String,
8685

@@ -91,4 +90,17 @@ CREATE TABLE BackupSchedules (
9190

9291
next_launch Timestamp,
9392
PRIMARY KEY (id)
94-
)
93+
);
94+
95+
UPSERT INTO OperationTypes (code, description, is_cancellable) VALUES
96+
('TB', 'Take backup', True),
97+
('RB', 'Restore backup', True),
98+
('DB', 'Delete backup', False),
99+
('TBWR', 'Take backup with retries', True);
100+
101+
-- +goose Down
102+
DROP TABLE BackupSchedules;
103+
DROP TABLE Operations;
104+
DROP TABLE OperationTypes;
105+
DROP TABLE Backups;
106+
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
-- +goose Up
2+
ALTER TABLE Operations
3+
ADD COLUMN root_path String;
4+
5+
ALTER TABLE BackupSchedules
6+
ADD COLUMN root_path String;
7+
8+
-- +goose Down
9+
ALTER TABLE BackupSchedules
10+
DROP COLUMN root_path;
11+
12+
ALTER TABLE Operations
13+
DROP COLUMN root_path;
14+

0 commit comments

Comments
 (0)