Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
[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)]$
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

rpond-pa commented Feb 2, 2016

OMGWAT!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment