Skip to content

Commit e04cecb

Browse files
authored
Merge pull request #32 from lukaszbudnik/reworked-docker-script
reworked docker scripts
2 parents c74f41e + 6684158 commit e04cecb

13 files changed

+125
-153
lines changed

README.md

Lines changed: 21 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,15 @@ DB migration tool written in go.
77
Short and sweet.
88

99
```
10-
$ migrator -h
11-
Usage of migrator:
10+
$ Usage of ./migrator:
1211
-action string
13-
migrator action to apply, valid actions are: ["apply" "config" "diskMigrations" "dbTenants" "dbMigrations"] (default "apply")
12+
when run in tool mode, action to execute, valid actions are: ["apply" "addTenant" "config" "diskMigrations" "dbTenants" "dbMigrations"] (default "apply")
1413
-configFile string
15-
path to migrator.yaml (default "migrator.yaml")
14+
path to migrator configuration yaml file (default "migrator.yaml")
1615
-mode string
17-
migrator mode to run: "tool" or "server" (default "tool")
16+
migrator mode to run: ["tool" "server"] (default "tool")
17+
-tenant string
18+
when run in tool mode and action set to "addTenant", specifies new tenant name
1819
```
1920

2021
Migrator requires a simple `migrator.yaml` file:
@@ -24,7 +25,9 @@ baseDir: test/migrations
2425
driver: postgres
2526
dataSource: "user=postgres dbname=migrator_test host=192.168.99.100 port=55432 sslmode=disable"
2627
# override only if you have a specific way of determining tenants, default is:
27-
tenantsSql: "select name from public.migrator_tenants"
28+
tenantSelectSql: "select name from public.migrator_tenants"
29+
# override only if you have a specific way of creating tenants, default is:
30+
tenantInsertSql: "insert into public.migrator_tenants (name) values ($1)"
2831
# override only if you have a specific schema placeholder, default is:
2932
schemaPlaceHolder: {schema}
3033
singleSchemas:
@@ -33,18 +36,18 @@ singleSchemas:
3336
- config
3437
tenantSchemas:
3538
- tenants
36-
# port is used only when migrator is run in server mode
37-
# optional element and defaults to 8080
38-
port: 8181
39-
# optional Slack Incoming Web Hook - every apply action posts a message to Slack
39+
# port is used only when migrator is run in server mode, defaults to:
40+
port: 8080
41+
# optional Slack Incoming Web Hook - if defined apply migrations action will post a message to Slack
4042
slackWebHook: https://hooks.slack.com/services/TTT/BBB/XXX
4143
```
4244

43-
Migrator will scan all directories under `baseDir` directory. Migrations listed under `singleSchemas` directories will be applied once. Migrations listed under `tenantSchemas` directories will be applied for all tenants fetched using `tenantsSql`.
45+
Migrator will scan all directories under `baseDir` directory. Migrations listed under `singleSchemas` directories will be applied once. Migrations listed under `tenantSchemas` directories will be applied for all tenants fetched using `tenantSelectSql`.
4446

4547
SQL migrations in both `singleSchemas` and `tenantsSchemas` can use `{schema}` placeholder which is automatically replaced by migrator to the current schema. For example:
4648

4749
```
50+
create schema if not exists {schema};
4851
create table if not exists {schema}.modules ( k int, v text );
4952
insert into {schema}.modules values ( 123, '123' );
5053
```
@@ -79,34 +82,18 @@ Port is configurable in `migrator.yaml` and defaults to 8080. Should you need HT
7982

8083
Currently migrator supports the following databases:
8184

82-
* PostgreSQL - schema-based multi-tenant database, with transactions spanning DDL statements
83-
* MySQL - database-based multi-tenant database, transactions do not span DDL statements
84-
* MariaDB - enhanced near linearly scalable multi-master MySQL
85+
* PostgreSQL - schema-based multi-tenant database, with transactions spanning DDL statements, driver used: https://github.com/lib/pq
86+
* MySQL - database-based multi-tenant database, transactions do not span DDL statements, driver used: https://github.com/go-sql-driver/mysql
87+
* MariaDB - enhanced near linearly scalable multi-master MySQL, driver used: https://github.com/go-sql-driver/mysql
8588

86-
# Examples
89+
# Running unit & integration tests
8790

88-
PostgreSQL:
91+
PostgreSQL, MySQL, and MariaDB:
8992

9093
```
91-
$ docker/postgresql-create-and-setup-container.sh
94+
$ docker/create-and-setup-container.sh [postgresql|mysql|mariadb]
9295
$ ./coverage.sh
93-
$ docker/postgresql-destroy-container.sh
94-
```
95-
96-
MySQL:
97-
98-
```
99-
$ docker/mysql-create-and-setup-container.sh
100-
$ ./coverage.sh
101-
$ docker/mysql-destroy-container.sh
102-
```
103-
104-
MariaDB:
105-
106-
```
107-
$ docker/mariadb-create-and-setup-container.sh
108-
$ ./coverage.sh
109-
$ docker/mariadb-destroy-container.sh
96+
$ docker/destroy-container.sh [postgresql|mysql|mariadb]
11097
```
11198

11299
Or see `.travis.yml` to see how it's done on Travis.
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#!/usr/bin/env bash
2+
3+
set -x
4+
5+
cd `dirname $0`
6+
7+
CONTAINER_TYPE=$1
8+
9+
for SCRIPT in scripts/*.sh; do
10+
source "$SCRIPT"
11+
done
12+
13+
case $CONTAINER_TYPE in
14+
postgresql )
15+
postgresql_start
16+
;;
17+
mysql )
18+
mysql_start mysql
19+
;;
20+
mariadb )
21+
mysql_start mariadb
22+
;;
23+
* )
24+
>&2 echo "Unknown container type $CONTAINER_TYPE"
25+
exit 1
26+
27+
esac

docker/destroy-all-containers.sh

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

docker/destroy-container.sh

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#!/usr/bin/env bash
2+
3+
set -x
4+
5+
cd `dirname $0`
6+
7+
CONTAINER_TYPE=$1
8+
9+
for SCRIPT in scripts/*.sh; do
10+
source "${SCRIPT}"
11+
done
12+
13+
destroy_container $CONTAINER_TYPE

docker/mariadb-create-and-setup-container.sh

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

docker/mariadb-destroy-container.sh

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

docker/mysql-create-and-setup-container.sh

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

docker/mysql-destroy-container.sh

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

docker/postgresql-create-and-setup-container.sh

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

docker/postgresql-destroy-container.sh

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

0 commit comments

Comments
 (0)