Skip to content

Commit 2e5bce6

Browse files
committed
move docker && create-model tool && tool refactoring
1 parent f031d24 commit 2e5bce6

File tree

22 files changed

+261
-113
lines changed

22 files changed

+261
-113
lines changed

README.md

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,12 @@
1717
Don't forget to set `binlog_do_db=<master_db_name>` and restart MySQL service.
1818
- Execute `sql/structure.sql` in your MySQL master and slave.
1919
- Execute `sql/replicator.sql` in your MySQL. It will create database for system values.
20-
- Start Docker as `docker-compose up -d --build`
20+
- Start Docker as `cd docker` and `docker-compose up -d --build`
2121
- Run as `cd src` and `go run main.go listen` in docker container.
2222

2323
### Testing
2424

2525
- Copy `examples/user.json` and `examples/post.json` to `src/configs`
26-
- Execute `sql/test.sql` in your MySQL master and see output.
27-
28-
##### OR
29-
3026
- Execute `cd src` and `go run main.go load`
3127

3228
### Add tables to replicator
@@ -57,6 +53,7 @@ Don't forget to set `binlog_do_db=<master_db_name>` and restart MySQL service.
5753

5854
- Set start position of log: `go run main.go set-position <table> <name> <position>`
5955
- Loader for replication testing: `go run main.go load`
56+
- Create model json-file by master table structure: `go run main.go create-model <table>`
6057

6158
### Container mode
6259

docker-compose.yml

Lines changed: 0 additions & 10 deletions
This file was deleted.
File renamed without changes.

docker/docker-compose.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
version: '3'
2+
services:
3+
horgh-replicator:
4+
container_name: horgh_replicator
5+
build:
6+
context: ../
7+
dockerfile: ./docker/Dockerfile
8+
tty: true
9+
volumes:
10+
- ../:/go/src/horgh-replicator
11+
- ../supervisor:/etc/supervisor/conf.d

examples/user.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
"name",
77
"status",
88
"active",
9+
"balance",
910
"created"
1011
]
1112
},
@@ -38,6 +39,11 @@
3839
"key": false,
3940
"mode": "bool"
4041
},
42+
{
43+
"name": "balance",
44+
"key": false,
45+
"mode": "float"
46+
},
4147
{
4248
"name": "created",
4349
"key": false,

sql/structure.sql

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ CREATE TABLE test.user
77
name VARCHAR(40),
88
status VARCHAR(255),
99
active bool,
10+
balance float,
1011
created TIMESTAMP DEFAULT CURRENT_TIMESTAMP NOT NULL ON UPDATE CURRENT_TIMESTAMP
1112
) engine=InnoDB;
1213

@@ -25,6 +26,7 @@ CREATE TABLE test.user
2526
name VARCHAR(40),
2627
status VARCHAR(255),
2728
active bool,
29+
balance float,
2830
created TIMESTAMP NOT NULL
2931
) engine=InnoDB;
3032

@@ -47,6 +49,7 @@ CREATE TABLE public."user"
4749
name VARCHAR(40),
4850
status VARCHAR(255),
4951
active bool,
52+
balance float,
5053
created TIMESTAMP DEFAULT NULL
5154
);
5255

@@ -61,7 +64,7 @@ CREATE TABLE public.post
6164
/*For ClickHouse Slave*/
6265
CREATE DATABASE test;
6366

64-
CREATE TABLE test.user (id Int32, name FixedString(40), status FixedString(255), active UInt8, created DateTime) ENGINE = MergeTree()
67+
CREATE TABLE test.user (id Int32, name FixedString(40), status FixedString(255), active UInt8, balance Float32, created DateTime) ENGINE = MergeTree()
6568
PARTITION BY id
6669
ORDER BY id;
6770

@@ -77,6 +80,7 @@ CREATE TABLE "user"
7780
name VARCHAR,
7881
status VARCHAR,
7982
active bool,
83+
balance FLOAT,
8084
created TIMESTAMP NOT NULL
8185
);
8286

sql/test.sql

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

src/Gopkg.lock

Lines changed: 1 addition & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/constants/errors.go

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,21 @@
11
package constants
22

33
const (
4-
ErrorMysqlCanal = "Invalid canal"
5-
ErrorMysqlPosition = "Invalid position"
6-
ErrorSliceCreation = "InterfaceSlice() given a non-slice type"
7-
ErrorNoColumn = "There is no column %s in %s.%s"
8-
ErrorDBConnect = "Can't connect to \"%s\""
9-
ErrorSave = "Can't %s model in \"%s\" data: %v"
10-
ErrorExecQuery = "Can't exec query. Type: \"%s\" error: \"%v\""
11-
ErrorNoModelFile = "Model file \"%s\" not exists"
12-
ErrorParserPosition = "Catch error: \"%s\""
13-
ErrorGetMinPosition = "Can't get min position. Error: \"%s\""
14-
ErrorUndefinedSlave = "Can't get slave. Error: \"%s\""
15-
ErrorCobraStarter = "Catch cobra error: \"%s\""
16-
ErrorCachePluginError = "Catch plugin error: \"%s\""
4+
ErrorMysqlCanal = "Invalid canal"
5+
ErrorMysqlPosition = "Invalid position"
6+
ErrorSliceCreation = "InterfaceSlice() given a non-slice type"
7+
ErrorNoColumn = "There is no column %s in %s.%s"
8+
ErrorDBConnect = "Can't connect to \"%s\""
9+
ErrorSave = "Can't %s model in \"%s\" data: %v"
10+
ErrorExecQuery = "Can't exec query. Type: \"%s\" error: \"%v\""
11+
ErrorNoModelFile = "Model file \"%s\" not exists"
12+
ErrorModelFileExists = "Model file \"%s\" already exists"
13+
ErrorParserPosition = "Catch error: \"%s\""
14+
ErrorGetMinPosition = "Can't get min position. Error: \"%s\""
15+
ErrorUndefinedSlave = "Can't get slave. Error: \"%s\""
16+
ErrorCobraStarter = "Catch cobra error: \"%s\""
17+
ErrorCachePluginError = "Catch plugin error: \"%s\""
18+
ErrorTableStructure = "Can't read structure of table %s. Error : \"%s\""
19+
ErrorFieldTypeConversion = "Can't convert field type %s"
20+
ErrorBuildModelConfig = "Can't build model config. Error: \"%s\""
1721
)

src/constants/messages.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,5 @@ const (
1313
MessageStopHandlingBinlog = "Stopping binlog handling..."
1414
MessageStopHandlingSave = "Stopping replication handling..."
1515
MessageWait = "Waiting %s %s..."
16+
MessageConfigCreated = "Model config for table %s created. File: \"%s\""
1617
)

0 commit comments

Comments
 (0)