actual_db_schema 0.7.8 → 0.7.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/Gemfile.lock +1 -1
- data/README.md +2 -1
- data/lib/actual_db_schema/commands/rollback.rb +38 -2
- data/lib/actual_db_schema/failed_migration.rb +13 -0
- data/lib/actual_db_schema/patches/migration_context.rb +1 -7
- data/lib/actual_db_schema/version.rb +1 -1
- data/lib/actual_db_schema.rb +1 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5a0d117f27b4bd908cbc04b0d3ca0faf0297a5feed5fd4f869c5672a50fc3cd9
|
4
|
+
data.tar.gz: cf0f37bc743eb44c8c5f6350454cc7f84f1781c8a8bc06ef25eb878830d7b973
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 50f4a4cd52039cd29d308676028a51fd7f44e25b89084e03c2ca570361c3c556f13bc924989415d04164967b63aadf0d88709c0f58289947fd2cf6a164f7f6dc
|
7
|
+
data.tar.gz: bd471eb79d28d9cf124452fe6e5608eb2a092800b4c49f1299348adf7a7c2a9d6a9bcd85da3f0cc6272753f743862e84b9777bab0cf095def8b9d1180a910e49
|
data/CHANGELOG.md
CHANGED
data/Gemfile.lock
CHANGED
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
|
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
|
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
|
-
|
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)
|
data/lib/actual_db_schema.rb
CHANGED
@@ -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.
|
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-
|
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
|