Skip to content

Commit

Permalink
Merge pull request #859 from eaguad1337/fix/migrate-status
Browse files Browse the repository at this point in the history
add batch number to status command
  • Loading branch information
josephmancuso authored Oct 28, 2023
2 parents 0b0ca18 + eb140ef commit 2288c40
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
11 changes: 7 additions & 4 deletions src/masoniteorm/commands/MigrateStatusCommand.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,20 @@ def handle(self):
)
migration.create_table_if_not_exists()
table = self.table()
table.set_header_row(["Ran?", "Migration"])
table.set_header_row(["Ran?", "Migration", "Batch"])
migrations = []

for migration_file in migration.get_ran_migrations():
for migration_data in migration.get_ran_migrations():
migration_file = migration_data["migration_file"]
batch = migration_data["batch"]

migrations.append(
["<info>Y</info>", f"<comment>{migration_file}</comment>"]
["<info>Y</info>", f"<comment>{migration_file}</comment>", f"<info>{batch}</info>"]
)

for migration_file in migration.get_unran_migrations():
migrations.append(
["<error>N</error>", f"<comment>{migration_file}</comment>"]
["<error>N</error>", f"<comment>{migration_file}</comment>", "<info>-</info>"]
)

table.set_rows(migrations)
Expand Down
12 changes: 10 additions & 2 deletions src/masoniteorm/migrations/Migration.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,16 @@ def get_ran_migrations(self):

database_migrations = self.migration_model.all()
for migration in all_migrations:
if migration in database_migrations.pluck("migration"):
ran.append(migration)
matched_migration = database_migrations.where(
"migration", migration
).first()
if matched_migration:
ran.append(
{
"migration_file": matched_migration.migration,
"batch": matched_migration.batch,
}
)
return ran

def migrate(self, migration="all", output=False):
Expand Down

0 comments on commit 2288c40

Please sign in to comment.