@@ -447,7 +447,7 @@ defmodule AshPostgres.DataLayer do
447
447
|> Enum . sort ( )
448
448
|> Enum . reverse ( )
449
449
|> Enum . filter ( fn file ->
450
- Enum . any? ( current_migrations , & String . starts_with? ( file , & 1 ) )
450
+ Enum . any? ( current_migrations , & String . starts_with? ( Path . basename ( file ) , & 1 ) )
451
451
end )
452
452
|> Enum . take ( 20 )
453
453
|> Enum . map ( & String . trim_leading ( & 1 , migrations_path ) )
@@ -484,31 +484,37 @@ defmodule AshPostgres.DataLayer do
484
484
Mix.Task . run ( "ash_postgres.rollback" , args ++ [ "-r" , inspect ( repo ) , "-n" , to_string ( n ) ] )
485
485
Mix.Task . reenable ( "ash_postgres.rollback" )
486
486
487
- first_tenant = repo . list_tenants ( ) |> Enum . at ( 0 )
487
+ tenant_files =
488
+ tenant_migrations_path
489
+ |> Path . join ( "**/*.exs" )
490
+ |> Path . wildcard ( )
491
+ |> Enum . sort ( )
492
+ |> Enum . reverse ( )
493
+
494
+ if ! Enum . empty? ( tenant_files ) do
495
+ first_tenant = repo . all_tenants ( ) |> Enum . at ( 0 )
496
+
497
+ if first_tenant do
498
+ current_tenant_migrations =
499
+ Ecto.Query . from ( row in "schema_migrations" ,
500
+ select: row . version
501
+ )
502
+ |> repo . all ( prefix: first_tenant )
503
+ |> Enum . map ( & to_string / 1 )
504
+
505
+ tenant_files =
506
+ tenant_files
507
+ |> Enum . filter ( fn file ->
508
+ Enum . any? (
509
+ current_tenant_migrations ,
510
+ & String . starts_with? ( Path . basename ( file ) , & 1 )
511
+ )
512
+ end )
513
+ |> Enum . take ( 20 )
514
+ |> Enum . map ( & String . trim_leading ( & 1 , tenant_migrations_path ) )
515
+ |> Enum . with_index ( )
516
+ |> Enum . map ( fn { file , index } -> "#{ index + 1 } : #{ file } " end )
488
517
489
- if first_tenant do
490
- current_tenant_migrations =
491
- Ecto.Query . from ( row in "schema_migrations" ,
492
- select: row . version
493
- )
494
- |> repo . all ( prefix: first_tenant )
495
- |> Enum . map ( & to_string / 1 )
496
-
497
- tenant_files =
498
- tenant_migrations_path
499
- |> Path . join ( "**/*.exs" )
500
- |> Path . wildcard ( )
501
- |> Enum . sort ( )
502
- |> Enum . reverse ( )
503
- |> Enum . filter ( fn file ->
504
- Enum . any? ( current_tenant_migrations , & String . starts_with? ( file , & 1 ) )
505
- end )
506
- |> Enum . take ( 20 )
507
- |> Enum . map ( & String . trim_leading ( & 1 , tenant_migrations_path ) )
508
- |> Enum . with_index ( )
509
- |> Enum . map ( fn { file , index } -> "#{ index + 1 } : #{ file } " end )
510
-
511
- if ! Enum . empty? ( tenant_files ) do
512
518
n =
513
519
Mix . shell ( ) . prompt (
514
520
"""
@@ -565,13 +571,7 @@ defmodule AshPostgres.DataLayer do
565
571
566
572
[ ]
567
573
|> AshPostgres.Mix.Helpers . repos! ( args )
568
- |> Enum . all? ( fn repo ->
569
- [ ]
570
- |> AshPostgres.Mix.Helpers . tenant_migrations_path ( repo )
571
- |> Path . join ( "**/*.exs" )
572
- |> Path . wildcard ( )
573
- |> Enum . empty? ( )
574
- end )
574
+ |> Enum . all? ( & ( not has_tenant_migrations? ( & 1 ) ) )
575
575
|> case do
576
576
true ->
577
577
:ok
@@ -586,6 +586,14 @@ defmodule AshPostgres.DataLayer do
586
586
Mix.Task . run ( "ash_postgres.drop" , args )
587
587
end
588
588
589
+ defp has_tenant_migrations? ( repo ) do
590
+ [ ]
591
+ |> AshPostgres.Mix.Helpers . tenant_migrations_path ( repo )
592
+ |> Path . join ( "**/*.exs" )
593
+ |> Path . wildcard ( )
594
+ |> Enum . empty? ( )
595
+ end
596
+
589
597
import Ecto.Query , only: [ from: 2 , subquery: 1 ]
590
598
591
599
@ impl true
0 commit comments