actual_db_schema 0.7.1 → 0.7.3

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: eac7885f8774402bb8f0532caf66d4304df61be50ef0c22f1fd8f6ef325b8330
4
- data.tar.gz: 8c90d4101e41941a4c247f6af2695e050f450a46435b659c99e1d5fe8fd71929
3
+ metadata.gz: ca3780aca89ac715ade8441154b10a78b258514b3daa1d23db1ede9d37d63108
4
+ data.tar.gz: cb4ce56d44d5a5c61d20220ab2ead11830db440438e1dd433d0774cdf23aef97
5
5
  SHA512:
6
- metadata.gz: 794038e111d31a3e99b1a48c3c3a0603498e6492e8b2a8f050d4e9e481debe047d908ff5cae5940789c96c3d76da13a10a841c55834275392e0d08076b4b6b52
7
- data.tar.gz: 342ba459e1705c42a64d0f476c50054724a48b212bbba79a82f85a1a4118ac342bac7d0ebab3158bcab58f5d6068c1e4f344f813a6464091e20545815ff09dc3
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,9 @@
1
+ ## [0.7.3] - 2024-04-06
2
+ - add multipe databases support
3
+
4
+ ## [0.7.2] - 2024-03-30
5
+ - update title and description in Rubygems
6
+
1
7
  ## [0.7.1] - 2024-03-19
2
8
 
3
9
  - add csv as a dependency since Ruby 3.3 has removed it from the standard library
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- actual_db_schema (0.7.1)
4
+ actual_db_schema (0.7.3)
5
5
  activerecord (>= 6.0.0)
6
6
  activesupport (>= 6.0.0)
7
7
  csv
@@ -93,7 +93,7 @@ GEM
93
93
  concurrent-ruby (1.2.2)
94
94
  connection_pool (2.4.1)
95
95
  crass (1.0.6)
96
- csv (3.2.8)
96
+ csv (3.3.0)
97
97
  date (3.3.3)
98
98
  debug (1.8.0)
99
99
  irb (>= 1.5.0)
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.
@@ -8,20 +8,19 @@ Gem::Specification.new do |spec|
8
8
  spec.authors = ["Andrei Kaleshka"]
9
9
  spec.email = ["ka8725@gmail.com"]
10
10
 
11
- spec.summary = "Keep your DB clean and consistent between branches."
11
+ spec.summary = "Keep your DB and schema.rb consistent in dev branches."
12
12
  spec.description = <<~DESC
13
- Switching between branches with migrations and running them can make your DB inconsistent
14
- and not working in another branch if not roll the migration back.
15
- Install this gem and forget about that issue by running the standard rake db:migrate.
13
+ Wipe out inconsistent DB and schema.rb when switching branches.
14
+ Just install this gem and use the standard rake db:migrate command.
16
15
  DESC
17
- spec.homepage = "https://github.com/widefix/actual_db_schema"
16
+ spec.homepage = "https://blog.widefix.com/actual-db-schema/"
18
17
  spec.license = "MIT"
19
18
  spec.required_ruby_version = ">= 2.7.0"
20
19
 
21
20
  # spec.metadata["allowed_push_host"] = "TODO: Set to your gem server 'https://example.com'"
22
21
 
23
22
  spec.metadata["homepage_uri"] = spec.homepage
24
- spec.metadata["source_code_uri"] = spec.homepage
23
+ spec.metadata["source_code_uri"] = "https://github.com/widefix/actual_db_schema"
25
24
  spec.metadata["changelog_uri"] = "#{spec.homepage}/blob/main/CHANGELOG.md"
26
25
 
27
26
  # Specify which files should be added to the gem when it is released.
@@ -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.1"
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.1
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-19 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
@@ -109,9 +109,8 @@ dependencies:
109
109
  - !ruby/object:Gem::Version
110
110
  version: '0'
111
111
  description: |
112
- Switching between branches with migrations and running them can make your DB inconsistent
113
- and not working in another branch if not roll the migration back.
114
- Install this gem and forget about that issue by running the standard rake db:migrate.
112
+ Wipe out inconsistent DB and schema.rb when switching branches.
113
+ Just install this gem and use the standard rake db:migrate command.
115
114
  email:
116
115
  - ka8725@gmail.com
117
116
  executables: []
@@ -145,13 +144,13 @@ files:
145
144
  - lib/railtie.rb
146
145
  - lib/tasks/db.rake
147
146
  - sig/actual_db_schema.rbs
148
- homepage: https://github.com/widefix/actual_db_schema
147
+ homepage: https://blog.widefix.com/actual-db-schema/
149
148
  licenses:
150
149
  - MIT
151
150
  metadata:
152
- homepage_uri: https://github.com/widefix/actual_db_schema
151
+ homepage_uri: https://blog.widefix.com/actual-db-schema/
153
152
  source_code_uri: https://github.com/widefix/actual_db_schema
154
- changelog_uri: https://github.com/widefix/actual_db_schema/blob/main/CHANGELOG.md
153
+ changelog_uri: https://blog.widefix.com/actual-db-schema//blob/main/CHANGELOG.md
155
154
  post_install_message:
156
155
  rdoc_options: []
157
156
  require_paths:
@@ -167,8 +166,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
167
166
  - !ruby/object:Gem::Version
168
167
  version: '0'
169
168
  requirements: []
170
- rubygems_version: 3.4.21
169
+ rubygems_version: 3.3.3
171
170
  signing_key:
172
171
  specification_version: 4
173
- summary: Keep your DB clean and consistent between branches.
172
+ summary: Keep your DB and schema.rb consistent in dev branches.
174
173
  test_files: []