@@ -13,6 +13,7 @@ import (
1313 migratePgx "github.com/golang-migrate/migrate/v4/database/pgx/v5" // postgres pgx driver for golang_migrate
1414 _ "github.com/golang-migrate/migrate/v4/source/file" // support file scheme for golang_migrate
1515 _ "github.com/golang-migrate/migrate/v4/source/github" // support github scheme for golang_migrate
16+ "github.com/golang-migrate/migrate/v4/source/iofs"
1617 "github.com/jackc/pgx/v5/pgxpool"
1718 pgxstd "github.com/jackc/pgx/v5/stdlib"
1819
@@ -42,6 +43,7 @@ import (
4243 "github.com/oasisprotocol/nexus/config"
4344 "github.com/oasisprotocol/nexus/log"
4445 "github.com/oasisprotocol/nexus/storage"
46+ "github.com/oasisprotocol/nexus/storage/migrations"
4547 source "github.com/oasisprotocol/nexus/storage/oasis"
4648 "github.com/oasisprotocol/nexus/storage/oasis/nodeapi"
4749)
@@ -50,8 +52,8 @@ const (
5052 moduleName = "analysis_service"
5153)
5254
53- // RunMigrations runs migrations defined in sourceURL against databaseURL.
54- func RunMigrations (sourceURL string , databaseURL string ) error {
55+ // RunMigrations runs embedded migrations against databaseURL.
56+ func RunMigrations (databaseURL string ) error {
5557 // Go-migrate supports only basic database URL parameters.
5658 // We use pgx to parse the database URL the same way as we do in the indexer
5759 // client. That way the config options for migrations and clients are compatible.
@@ -73,10 +75,16 @@ func RunMigrations(sourceURL string, databaseURL string) error {
7375 }
7476 defer driver .Close ()
7577
76- m , err := migrate . NewWithDatabaseInstance ( sourceURL , config . ConnConfig . Database , driver )
78+ sourceDriver , err := iofs . New ( migrations . FS , "." )
7779 if err != nil {
78- return err
80+ return fmt . Errorf ( "failed to create embedded migration source: %w" , err )
7981 }
82+
83+ m , err := migrate .NewWithInstance ("iofs" , sourceDriver , config .ConnConfig .Database , driver )
84+ if err != nil {
85+ return fmt .Errorf ("failed to create migration instance: %w" , err )
86+ }
87+
8088 return m .Up ()
8189}
8290
@@ -94,7 +102,7 @@ func Init(ctx context.Context, cfg *config.AnalysisConfig, logger *log.Logger) (
94102 }
95103
96104 logger .Info ("checking if migrations need to be applied..." )
97- switch err := RunMigrations (cfg .Storage .Migrations , cfg . Storage . Endpoint ); {
105+ switch err := RunMigrations (cfg .Storage .Endpoint ); {
98106 case err == migrate .ErrNoChange :
99107 logger .Info ("no migrations needed to be applied" )
100108 case err != nil :
0 commit comments