actual_db_schema 0.7.2 → 0.7.3

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: ca3780aca89ac715ade8441154b10a78b258514b3daa1d23db1ede9d37d63108
4
+ data.tar.gz: cb4ce56d44d5a5c61d20220ab2ead11830db440438e1dd433d0774cdf23aef97
5
5
  SHA512:
6
- metadata.gz: 452cbc36fd51ff0c37e9cc6a4e1bd84ca0ecccee9ba7bb34958c77a96fa7753dc1f02a6d34f4d4bc1e26753f3bf9dfc6c31d9ac4d64a8cd5ad69ea0e4f04a011
7
- data.tar.gz: 54a6f8d64cb267b7906b5c375b09074dd3e6dc1acffa99d33b19335143f2ef29b94843b8f9965b1d3eb4c8453dc1dc362da03da50bca428838f497dd98996e80
6
+ metadata.gz: bf59099adf9a660b934fc65c3573460c4034e59876f0770691019799601217b6eeee29b9f3eda43d1ea837380d6da2bb2930819b81dbc9eb334c6bc2f4e4777c
7
+ data.tar.gz: 8c9f16c0bf8f0571f163bcf07a73fe4b62dc4c031897d2d156e234aac3d4ca749a6380a41e983c5dec722d61909b0aaf09caf1f3b2303f885bc76385da6b1039
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/CHANGELOG.md CHANGED
@@ -1,3 +1,6 @@
1
+ ## [0.7.3] - 2024-04-06
2
+ - add multipe databases support
3
+
1
4
  ## [0.7.2] - 2024-03-30
2
5
  - update title and description in Rubygems
3
6
 
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.3)
5
5
  activerecord (>= 6.0.0)
6
6
  activesupport (>= 6.0.0)
7
7
  csv
data/README.md CHANGED
@@ -48,6 +48,8 @@ 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
55
  Just run `rails db:migrate` inside the current branch.
@@ -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: "../"
@@ -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
 
@@ -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.3"
5
5
  end
@@ -29,12 +29,41 @@ 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
+ ActiveRecord::Base.connection_db_config.migrations_paths
33
54
  end
34
55
 
35
56
  def self.migration_filename(fullpath)
36
57
  fullpath.split("/").last
37
58
  end
59
+
60
+ def self.for_each_db_connection
61
+ configs = ActiveRecord::Base.configurations.configs_for(env_name: ActiveRecord::Tasks::DatabaseTasks.env)
62
+ configs.each do |db_config|
63
+ ActiveRecord::Base.establish_connection(db_config)
64
+ yield
65
+ end
66
+ end
38
67
  end
39
68
 
40
69
  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.3
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-05-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -166,7 +166,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
166
166
  - !ruby/object:Gem::Version
167
167
  version: '0'
168
168
  requirements: []
169
- rubygems_version: 3.4.21
169
+ rubygems_version: 3.3.3
170
170
  signing_key:
171
171
  specification_version: 4
172
172
  summary: Keep your DB and schema.rb consistent in dev branches.