actual_db_schema 0.7.8 → 0.7.9

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1d2364e9f753a0515b61cfc7598a8479af8e6819a54ce9c103b44572bd09f7a2
4
- data.tar.gz: 9d0e8b6a73e4f94b9beeb73d799053be6745b17804f93acbf3f0e09c6a7142f0
3
+ metadata.gz: 5a0d117f27b4bd908cbc04b0d3ca0faf0297a5feed5fd4f869c5672a50fc3cd9
4
+ data.tar.gz: cf0f37bc743eb44c8c5f6350454cc7f84f1781c8a8bc06ef25eb878830d7b973
5
5
  SHA512:
6
- metadata.gz: 32b066503c2e9aa938552be473b4f8959022d022de6c743791f885781f6a1e585c83d1a1e635d78ffa378fdd0de828c5496c7f55c43638e16319aac74b2d39ac
7
- data.tar.gz: 329e032b35b735a1b5fc0a3ffd4c7be8ebb9d98aca4469012321faa562cb6f46455996ad9bcc47d271ab2dd276ca5d5abad15af9b3da77b08c2612cc9936ebb1
6
+ metadata.gz: 50f4a4cd52039cd29d308676028a51fd7f44e25b89084e03c2ca570361c3c556f13bc924989415d04164967b63aadf0d88709c0f58289947fd2cf6a164f7f6dc
7
+ data.tar.gz: bd471eb79d28d9cf124452fe6e5608eb2a092800b4c49f1299348adf7a7c2a9d6a9bcd85da3f0cc6272753f743862e84b9777bab0cf095def8b9d1180a910e49
data/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
+ ## [0.7.9] - 2024-09-07
2
+ - Don't stop if a phantom migration rollback fails
3
+ - Improve failed rollback of phantom migrations report
4
+
1
5
  ## [0.7.8] - 2024-08-07
2
6
  - Make UI working without assets pipeline
3
7
 
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- actual_db_schema (0.7.8)
4
+ actual_db_schema (0.7.9)
5
5
  activerecord
6
6
  activesupport
7
7
  csv
data/README.md CHANGED
@@ -122,7 +122,8 @@ To release a new version do the following in the order:
122
122
  - update the CHANGELOG;
123
123
  - `bundle install` to update `Gemfile.lock`;
124
124
  - make the commit and push;
125
- - run `bundle exec rake release`. This will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
125
+ - run `bundle exec rake release`. This will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org);
126
+ - [announce the new release on GitHub](https://github.com/widefix/actual_db_schema/releases).
126
127
 
127
128
  ### Running Tests with Specific Rails Versions
128
129
 
@@ -4,6 +4,12 @@ module ActualDbSchema
4
4
  module Commands
5
5
  # Rolls back all phantom migrations
6
6
  class Rollback < Base
7
+ UNICODE_COLORS = {
8
+ red: 31,
9
+ green: 32,
10
+ yellow: 33
11
+ }.freeze
12
+
7
13
  def initialize(context, manual_mode: false)
8
14
  @manual_mode = manual_mode || manual_mode_default?
9
15
  super(context)
@@ -16,16 +22,46 @@ module ActualDbSchema
16
22
 
17
23
  return if ActualDbSchema.failed.empty?
18
24
 
25
+ puts_preamble
26
+ puts_into
19
27
  puts ""
20
- puts "[ActualDbSchema] Irreversible migrations were found from other branches. Roll them back or fix manually:"
28
+ puts failed_migrations_list
29
+ puts_preamble
30
+ end
31
+
32
+ def failed_migrations_list
33
+ ActualDbSchema.failed.map.with_index(1) do |failed, index|
34
+ filename = failed.short_filename
35
+ exception = failed.exception
36
+ <<~MSG
37
+ \t#{colorize("[Migration##{index}]", :yellow)}
38
+ \t- #{filename}
39
+
40
+ \t\t#{exception.inspect.gsub("\n", "\n\t ")}
41
+ MSG
42
+ end
43
+ end
44
+
45
+ def puts_preamble
21
46
  puts ""
22
- puts ActualDbSchema.failed.map { |migration| "- #{migration.filename}" }.join("\n")
47
+ puts %(\u2757\u2757\u2757 #{colorize("[ActualDbSchema]", :red)})
23
48
  puts ""
24
49
  end
25
50
 
51
+ def puts_into
52
+ msg = "#{ActualDbSchema.failed.count} phantom migration(s) could not be rolled back automatically."
53
+ msg += " Roll them back or fix manually:"
54
+ puts colorize(msg, :red)
55
+ end
56
+
26
57
  def manual_mode_default?
27
58
  ActualDbSchema.config[:auto_rollback_disabled]
28
59
  end
60
+
61
+ def colorize(text, color)
62
+ code = UNICODE_COLORS.fetch(color, 37)
63
+ "\e[#{code}m#{text}\e[0m"
64
+ end
29
65
  end
30
66
  end
31
67
  end
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ActualDbSchema
4
+ FailedMigration = Struct.new(:migration, :exception, keyword_init: true) do
5
+ def filename
6
+ migration.filename
7
+ end
8
+
9
+ def short_filename
10
+ migration.filename.sub(File.join(Rails.root, "/"), "")
11
+ end
12
+ end
13
+ end
@@ -11,7 +11,7 @@ module ActualDbSchema
11
11
  show_info_for(migration) if manual_mode
12
12
  migrate(migration) if !manual_mode || user_wants_rollback?
13
13
  rescue StandardError => e
14
- handle_migration_error(e, migration)
14
+ ActualDbSchema.failed << FailedMigration.new(migration: migration, exception: e)
15
15
  end
16
16
  end
17
17
 
@@ -71,12 +71,6 @@ module ActualDbSchema
71
71
  puts File.read(migration.filename)
72
72
  end
73
73
 
74
- def handle_migration_error(error, migration)
75
- raise unless error.message.include?("ActiveRecord::IrreversibleMigration")
76
-
77
- ActualDbSchema.failed << migration
78
- end
79
-
80
74
  def migrate(migration)
81
75
  migrator = down_migrator_for(migration)
82
76
  migrator.extend(ActualDbSchema::Patches::Migrator)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ActualDbSchema
4
- VERSION = "0.7.8"
4
+ VERSION = "0.7.9"
5
5
  end
@@ -7,6 +7,7 @@ require_relative "actual_db_schema/git"
7
7
  require_relative "actual_db_schema/store"
8
8
  require_relative "actual_db_schema/version"
9
9
  require_relative "actual_db_schema/migration"
10
+ require_relative "actual_db_schema/failed_migration"
10
11
  require_relative "actual_db_schema/migration_context"
11
12
  require_relative "actual_db_schema/patches/migration_proxy"
12
13
  require_relative "actual_db_schema/patches/migrator"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: actual_db_schema
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.8
4
+ version: 0.7.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrei Kaleshka
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-08-07 00:00:00.000000000 Z
11
+ date: 2024-09-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -146,6 +146,7 @@ files:
146
146
  - lib/actual_db_schema/commands/list.rb
147
147
  - lib/actual_db_schema/commands/rollback.rb
148
148
  - lib/actual_db_schema/engine.rb
149
+ - lib/actual_db_schema/failed_migration.rb
149
150
  - lib/actual_db_schema/git.rb
150
151
  - lib/actual_db_schema/migration.rb
151
152
  - lib/actual_db_schema/migration_context.rb