Skip to content

Commit 9c3a0cd

Browse files
committed
changes to loader API, added information about deprecating CLI in 2.2
1 parent d6305af commit 9c3a0cd

File tree

3 files changed

+23
-21
lines changed

3 files changed

+23
-21
lines changed

README.md

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ migrator can run as a HTTP REST service. Further, there is a ready-to-go migrato
88

99
# Usage
1010

11+
Important: Migrator since its inception supported both CLI and REST API. However, CLI is deprecated as of v2.2 and will be removed in migrator v3.0. Starting v3.0 only REST API will be supported.
12+
1113
Short and sweet.
1214

1315
```
@@ -57,14 +59,6 @@ create table if not exists {schema}.modules ( k int, v text );
5759
insert into {schema}.modules values ( 123, '123' );
5860
```
5961

60-
# DB Schemas
61-
62-
When using migrator please remember about these:
63-
64-
* migrator creates `migrator` schema (where `migrator_migrations` and `migrator_tenants` tables reside) automatically
65-
* when adding a new tenant migrator creates a new schema automatically
66-
* single schemas are not created automatically, for this you must add initial migration with `create schema` SQL statement (see example above)
67-
6862
# Server mode
6963

7064
When migrator is run with `-mode server` it starts a HTTP service and exposes simple REST API which you can use to invoke migrator actions remotely.
@@ -84,13 +78,21 @@ Some curl examples to get you started:
8478
curl http://localhost:8080/
8579
curl http://localhost:8080/diskMigrations
8680
curl http://localhost:8080/tenants
87-
curl -X POST -H "Content-Type: application/json" -d '{"name": "new_tenant"}' http://localhost:8080/tenants
8881
curl http://localhost:8080/migrations
8982
curl -X POST http://localhost:8080/migrations
83+
curl -X POST -H "Content-Type: application/json" -d '{"name": "new_tenant"}' http://localhost:8080/tenants
9084
```
9185

9286
Port is configurable in `migrator.yaml` and defaults to 8080. Should you need HTTPS capabilities I encourage you to use nginx/apache/haproxy for TLS offloading.
9387

88+
# DB Schemas
89+
90+
When using migrator please remember about these:
91+
92+
* migrator creates `migrator` schema (where `migrator_migrations` and `migrator_tenants` tables reside) automatically
93+
* when adding a new tenant migrator creates a new schema automatically
94+
* single schemas are not created automatically, for this you must add initial migration with `create schema` SQL statement (see example above)
95+
9496
# Supported databases
9597

9698
Currently migrator supports the following databases and their flavours:

loader/disk_loader.go

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,13 @@ import (
1515
"github.com/lukaszbudnik/migrator/utils"
1616
)
1717

18-
// DiskLoader is struct used for implementing Loader interface for loading migrations from disk
19-
type DiskLoader struct {
20-
Config *config.Config
18+
// diskLoader is struct used for implementing Loader interface for loading migrations from disk
19+
type diskLoader struct {
20+
config *config.Config
2121
}
2222

2323
// GetDiskMigrations returns all migrations from disk
24-
func (dl *DiskLoader) GetDiskMigrations() (migrations []types.Migration, err error) {
24+
func (dl *diskLoader) GetDiskMigrations() (migrations []types.Migration, err error) {
2525
defer func() {
2626
if r := recover(); r != nil {
2727
var ok bool
@@ -32,13 +32,13 @@ func (dl *DiskLoader) GetDiskMigrations() (migrations []types.Migration, err err
3232
}
3333
}()
3434

35-
dirs, err := ioutil.ReadDir(dl.Config.BaseDir)
35+
dirs, err := ioutil.ReadDir(dl.config.BaseDir)
3636
if err != nil {
3737
panic(err.Error())
3838
}
3939

40-
singleSchemasDirs := dl.filterSchemaDirs(dirs, dl.Config.SingleSchemas)
41-
tenantSchemasDirs := dl.filterSchemaDirs(dirs, dl.Config.TenantSchemas)
40+
singleSchemasDirs := dl.filterSchemaDirs(dirs, dl.config.SingleSchemas)
41+
tenantSchemasDirs := dl.filterSchemaDirs(dirs, dl.config.TenantSchemas)
4242

4343
migrationsMap := make(map[string][]types.Migration)
4444

@@ -61,7 +61,7 @@ func (dl *DiskLoader) GetDiskMigrations() (migrations []types.Migration, err err
6161
return
6262
}
6363

64-
func (dl *DiskLoader) filterSchemaDirs(files []os.FileInfo, schemaDirs []string) []string {
64+
func (dl *diskLoader) filterSchemaDirs(files []os.FileInfo, schemaDirs []string) []string {
6565
var dirs []string
6666
for _, f := range files {
6767
if f.IsDir() {
@@ -74,15 +74,15 @@ func (dl *DiskLoader) filterSchemaDirs(files []os.FileInfo, schemaDirs []string)
7474
return dirs
7575
}
7676

77-
func (dl *DiskLoader) readMigrationsFromSchemaDirs(migrations map[string][]types.Migration, sourceDirs []string, migrationType types.MigrationType) {
77+
func (dl *diskLoader) readMigrationsFromSchemaDirs(migrations map[string][]types.Migration, sourceDirs []string, migrationType types.MigrationType) {
7878
for _, sourceDir := range sourceDirs {
79-
files, err := ioutil.ReadDir(filepath.Join(dl.Config.BaseDir, sourceDir))
79+
files, err := ioutil.ReadDir(filepath.Join(dl.config.BaseDir, sourceDir))
8080
if err != nil {
8181
panic(err.Error())
8282
}
8383
for _, file := range files {
8484
if !file.IsDir() {
85-
contents, err := ioutil.ReadFile(filepath.Join(dl.Config.BaseDir, sourceDir, file.Name()))
85+
contents, err := ioutil.ReadFile(filepath.Join(dl.config.BaseDir, sourceDir, file.Name()))
8686
if err != nil {
8787
panic(err.Error())
8888
}

loader/loader.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,5 @@ type Loader interface {
1212

1313
// NewLoader returns new instance of Loader, currently DiskLoader is available
1414
func NewLoader(config *config.Config) Loader {
15-
return &DiskLoader{config}
15+
return &diskLoader{config}
1616
}

0 commit comments

Comments
 (0)