actual_db_schema 0.7.2 → 0.7.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +4 -0
- data/Appraisals +6 -0
- data/CHANGELOG.md +7 -0
- data/Gemfile.lock +5 -1
- data/README.md +23 -1
- data/gemfiles/rails.6.0.gemfile +1 -0
- data/gemfiles/rails.6.1.gemfile +1 -0
- data/gemfiles/rails.7.0.gemfile +1 -0
- data/gemfiles/rails.7.1.gemfile +1 -0
- data/gemfiles/rails.edge.gemfile +15 -0
- data/lib/actual_db_schema/commands/base.rb +13 -8
- data/lib/actual_db_schema/commands/list.rb +10 -1
- data/lib/actual_db_schema/patches/migration_context.rb +0 -1
- data/lib/actual_db_schema/store.rb +1 -0
- data/lib/actual_db_schema/version.rb +1 -1
- data/lib/actual_db_schema.rb +35 -1
- data/lib/tasks/db.rake +8 -3
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7bae784cf88c546a852fea372e8bcbf1356008bc36c9e63c6ff0e18fb1c06bd6
|
4
|
+
data.tar.gz: 0fc13227fd92ecb46f7d10f16d900477115a2ca960c701a2080d19690f1631d3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 226db7dc680bb706a73048c1fec3e52685a1e36ac5d5e2cef82511080234e1cc6b789cb5266ea101669462205823ec565da9b059cc7d4b0752fc4f600f0cfbe2
|
7
|
+
data.tar.gz: 47c936d8bb2cddf627dbb04ab8d3993e71a960363d4472c9ef9fa4b2102b89789fea7257333b6b91e38ffe1a288c52b5e72ef619377c97276684a0f46dd04ee1
|
data/.rubocop.yml
CHANGED
data/Appraisals
CHANGED
data/CHANGELOG.md
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
actual_db_schema (0.7.
|
4
|
+
actual_db_schema (0.7.4)
|
5
5
|
activerecord (>= 6.0.0)
|
6
6
|
activesupport (>= 6.0.0)
|
7
7
|
csv
|
@@ -133,6 +133,8 @@ GEM
|
|
133
133
|
net-smtp (0.4.0)
|
134
134
|
net-protocol
|
135
135
|
nio4r (2.5.9)
|
136
|
+
nokogiri (1.15.4-arm64-darwin)
|
137
|
+
racc (~> 1.4)
|
136
138
|
nokogiri (1.15.4-x86_64-darwin)
|
137
139
|
racc (~> 1.4)
|
138
140
|
nokogiri (1.15.4-x86_64-linux)
|
@@ -204,6 +206,7 @@ GEM
|
|
204
206
|
parser (>= 3.2.1.0)
|
205
207
|
ruby-progressbar (1.13.0)
|
206
208
|
ruby2_keywords (0.0.5)
|
209
|
+
sqlite3 (1.6.8-arm64-darwin)
|
207
210
|
sqlite3 (1.6.8-x86_64-darwin)
|
208
211
|
sqlite3 (1.6.8-x86_64-linux)
|
209
212
|
stringio (3.0.8)
|
@@ -219,6 +222,7 @@ GEM
|
|
219
222
|
zeitwerk (2.6.12)
|
220
223
|
|
221
224
|
PLATFORMS
|
225
|
+
arm64-darwin-23
|
222
226
|
x86_64-darwin-20
|
223
227
|
x86_64-darwin-22
|
224
228
|
x86_64-linux
|
data/README.md
CHANGED
@@ -48,9 +48,11 @@ And then execute:
|
|
48
48
|
|
49
49
|
$ bundle install
|
50
50
|
|
51
|
+
If you cannot commit changes to the repo or Gemfile, consider the local Gemfile installation described in [this post](https://blog.widefix.com/personal-gemfile-for-development/).
|
52
|
+
|
51
53
|
## Usage
|
52
54
|
|
53
|
-
Just run `rails db:migrate` inside the current branch.
|
55
|
+
Just run `rails db:migrate` inside the current branch. It will roll back all phantom migrations for all configured databases in your `database.yml.`
|
54
56
|
|
55
57
|
> [!WARNING]
|
56
58
|
> This solution implies that all migrations are reversible. The irreversible migrations should be solved manually. At the moment, the gem ignores them. You will see warnings in the terminal for each irreversible migrations.
|
@@ -73,6 +75,26 @@ To release a new version do the following in the order:
|
|
73
75
|
- make the commit and push;
|
74
76
|
- 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).
|
75
77
|
|
78
|
+
### Running Tests with Specific Rails Versions
|
79
|
+
|
80
|
+
The following versions can be specifically tested using Appraisal
|
81
|
+
- 6.0
|
82
|
+
- 6.1
|
83
|
+
- 7.0
|
84
|
+
- 7.1
|
85
|
+
- edge
|
86
|
+
|
87
|
+
To run tests with a specific version of Rails using Appraisal:
|
88
|
+
- Run all tests with Rails 6.0:
|
89
|
+
```sh
|
90
|
+
bundle exec appraisal rails.6.0 rake test
|
91
|
+
- Run tests for a specific file:
|
92
|
+
```sh
|
93
|
+
bundle exec appraisal rails.6.0 rake test TEST=test/rake_task_test.rb
|
94
|
+
- Run a specific test:
|
95
|
+
```sh
|
96
|
+
bundle exec appraisal rails.6.0 rake test TEST=test/rake_task_test.rb TESTOPTS="--name=/db::db:rollback_branches#test_0003_keeps/"
|
97
|
+
|
76
98
|
## Contributing
|
77
99
|
|
78
100
|
Bug reports and pull requests are welcome on GitHub at https://github.com/widefix/actual_db_schema. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/widefix/actual_db_schema/blob/master/CODE_OF_CONDUCT.md).
|
data/gemfiles/rails.6.0.gemfile
CHANGED
data/gemfiles/rails.6.1.gemfile
CHANGED
data/gemfiles/rails.7.0.gemfile
CHANGED
data/gemfiles/rails.7.1.gemfile
CHANGED
@@ -0,0 +1,15 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# This file was generated by Appraisal
|
4
|
+
|
5
|
+
source "https://rubygems.org"
|
6
|
+
|
7
|
+
gem "activerecord", ">= 7.2.0.beta"
|
8
|
+
gem "activesupport", ">= 7.2.0.beta"
|
9
|
+
gem "minitest", "~> 5.0"
|
10
|
+
gem "rake"
|
11
|
+
gem "rubocop", "~> 1.21"
|
12
|
+
gem "rails", ">= 7.2.0.beta"
|
13
|
+
gem "sqlite3"
|
14
|
+
|
15
|
+
gemspec path: "../"
|
@@ -9,10 +9,6 @@ module ActualDbSchema
|
|
9
9
|
raise "ActualDbSchema is disabled. Set ActualDbSchema.config[:enabled] = true to enable it."
|
10
10
|
end
|
11
11
|
|
12
|
-
if ActiveRecord::Migration.current_version >= 6
|
13
|
-
ActiveRecord::Tasks::DatabaseTasks.raise_for_multi_db(command: "db:rollback_branches")
|
14
|
-
end
|
15
|
-
|
16
12
|
call_impl
|
17
13
|
end
|
18
14
|
|
@@ -23,10 +19,19 @@ module ActualDbSchema
|
|
23
19
|
end
|
24
20
|
|
25
21
|
def context
|
26
|
-
@context ||=
|
27
|
-
|
28
|
-
|
29
|
-
|
22
|
+
@context ||= fetch_migration_context.tap do |c|
|
23
|
+
c.extend(ActualDbSchema::Patches::MigrationContext)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def fetch_migration_context
|
28
|
+
ar_version = Gem::Version.new(ActiveRecord::VERSION::STRING)
|
29
|
+
if ar_version >= Gem::Version.new("7.2.0") ||
|
30
|
+
(ar_version >= Gem::Version.new("7.1.0") && ar_version.prerelease?)
|
31
|
+
ActiveRecord::Base.connection_pool.migration_context
|
32
|
+
else
|
33
|
+
ActiveRecord::Base.connection.migration_context
|
34
|
+
end
|
30
35
|
end
|
31
36
|
end
|
32
37
|
end
|
@@ -19,11 +19,20 @@ module ActualDbSchema
|
|
19
19
|
puts "\nPhantom migrations\n\n"
|
20
20
|
puts "Below is a list of irrelevant migrations executed in unmerged branches."
|
21
21
|
puts "To bring your database schema up to date, the migrations marked as \"up\" should be rolled back."
|
22
|
-
|
22
|
+
database_path = db_config[:database]
|
23
|
+
puts "\ndatabase: #{database_path}\n\n"
|
23
24
|
puts header.join(" ")
|
24
25
|
puts "-" * separator_width
|
25
26
|
end
|
26
27
|
|
28
|
+
def db_config
|
29
|
+
if ActiveRecord::Base.respond_to?(:connection_db_config)
|
30
|
+
ActiveRecord::Base.connection_db_config.configuration_hash
|
31
|
+
else
|
32
|
+
ActiveRecord::Base.connection_config
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
27
36
|
def separator_width
|
28
37
|
header.map(&:length).sum + (header.size - 1) * 2
|
29
38
|
end
|
@@ -5,7 +5,6 @@ module ActualDbSchema
|
|
5
5
|
# Add new command to roll back the phantom migrations
|
6
6
|
module MigrationContext
|
7
7
|
def rollback_branches
|
8
|
-
ActualDbSchema.failed = []
|
9
8
|
migrations.reverse_each do |migration|
|
10
9
|
migrator = down_migrator_for(migration)
|
11
10
|
migrator.extend(ActualDbSchema::Patches::Migrator)
|
data/lib/actual_db_schema.rb
CHANGED
@@ -29,12 +29,46 @@ module ActualDbSchema
|
|
29
29
|
}
|
30
30
|
|
31
31
|
def self.migrated_folder
|
32
|
-
|
32
|
+
migrated_folders.first
|
33
|
+
end
|
34
|
+
|
35
|
+
def self.migrated_folders
|
36
|
+
return [default_migrated_folder] unless migrations_paths
|
37
|
+
|
38
|
+
Array(migrations_paths).map do |path|
|
39
|
+
if path.end_with?("db/migrate")
|
40
|
+
default_migrated_folder
|
41
|
+
else
|
42
|
+
postfix = path.split("/").last
|
43
|
+
Rails.root.join("tmp", "migrated_#{postfix}")
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
def self.default_migrated_folder
|
49
|
+
Rails.root.join("tmp", "migrated")
|
50
|
+
end
|
51
|
+
|
52
|
+
def self.migrations_paths
|
53
|
+
if ActiveRecord::Base.respond_to?(:connection_db_config)
|
54
|
+
ActiveRecord::Base.connection_db_config.migrations_paths
|
55
|
+
else
|
56
|
+
ActiveRecord::Base.connection_config[:migrations_paths]
|
57
|
+
end
|
33
58
|
end
|
34
59
|
|
35
60
|
def self.migration_filename(fullpath)
|
36
61
|
fullpath.split("/").last
|
37
62
|
end
|
63
|
+
|
64
|
+
def self.for_each_db_connection
|
65
|
+
configs = ActiveRecord::Base.configurations.configs_for(env_name: ActiveRecord::Tasks::DatabaseTasks.env)
|
66
|
+
configs.each do |db_config|
|
67
|
+
config = db_config.respond_to?(:config) ? db_config.config : db_config
|
68
|
+
ActiveRecord::Base.establish_connection(config)
|
69
|
+
yield
|
70
|
+
end
|
71
|
+
end
|
38
72
|
end
|
39
73
|
|
40
74
|
ActiveRecord::MigrationProxy.prepend(ActualDbSchema::Patches::MigrationProxy)
|
data/lib/tasks/db.rake
CHANGED
@@ -3,13 +3,18 @@
|
|
3
3
|
namespace :db do
|
4
4
|
desc "Rollback migrations that were run inside not a merged branch."
|
5
5
|
task rollback_branches: :load_config do
|
6
|
-
ActualDbSchema
|
6
|
+
ActualDbSchema.failed = []
|
7
|
+
ActualDbSchema.for_each_db_connection do
|
8
|
+
ActualDbSchema::Commands::Rollback.new.call
|
9
|
+
end
|
7
10
|
end
|
8
11
|
|
9
12
|
desc "List all phantom migrations - non-relevant migrations that were run inside not a merged branch."
|
10
13
|
task phantom_migrations: :load_config do
|
11
|
-
ActualDbSchema
|
14
|
+
ActualDbSchema.for_each_db_connection do
|
15
|
+
ActualDbSchema::Commands::List.new.call
|
16
|
+
end
|
12
17
|
end
|
13
18
|
|
14
|
-
task
|
19
|
+
task "schema:dump" => :rollback_branches
|
15
20
|
end
|
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.4
|
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-06-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
@@ -131,6 +131,7 @@ files:
|
|
131
131
|
- gemfiles/rails.6.1.gemfile
|
132
132
|
- gemfiles/rails.7.0.gemfile
|
133
133
|
- gemfiles/rails.7.1.gemfile
|
134
|
+
- gemfiles/rails.edge.gemfile
|
134
135
|
- lib/actual_db_schema.rb
|
135
136
|
- lib/actual_db_schema/commands/base.rb
|
136
137
|
- lib/actual_db_schema/commands/list.rb
|
@@ -166,7 +167,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
166
167
|
- !ruby/object:Gem::Version
|
167
168
|
version: '0'
|
168
169
|
requirements: []
|
169
|
-
rubygems_version: 3.
|
170
|
+
rubygems_version: 3.3.26
|
170
171
|
signing_key:
|
171
172
|
specification_version: 4
|
172
173
|
summary: Keep your DB and schema.rb consistent in dev branches.
|