@@ -651,28 +651,39 @@ func (p *DatabasePlugin) markApplied(ctx cli.CommandContext) error {
651651// Helper functions
652652
653653func (p * DatabasePlugin ) loadMigrations () (* migrate.Migrations , error ) {
654- // Try multiple possible migration paths
655- possiblePaths := []string {
656- filepath .Join (p .config .RootDir , "migrations" ), // Standard location
657- filepath .Join (p .config .RootDir , "database" , "migrations" ), // Alternative location
658- }
659-
660654 var migrationPath string
661655
662- for _ , path := range possiblePaths {
663- if info , err := os . Stat ( path ); err == nil && info . IsDir () {
664- migrationPath = path
656+ // First priority: Check if migrations_path is configured in .forge.yaml
657+ if p . config != nil && p . config . Database . MigrationsPath != "" {
658+ migrationPath = p . config . Database . MigrationsPath
665659
666- break
660+ // Make relative paths absolute based on project root
661+ if ! filepath .IsAbs (migrationPath ) {
662+ migrationPath = filepath .Join (p .config .RootDir , migrationPath )
663+ }
664+ } else {
665+ // Fallback: Try multiple possible migration paths
666+ possiblePaths := []string {
667+ filepath .Join (p .config .RootDir , "migrations" ), // Standard location
668+ filepath .Join (p .config .RootDir , "database" , "migrations" ), // Alternative location
669+ }
670+
671+ for _ , path := range possiblePaths {
672+ if info , err := os .Stat (path ); err == nil && info .IsDir () {
673+ migrationPath = path
674+ break
675+ }
667676 }
668677 }
669678
670- // If no migrations directory exists, create one
679+ // If no migrations directory found, use default
671680 if migrationPath == "" {
672681 migrationPath = filepath .Join (p .config .RootDir , "migrations" )
673- if err := os .MkdirAll (migrationPath , 0755 ); err != nil {
674- return nil , fmt .Errorf ("failed to create migrations directory: %w" , err )
675- }
682+ }
683+
684+ // Create directory if it doesn't exist
685+ if err := os .MkdirAll (migrationPath , 0755 ); err != nil {
686+ return nil , fmt .Errorf ("failed to create migrations directory: %w" , err )
676687 }
677688
678689 // Create migrations collection and discover SQL files
@@ -693,7 +704,29 @@ func (p *DatabasePlugin) loadMigrations() (*migrate.Migrations, error) {
693704}
694705
695706func (p * DatabasePlugin ) getMigrationPath () (string , error ) {
696- // Try multiple possible migration paths
707+ // First priority: Check if migrations_path is configured in .forge.yaml
708+ if p .config != nil && p .config .Database .MigrationsPath != "" {
709+ migrationPath := p .config .Database .MigrationsPath
710+
711+ // Make relative paths absolute based on project root
712+ if ! filepath .IsAbs (migrationPath ) {
713+ migrationPath = filepath .Join (p .config .RootDir , migrationPath )
714+ }
715+
716+ // Check if the configured path exists
717+ if info , err := os .Stat (migrationPath ); err == nil && info .IsDir () {
718+ return migrationPath , nil
719+ }
720+
721+ // If configured but doesn't exist, create it
722+ if err := os .MkdirAll (migrationPath , 0755 ); err != nil {
723+ return "" , fmt .Errorf ("failed to create configured migrations directory %s: %w" , migrationPath , err )
724+ }
725+
726+ return migrationPath , nil
727+ }
728+
729+ // Fallback: Try multiple possible migration paths
697730 possiblePaths := []string {
698731 filepath .Join (p .config .RootDir , "migrations" ), // Standard location
699732 filepath .Join (p .config .RootDir , "database" , "migrations" ), // Alternative location
0 commit comments