@@ -3,15 +3,19 @@ package fxsql
33import (
44 "context"
55 "database/sql"
6+ "sync"
67
78 "github.com/ankorstore/yokai/config"
89 "github.com/ankorstore/yokai/log"
910 yokaisql "github.com/ankorstore/yokai/sql"
1011 yokaisqllog "github.com/ankorstore/yokai/sql/hook/log"
1112 yokaisqltrace "github.com/ankorstore/yokai/sql/hook/trace"
13+ "github.com/pressly/goose/v3"
1214 "go.uber.org/fx"
1315)
1416
17+ var once sync.Once
18+
1519// ModuleName is the module name.
1620const ModuleName = "sql"
1721
@@ -98,11 +102,18 @@ func NewFxSQLDatabase(p FxSQLDatabaseParam) (*sql.DB, error) {
98102type FxSQLMigratorParam struct {
99103 fx.In
100104 Db * sql.DB
105+ Config * config.Config
101106 Logger * log.Logger
102107}
103108
104109// NewFxSQLMigrator returns a Migrator instance.
105110func NewFxSQLMigrator (p FxSQLMigratorParam ) * Migrator {
111+ // set once migrator the logger
112+ once .Do (func () {
113+ goose .SetLogger (NewMigratorLogger (p .Logger , p .Config .GetBool ("modules.sql.migrations.stdout" )))
114+ })
115+
116+ // migrator
106117 return NewMigrator (p .Db , p .Logger )
107118}
108119
@@ -126,7 +137,7 @@ func RunFxSQLMigration(command string, args ...string) fx.Option {
126137 return migrator .Run (
127138 ctx ,
128139 config .GetString ("modules.sql.driver" ),
129- config .GetString ("modules.sql.migrations" ),
140+ config .GetString ("modules.sql.migrations.path " ),
130141 command ,
131142 args ... ,
132143 )
@@ -144,7 +155,7 @@ func RunFxSQLMigrationAndShutdown(command string, args ...string) fx.Option {
144155 return migrator .Run (
145156 ctx ,
146157 config .GetString ("modules.sql.driver" ),
147- config .GetString ("modules.sql.migrations" ),
158+ config .GetString ("modules.sql.migrations.path " ),
148159 command ,
149160 args ... ,
150161 )
0 commit comments