Skip to content

Commit

Permalink
fix cop
Browse files Browse the repository at this point in the history
  • Loading branch information
ka8725 committed Sep 6, 2024
1 parent 93167c7 commit 39ff82d
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 18 deletions.
40 changes: 22 additions & 18 deletions lib/actual_db_schema/commands/rollback.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ module ActualDbSchema
module Commands
# Rolls back all phantom migrations
class Rollback < Base
UNICODE_COLORS = {
red: 31,
green: 32,
yellow: 33
}.freeze

def initialize(context, manual_mode: false)
@manual_mode = manual_mode || manual_mode_default?
super(context)
Expand All @@ -16,14 +22,11 @@ def call_impl

return if ActualDbSchema.failed.empty?

puts ""
puts "\u2757\u2757\u2757 #{colorize('[ActualDbSchema]', :red)}"
puts ""
puts colorize("#{ActualDbSchema.failed.count} phantom migration(s) could not be rolled back automatically. Roll them back or fix manually:", :red)
puts_preamble
puts_into
puts ""
puts failed_migrations_list
puts "\u2757\u2757\u2757 #{colorize('[ActualDbSchema]', :red)}"
puts ""
puts_preamble
end

def failed_migrations_list
Expand All @@ -39,23 +42,24 @@ def failed_migrations_list
end
end

def puts_preamble
puts ""
puts %(\u2757\u2757\u2757 #{colorize("[ActualDbSchema]", :red)})
puts ""
end

def puts_into
msg = "#{ActualDbSchema.failed.count} phantom migration(s) could not be rolled back automatically."
msg += " Roll them back or fix manually:"
puts colorize(msg, :red)
end

def manual_mode_default?
ActualDbSchema.config[:auto_rollback_disabled]
end

def colorize(text, color)
code =
case color
when :red
31
when :green
32
when :yellow
33
else
37
end

code = UNICODE_COLORS.fetch(color, 37)
"\e[#{code}m#{text}\e[0m"
end
end
Expand Down
2 changes: 2 additions & 0 deletions lib/actual_db_schema/failed_migration.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module ActualDbSchema
FailedMigration = Struct.new(:migration, :exception, keyword_init: true) do
def filename
Expand Down

0 comments on commit 39ff82d

Please sign in to comment.