Skip to content

Commit 119b0c1

Browse files
authored
Merge pull request #34 from stxml/master
Expand environment variables in datasource
2 parents 1911909 + 1ad0b33 commit 119b0c1

3 files changed

Lines changed: 24 additions & 0 deletions

File tree

sql-migrate/config.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"flag"
77
"fmt"
88
"io/ioutil"
9+
"os"
910

1011
"github.com/rubenv/sql-migrate"
1112
"gopkg.in/gorp.v1"
@@ -71,6 +72,7 @@ func GetEnvironment() (*Environment, error) {
7172
if env.DataSource == "" {
7273
return nil, errors.New("No data source specified")
7374
}
75+
env.DataSource = os.ExpandEnv(env.DataSource)
7476

7577
if env.Dir == "" {
7678
env.Dir = "migrations"

test-integration/dbconfig.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,11 @@ mysql_noflag:
1313
datasource: root@/test
1414
dir: test-migrations
1515

16+
mysql_env:
17+
dialect: mysql
18+
datasource: ${MYSQL_USER}@/$DATABASE?parseTime=true
19+
dir: test-migrations
20+
1621
sqlite:
1722
dialect: sqlite3
1823
datasource: test.db

test-integration/mysql-env.sh

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#!/bin/bash
2+
3+
# Tweak PATH for Travis
4+
export PATH=$PATH:$HOME/gopath/bin
5+
6+
export MYSQL_USER=root
7+
export DATABASE=test
8+
9+
OPTIONS="-config=test-integration/dbconfig.yml -env mysql_env"
10+
11+
set -ex
12+
13+
sql-migrate status $OPTIONS
14+
sql-migrate up $OPTIONS
15+
sql-migrate down $OPTIONS
16+
sql-migrate redo $OPTIONS
17+
sql-migrate status $OPTIONS

0 commit comments

Comments
 (0)