@@ -453,72 +453,74 @@ defmodule AshPostgres.DataLayer do
453453 migrations_path = AshPostgres.Mix.Helpers . migrations_path ( [ ] , repo )
454454 tenant_migrations_path = AshPostgres.Mix.Helpers . tenant_migrations_path ( [ ] , repo )
455455
456- current_migrations =
457- Ecto.Query . from ( row in "schema_migrations" ,
458- select: row . version
459- )
460- |> repo . all ( )
461- |> Enum . map ( & to_string / 1 )
456+ if "--tenants" not in args do
457+ current_migrations =
458+ Ecto.Query . from ( row in "schema_migrations" ,
459+ select: row . version
460+ )
461+ |> repo . all ( )
462+ |> Enum . map ( & to_string / 1 )
463+
464+ files =
465+ migrations_path
466+ |> Path . join ( "**/*.exs" )
467+ |> Path . wildcard ( )
468+ |> Enum . sort ( )
469+ |> Enum . reverse ( )
470+ |> Enum . filter ( fn file ->
471+ Enum . any? ( current_migrations , & String . starts_with? ( Path . basename ( file ) , & 1 ) )
472+ end )
473+ |> Enum . take ( 20 )
474+ |> Enum . map ( & String . trim_leading ( & 1 , migrations_path ) )
475+ |> Enum . map ( & String . trim_leading ( & 1 , "/" ) )
476+
477+ indexed =
478+ files
479+ |> Enum . with_index ( )
480+ |> Enum . map ( fn { file , index } -> "#{ index + 1 } : #{ file } " end )
481+
482+ to =
483+ Mix . shell ( ) . prompt (
484+ """
485+ How many migrations should be rolled back#{ for_repo } ? (default: 0)
486+
487+ Last 20 migration names, with the input you must provide to
488+ rollback up to *and including* that migration:
489+
490+ #{ Enum . join ( indexed , "\n " ) }
491+ Rollback to:
492+ """
493+ |> String . trim_trailing ( )
494+ )
495+ |> String . trim ( )
496+ |> case do
497+ "" ->
498+ nil
462499
463- files =
464- migrations_path
465- |> Path . join ( "**/*.exs" )
466- |> Path . wildcard ( )
467- |> Enum . sort ( )
468- |> Enum . reverse ( )
469- |> Enum . filter ( fn file ->
470- Enum . any? ( current_migrations , & String . starts_with? ( Path . basename ( file ) , & 1 ) )
471- end )
472- |> Enum . take ( 20 )
473- |> Enum . map ( & String . trim_leading ( & 1 , migrations_path ) )
474- |> Enum . map ( & String . trim_leading ( & 1 , "/" ) )
475-
476- indexed =
477- files
478- |> Enum . with_index ( )
479- |> Enum . map ( fn { file , index } -> "#{ index + 1 } : #{ file } " end )
480-
481- to =
482- Mix . shell ( ) . prompt (
483- """
484- How many migrations should be rolled back#{ for_repo } ? (default: 0)
485-
486- Last 20 migration names, with the input you must provide to
487- rollback up to *and including* that migration:
488-
489- #{ Enum . join ( indexed , "\n " ) }
490- Rollback to:
491- """
492- |> String . trim_trailing ( )
493- )
494- |> String . trim ( )
495- |> case do
496- "" ->
497- nil
498-
499- "0" ->
500- nil
501-
502- n ->
503- try do
504- files
505- |> Enum . at ( String . to_integer ( n ) - 1 )
506- rescue
507- _ ->
508- reraise "Required an integer value, got: #{ n } " , __STACKTRACE__
509- end
510- |> String . split ( "_" , parts: 2 )
511- |> Enum . at ( 0 )
512- |> String . to_integer ( )
513- end
500+ "0" ->
501+ nil
514502
515- if to do
516- Mix.Task . run (
517- "ash_postgres.rollback" ,
518- args ++ [ "-r" , inspect ( repo ) , "--to" , to_string ( to ) ]
519- )
503+ n ->
504+ try do
505+ files
506+ |> Enum . at ( String . to_integer ( n ) - 1 )
507+ rescue
508+ _ ->
509+ reraise "Required an integer value, got: #{ n } " , __STACKTRACE__
510+ end
511+ |> String . split ( "_" , parts: 2 )
512+ |> Enum . at ( 0 )
513+ |> String . to_integer ( )
514+ end
520515
521- Mix.Task . reenable ( "ash_postgres.rollback" )
516+ if to do
517+ Mix.Task . run (
518+ "ash_postgres.rollback" ,
519+ args ++ [ "-r" , inspect ( repo ) , "--to" , to_string ( to ) ]
520+ )
521+
522+ Mix.Task . reenable ( "ash_postgres.rollback" )
523+ end
522524 end
523525
524526 tenant_files =
@@ -599,7 +601,7 @@ defmodule AshPostgres.DataLayer do
599601 if to do
600602 Mix.Task . run (
601603 "ash_postgres.rollback" ,
602- args ++ [ "--tenants" , "-r" , inspect ( repo ) , "--to" , to ]
604+ args ++ [ "--tenants" , "-r" , inspect ( repo ) , "--to" , to_string ( to ) ]
603605 )
604606
605607 Mix.Task . reenable ( "ash_postgres.rollback" )
0 commit comments