activerecord-migrate-fix 0.1.0

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 01ebe6ba4c74600e89ea3e49e3cc9636abef544a7f42af700c16f8a8512c8267
4
+ data.tar.gz: 1c5a3d98a94e9a00754dda820e4ad9dea047b8f1fef8db341654cfad30ab8588
5
+ SHA512:
6
+ metadata.gz: a6c806066e2a26636049d2ee1a8a24d5419c4f3bca81ec20aa6f7b5ce33e9d32093ed9d19705ba8023c1a2c46972a9fa3d12dafef5865adbdfadbe9ddf680f70
7
+ data.tar.gz: 83011d3a6e17693ad26ce3e0af522a8620bbb665fe3d2282815f12220cd35a2c5278089d3fd6ae857fb0b49bb33a19404d5758779c1737d4d188917adcc365c4
data/CHANGELOG.md ADDED
@@ -0,0 +1 @@
1
+ ## [Unreleased]
data/MIT-LICENSE.txt ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) David Heinemeier Hansson
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,42 @@
1
+ # ActiveRecord migrate fix
2
+
3
+ [![Gem Version](https://badge.fury.io/rb/activerecord-migrate-fix.svg?icon=si%3Arubygems&icon_color=%23ff6251)](https://rubygems.org/gems/activerecord-migrate-fix)
4
+
5
+
6
+ ## What does this do
7
+
8
+ This is a tiny monkey-patch for ActiveRecord 8.1+, reverting [this change made in AR 8.0](https://github.com/rails/rails/issues/53899), where `rake db:migrate` no longer runs all migrations from the beginning on an empty database, but instead just installs the schema from `db/schema.rb` same way that `db:prepare` does.
9
+
10
+ The fix overrides `ActiveRecord::Tasks::DatabaseTasks#migrate_all` with a version that instead of calling `#initialize_database`, which creates the database if needed and imports the `schema.rb`, calls a local helper `#create_database_if_missing`, which only creates the database, but doesn't add the tables, letting the migration runner take care of that.
11
+
12
+
13
+ ## Requirements
14
+
15
+ * Ruby 3.2 or newer
16
+ * compatible with ActiveRecord 8.1.x
17
+
18
+
19
+ ## Usage
20
+
21
+ Add the gem to your `Gemfile`:
22
+
23
+ ```rb
24
+ gem 'activerecord-migrate-fix', '~> 0.1.0'
25
+ ```
26
+
27
+ And load it in your `Rakefile`:
28
+
29
+ ```rb
30
+ require 'activerecord-migrate-fix'
31
+ ```
32
+
33
+ Now, when you run `bundle exec rake db:migrate` in the app with no database initialized, it should run all migrations one by one.
34
+
35
+
36
+ ## Credits
37
+
38
+ This project: copyright © 2026 Kuba Suder ([@mackuba.eu](https://bsky.app/profile/did:plc:oio4hkxaop4ao4wz2pp3f4cr)).
39
+
40
+ Rails & ActiveRecord: copyright ® David Heinemeier Hansson and Rails contributors.
41
+
42
+ The code is available under the terms of the MIT license.
data/Rakefile ADDED
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rspec/core/rake_task"
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ task default: :spec
@@ -0,0 +1,42 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'active_record'
4
+ require 'active_record/tasks/database_tasks'
5
+
6
+ module ActiveRecord
7
+ module Tasks
8
+ module DatabaseTasks
9
+ def migrate_all
10
+ db_configs = ActiveRecord::Base.configurations.configs_for(env_name: ActiveRecord::Tasks::DatabaseTasks.env)
11
+ db_configs.each { |db_config| create_database_if_missing(db_config) }
12
+
13
+ if db_configs.size == 1 && db_configs.first.primary?
14
+ ActiveRecord::Tasks::DatabaseTasks.migrate(skip_initialize: true)
15
+ else
16
+ mapped_versions = ActiveRecord::Tasks::DatabaseTasks.db_configs_with_versions
17
+
18
+ mapped_versions.sort.each do |version, db_configs|
19
+ db_configs.each do |db_config|
20
+ ActiveRecord::Tasks::DatabaseTasks.with_temporary_connection(db_config) do
21
+ ActiveRecord::Tasks::DatabaseTasks.migrate(version, skip_initialize: true)
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
27
+
28
+ private
29
+
30
+ def create_database_if_missing(db_config)
31
+ with_temporary_pool(db_config) do
32
+ begin
33
+ migration_connection_pool.schema_migration.table_exists?
34
+ rescue ActiveRecord::NoDatabaseError
35
+ create(db_config)
36
+ retry
37
+ end
38
+ end
39
+ end
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ActiveRecord
4
+ module MigrateFix
5
+ VERSION = '0.1.0'
6
+ end
7
+ end
@@ -0,0 +1,4 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'migrate_fix/migrate_all'
4
+ require_relative 'migrate_fix/version'
@@ -0,0 +1,3 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'active_record/migrate_fix'
metadata ADDED
@@ -0,0 +1,69 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: activerecord-migrate-fix
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Kuba Suder
8
+ bindir: bin
9
+ cert_chain: []
10
+ date: 1980-01-02 00:00:00.000000000 Z
11
+ dependencies:
12
+ - !ruby/object:Gem::Dependency
13
+ name: activerecord
14
+ requirement: !ruby/object:Gem::Requirement
15
+ requirements:
16
+ - - "~>"
17
+ - !ruby/object:Gem::Version
18
+ version: 8.1.4
19
+ type: :runtime
20
+ prerelease: false
21
+ version_requirements: !ruby/object:Gem::Requirement
22
+ requirements:
23
+ - - "~>"
24
+ - !ruby/object:Gem::Version
25
+ version: 8.1.4
26
+ description: "\n Rails/ActiveRecord 8.0 changed the behavior of the db:migrate
27
+ task so that on an empty database it no longer\n runs all migrations, but instead
28
+ loads the schema from db/schema.rb. This gem\n patches ActiveRecord::Tasks::DatabaseTasks
29
+ to make it skip loading the schema and run all migrations instead\n like in previous
30
+ versions of Rails.\n "
31
+ email:
32
+ - jakub.suder@gmail.com
33
+ executables: []
34
+ extensions: []
35
+ extra_rdoc_files: []
36
+ files:
37
+ - CHANGELOG.md
38
+ - MIT-LICENSE.txt
39
+ - README.md
40
+ - Rakefile
41
+ - lib/active_record/migrate_fix.rb
42
+ - lib/active_record/migrate_fix/migrate_all.rb
43
+ - lib/active_record/migrate_fix/version.rb
44
+ - lib/activerecord-migrate-fix.rb
45
+ licenses:
46
+ - MIT
47
+ metadata:
48
+ bug_tracker_uri: https://tangled.org/mackuba.eu/activerecord-migrate-fix/issues
49
+ changelog_uri: https://tangled.org/mackuba.eu/activerecord-migrate-fix/blob/master/CHANGELOG.md
50
+ source_code_uri: https://tangled.org/mackuba.eu/activerecord-migrate-fix
51
+ rubygems_mfa_required: 'true'
52
+ rdoc_options: []
53
+ require_paths:
54
+ - lib
55
+ required_ruby_version: !ruby/object:Gem::Requirement
56
+ requirements:
57
+ - - ">="
58
+ - !ruby/object:Gem::Version
59
+ version: 3.2.0
60
+ required_rubygems_version: !ruby/object:Gem::Requirement
61
+ requirements:
62
+ - - ">="
63
+ - !ruby/object:Gem::Version
64
+ version: '0'
65
+ requirements: []
66
+ rubygems_version: 4.0.23
67
+ specification_version: 4
68
+ summary: Patch for ActiveRecord 8.1+ which restores pre Rails 8 db:migrate behavior
69
+ test_files: []