Created
February 1, 2016 23:26
-
-
Save tenderlove/44447d1b1e466a28eb3f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[aaron@TC omglolwut (master)]$ cat lib/tasks/disable_autoload_during_migrations.rake | |
task :disable_autoload do | |
ActiveSupport::Dependencies.class_eval do | |
extend Module.new { | |
def load_file(path, const_paths = loadable_constants_for_path(path)) | |
return if path.starts_with? File.join(Rails.application.root, 'app', 'models') | |
super | |
end | |
} | |
end | |
end | |
Rake::Task["db:migrate"].prerequisites << :disable_autoload | |
[aaron@TC omglolwut (master)]$ cat db/migrate/20160201230058_omglol.rb | |
class Omglol < ActiveRecord::Migration[5.0] | |
def change | |
User.delete_all | |
end | |
end | |
[aaron@TC omglolwut (master)]$ rake db:migrate | |
== 20160201230058 Omglol: migrating =========================================== | |
rake aborted! | |
LoadError: Unable to autoload constant User, expected /Users/aaron/git/omglolwut/app/models/user.rb to define it | |
/Users/aaron/git/rails/activesupport/lib/active_support/dependencies.rb:530:in `load_missing_constant' | |
/Users/aaron/git/rails/activesupport/lib/active_support/dependencies.rb:212:in `const_missing' | |
/Users/aaron/git/rails/activesupport/lib/active_support/dependencies.rb:561:in `load_missing_constant' | |
/Users/aaron/git/rails/activesupport/lib/active_support/dependencies.rb:212:in `const_missing' | |
/Users/aaron/git/omglolwut/db/migrate/20160201230058_omglol.rb:3:in `change' | |
/Users/aaron/git/rails/activerecord/lib/active_record/migration.rb:794:in `exec_migration' | |
/Users/aaron/git/rails/activerecord/lib/active_record/migration.rb:778:in `block (2 levels) in migrate' | |
/Users/aaron/git/rails/activerecord/lib/active_record/migration.rb:777:in `block in migrate' | |
/Users/aaron/git/rails/activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb:398:in `with_connection' | |
/Users/aaron/git/rails/activerecord/lib/active_record/migration.rb:776:in `migrate' | |
/Users/aaron/git/rails/activerecord/lib/active_record/migration.rb:956:in `migrate' | |
/Users/aaron/git/rails/activerecord/lib/active_record/migration.rb:1217:in `block in execute_migration_in_transaction' | |
/Users/aaron/git/rails/activerecord/lib/active_record/migration.rb:1285:in `block in ddl_transaction' | |
/Users/aaron/git/rails/activerecord/lib/active_record/connection_adapters/abstract/database_statements.rb:230:in `block in transaction' | |
/Users/aaron/git/rails/activerecord/lib/active_record/connection_adapters/abstract/transaction.rb:184:in `within_new_transaction' | |
/Users/aaron/git/rails/activerecord/lib/active_record/connection_adapters/abstract/database_statements.rb:230:in `transaction' | |
/Users/aaron/git/rails/activerecord/lib/active_record/transactions.rb:211:in `transaction' | |
/Users/aaron/git/rails/activerecord/lib/active_record/migration.rb:1285:in `ddl_transaction' | |
/Users/aaron/git/rails/activerecord/lib/active_record/migration.rb:1216:in `execute_migration_in_transaction' | |
/Users/aaron/git/rails/activerecord/lib/active_record/migration.rb:1189:in `block in migrate_without_lock' | |
/Users/aaron/git/rails/activerecord/lib/active_record/migration.rb:1188:in `each' | |
/Users/aaron/git/rails/activerecord/lib/active_record/migration.rb:1188:in `migrate_without_lock' | |
/Users/aaron/git/rails/activerecord/lib/active_record/migration.rb:1139:in `migrate' | |
/Users/aaron/git/rails/activerecord/lib/active_record/migration.rb:1011:in `up' | |
/Users/aaron/git/rails/activerecord/lib/active_record/migration.rb:989:in `migrate' | |
/Users/aaron/git/rails/activerecord/lib/active_record/tasks/database_tasks.rb:155:in `migrate' | |
/Users/aaron/git/rails/activerecord/lib/active_record/railties/databases.rake:58:in `block (2 levels) in <top (required)>' | |
Tasks: TOP => db:migrate | |
(See full trace by running task with --trace) | |
[aaron@TC omglolwut (master)]$ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
task :disable_autoload do | |
ActiveSupport::Dependencies.class_eval do | |
extend Module.new { | |
def load_file(path, const_paths = loadable_constants_for_path(path)) | |
return if path.starts_with? File.join(Rails.application.root, 'app', 'models') | |
super | |
end | |
} | |
end | |
end | |
Rake::Task["db:migrate"].prerequisites << :disable_autoload |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
OMGWAT!