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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 93ad4dbd2993e9e0b42afe547312d0c65027dd94a0bb12ec32bd8db9a054e050
4
- data.tar.gz: d7ba34542cd5d9fcc09e6eadeba2147ab00e21245ad41197e9f0697db2c98ba9
3
+ metadata.gz: 7bae784cf88c546a852fea372e8bcbf1356008bc36c9e63c6ff0e18fb1c06bd6
4
+ data.tar.gz: 0fc13227fd92ecb46f7d10f16d900477115a2ca960c701a2080d19690f1631d3
5
5
  SHA512:
6
- metadata.gz: 452cbc36fd51ff0c37e9cc6a4e1bd84ca0ecccee9ba7bb34958c77a96fa7753dc1f02a6d34f4d4bc1e26753f3bf9dfc6c31d9ac4d64a8cd5ad69ea0e4f04a011
7
- data.tar.gz: 54a6f8d64cb267b7906b5c375b09074dd3e6dc1acffa99d33b19335143f2ef29b94843b8f9965b1d3eb4c8453dc1dc362da03da50bca428838f497dd98996e80
6
+ metadata.gz: 226db7dc680bb706a73048c1fec3e52685a1e36ac5d5e2cef82511080234e1cc6b789cb5266ea101669462205823ec565da9b059cc7d4b0752fc4f600f0cfbe2
7
+ data.tar.gz: 47c936d8bb2cddf627dbb04ab8d3993e71a960363d4472c9ef9fa4b2102b89789fea7257333b6b91e38ffe1a288c52b5e72ef619377c97276684a0f46dd04ee1
data/.rubocop.yml CHANGED
@@ -24,3 +24,7 @@ Metrics/BlockLength:
24
24
  Metrics/MethodLength:
25
25
  Exclude:
26
26
  - test/**/*
27
+
28
+ Metrics/ClassLength:
29
+ Exclude:
30
+ - test/**/*
data/Appraisals CHANGED
@@ -6,3 +6,9 @@
6
6
  gem "activesupport", "~> #{version}.0"
7
7
  end
8
8
  end
9
+
10
+ appraise "rails.edge" do
11
+ gem "rails", ">= 7.2.0.beta"
12
+ gem "activerecord", ">= 7.2.0.beta"
13
+ gem "activesupport", ">= 7.2.0.beta"
14
+ end
data/CHANGELOG.md CHANGED
@@ -1,3 +1,10 @@
1
+ ## [0.7.4] - 2024-06-06
2
+ - Rails 7.2 support added
3
+ - Rails 6.0 support added
4
+
5
+ ## [0.7.3] - 2024-04-06
6
+ - add multipe databases support
7
+
1
8
  ## [0.7.2] - 2024-03-30
2
9
  - update title and description in Rubygems
3
10
 
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- actual_db_schema (0.7.2)
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).
@@ -9,5 +9,6 @@ gem "activesupport", "~> 6.0.0"
9
9
  gem "minitest", "~> 5.0"
10
10
  gem "rake"
11
11
  gem "rubocop", "~> 1.21"
12
+ gem "sqlite3", "~> 1.4.0"
12
13
 
13
14
  gemspec path: "../"
@@ -9,5 +9,6 @@ gem "activesupport", "~> 6.1.0"
9
9
  gem "minitest", "~> 5.0"
10
10
  gem "rake"
11
11
  gem "rubocop", "~> 1.21"
12
+ gem "sqlite3", "~> 1.4.0"
12
13
 
13
14
  gemspec path: "../"
@@ -9,5 +9,6 @@ gem "activesupport", "~> 7.0.0"
9
9
  gem "minitest", "~> 5.0"
10
10
  gem "rake"
11
11
  gem "rubocop", "~> 1.21"
12
+ gem "sqlite3", "~> 1.4.0"
12
13
 
13
14
  gemspec path: "../"
@@ -9,5 +9,6 @@ gem "activesupport", "~> 7.1.0"
9
9
  gem "minitest", "~> 5.0"
10
10
  gem "rake"
11
11
  gem "rubocop", "~> 1.21"
12
+ gem "sqlite3", "~> 1.4.0"
12
13
 
13
14
  gemspec path: "../"
@@ -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
- ActiveRecord::Base.connection.migration_context.tap do |c|
28
- c.extend(ActualDbSchema::Patches::MigrationContext)
29
- end
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
- puts "\ndatabase: #{ActiveRecord::Base.connection_db_config.database}\n\n"
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)
@@ -9,6 +9,7 @@ module ActualDbSchema
9
9
 
10
10
  def write(filename)
11
11
  basename = File.basename(filename)
12
+ FileUtils.mkdir_p(folder)
12
13
  FileUtils.copy(filename, folder.join(basename))
13
14
  record_metadata(filename)
14
15
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ActualDbSchema
4
- VERSION = "0.7.2"
4
+ VERSION = "0.7.4"
5
5
  end
@@ -29,12 +29,46 @@ module ActualDbSchema
29
29
  }
30
30
 
31
31
  def self.migrated_folder
32
- Rails.root.join("tmp", "migrated").tap { |folder| FileUtils.mkdir_p(folder) }
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::Commands::Rollback.new.call
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::Commands::List.new.call
14
+ ActualDbSchema.for_each_db_connection do
15
+ ActualDbSchema::Commands::List.new.call
16
+ end
12
17
  end
13
18
 
14
- task _dump: :rollback_branches
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.2
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-03-30 00:00:00.000000000 Z
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.4.21
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.