aboutsummaryrefslogtreecommitdiff
path: root/lib/sql/client.go
diff options
context:
space:
mode:
authorShulhan <m.shulhan@gmail.com>2020-12-17 21:32:40 +0700
committerShulhan <m.shulhan@gmail.com>2020-12-17 21:32:40 +0700
commit6a2d049cc385d825cb2c48f7c36d96990da92c6c (patch)
tree5db3a0d6c2dd9f8190f5880a0d05c31a62dc9a97 /lib/sql/client.go
parent0c5ed9573fec93cbf31e4778c981c61d7decdf4a (diff)
downloadpakakeh.go-6a2d049cc385d825cb2c48f7c36d96990da92c6c.tar.xz
sql: use the options MigrationDir if the argument fs is nil
If case the file-system argument is not provided, the function will assume that the migration script is stored in the MigrationDir which defined in ClientOptions.
Diffstat (limited to 'lib/sql/client.go')
-rw-r--r--lib/sql/client.go7
1 files changed, 7 insertions, 0 deletions
diff --git a/lib/sql/client.go b/lib/sql/client.go
index ac88cb23..3ab7ccef 100644
--- a/lib/sql/client.go
+++ b/lib/sql/client.go
@@ -102,6 +102,13 @@ func (cl *Client) FetchTableNames() (tableNames []string, err error) {
// SQL file name that has been executed and the timestamp.
//
func (cl *Client) Migrate(fs http.FileSystem) (err error) {
+ if fs == nil {
+ if len(cl.MigrationDir) == 0 {
+ return nil
+ }
+ fs = http.Dir(cl.MigrationDir)
+ }
+
root, err := fs.Open("/")
if err != nil {
return fmt.Errorf("Migrate: %w", err)