actual_db_schema 0.2.0 → 0.4.0

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: ba9797cc49da84c28977ef23e93bb8f76a34176614fa12deb3f2e7787dcb880e
4
- data.tar.gz: 502f59630d933d643df14de7e50c72c84b4fe00bf8ff0034bb01c604e8d2c343
3
+ metadata.gz: 2f452edc8daa863317285713926ed63c23141523bb4072d5d92efaf512c95023
4
+ data.tar.gz: 21d4189566b38353dc93f5f58acec5a343ef8553736f8e119263b4606672082f
5
5
  SHA512:
6
- metadata.gz: d0e6ad5b607a3ff67243b5e2ec8d8fa6863068f0e63118de3a2dbda3922892e5c73e036c1c0da7693a7ab427fe923fe82b214adb8640352848c87545f1e8862d
7
- data.tar.gz: 8a47aec7467625c6e68e8d35fd2f5035863d8556e7da9e6cce13931d27a06acae823e2beb186286cc62eab0c636e80af866ffcac0e1fab8c3667c89fc76b962c
6
+ metadata.gz: a591d53c12d6d26993ff7ffaebf12ee4fc2cfd183a04bae10f32d1f7b514dcbdc0b012349f0b2f6fc392d724fcba1ecc6981a6f8f5f0c69222eb0c91290f1397
7
+ data.tar.gz: c9251df1909fbd42a722ae7f62b3dfbcf40ff5cc669fc3a6eac992a322d91fd96c31d476a6adac0324bf21d9420e2f91bd5f08c910fb833dfb57841af7e84e73
data/CHANGELOG.md CHANGED
@@ -1,3 +1,11 @@
1
+ ## [0.4.0] - 2023-07-05
2
+
3
+ - rollback migrations in the reversed order
4
+
5
+ ## [0.3.0] - 2023-01-23
6
+
7
+ - add Rails 6 and older support
8
+
1
9
  ## [0.2.0] - 2022-10-19
2
10
 
3
11
  - Catch exceptions about irreversible migrations and show a warning
data/Gemfile.lock CHANGED
@@ -1,25 +1,25 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- actual_db_schema (0.2.0)
4
+ actual_db_schema (0.4.0)
5
5
  activerecord
6
6
 
7
7
  GEM
8
8
  remote: https://rubygems.org/
9
9
  specs:
10
- activemodel (7.0.4)
11
- activesupport (= 7.0.4)
12
- activerecord (7.0.4)
13
- activemodel (= 7.0.4)
14
- activesupport (= 7.0.4)
15
- activesupport (7.0.4)
10
+ activemodel (7.0.6)
11
+ activesupport (= 7.0.6)
12
+ activerecord (7.0.6)
13
+ activemodel (= 7.0.6)
14
+ activesupport (= 7.0.6)
15
+ activesupport (7.0.6)
16
16
  concurrent-ruby (~> 1.0, >= 1.0.2)
17
17
  i18n (>= 1.6, < 2)
18
18
  minitest (>= 5.1)
19
19
  tzinfo (~> 2.0)
20
20
  ast (2.4.2)
21
- concurrent-ruby (1.1.10)
22
- i18n (1.12.0)
21
+ concurrent-ruby (1.2.2)
22
+ i18n (1.14.1)
23
23
  concurrent-ruby (~> 1.0)
24
24
  json (2.6.2)
25
25
  minitest (5.16.3)
@@ -43,7 +43,7 @@ GEM
43
43
  rubocop-ast (1.21.0)
44
44
  parser (>= 3.1.1.0)
45
45
  ruby-progressbar (1.11.0)
46
- tzinfo (2.0.5)
46
+ tzinfo (2.0.6)
47
47
  concurrent-ruby (~> 1.0)
48
48
  unicode-display_width (2.3.0)
49
49
 
data/README.md CHANGED
@@ -1,3 +1,5 @@
1
+ [![Gem Version](https://badge.fury.io/rb/actual_db_schema.svg)](https://badge.fury.io/rb/actual_db_schema)
2
+
1
3
  # ActualDbSchema
2
4
 
3
5
  Keep Rails DB schema consistent while switching between branches with no additional actions.
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ActualDbSchema
4
- VERSION = "0.2.0"
4
+ VERSION = "0.4.0"
5
5
  end
data/lib/tasks/db.rake CHANGED
@@ -39,8 +39,8 @@ module ActualDbSchema
39
39
  # Add new command to roll back the phantom migrations
40
40
  module MigrationContextPatch
41
41
  def rollback_branches
42
- migrations.each do |migration|
43
- migrator = ActiveRecord::Migrator.new(:down, [migration], schema_migration, migration.version)
42
+ migrations.reverse_each do |migration|
43
+ migrator = down_migrator_for(migration)
44
44
  migrator.extend(ActualDbSchema::MigratorPatch)
45
45
  migrator.migrate
46
46
  rescue StandardError => e
@@ -52,13 +52,21 @@ module ActualDbSchema
52
52
 
53
53
  private
54
54
 
55
+ def down_migrator_for(migration)
56
+ if ActiveRecord::Migration.current_version < 6
57
+ ActiveRecord::Migrator.new(:down, [migration], migration.version)
58
+ else
59
+ ActiveRecord::Migrator.new(:down, [migration], schema_migration, migration.version)
60
+ end
61
+ end
62
+
55
63
  def migration_files
56
64
  paths = Array(migrations_paths)
57
65
  current_branch_files = Dir[*paths.flat_map { |path| "#{path}/**/[0-9]*_*.rb" }]
58
66
  other_branches_files = Dir["#{migrated_folder}/**/[0-9]*_*.rb"]
59
67
 
60
- current_branch_file_names = current_branch_files.map { migration_filename(_1) }
61
- other_branches_files.reject { migration_filename(_1).in?(current_branch_file_names) }
68
+ current_branch_file_names = current_branch_files.map { |f| migration_filename(f) }
69
+ other_branches_files.reject { |f| migration_filename(f).in?(current_branch_file_names) }
62
70
  end
63
71
  end
64
72
  end
@@ -68,7 +76,9 @@ ActiveRecord::MigrationProxy.prepend(ActualDbSchema::MigrationProxyPatch)
68
76
  namespace :db do
69
77
  desc "Rollback migrations that were run inside not a merged branch."
70
78
  task rollback_branches: :load_config do
71
- ActiveRecord::Tasks::DatabaseTasks.raise_for_multi_db(command: "db:rollback_branches")
79
+ if ActiveRecord::Migration.current_version >= 6
80
+ ActiveRecord::Tasks::DatabaseTasks.raise_for_multi_db(command: "db:rollback_branches")
81
+ end
72
82
 
73
83
  context = ActiveRecord::Base.connection.migration_context
74
84
  context.extend(ActualDbSchema::MigrationContextPatch)
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.2.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrei Kaleshka
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-10-19 00:00:00.000000000 Z
11
+ date: 2023-07-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord