How to disable db:schema:dump for migrations
Create an application specific task (as Alex Kaushovik suggested) like so...
Create a file lib\tasks\db_schema_override
(actual name doesn't matter, you need a .rake file in lib\tasks) with contents as below (credit to Matthew Bass for remove_task
)
Rake::TaskManager.class_eval do
def remove_task(task_name)
@tasks.delete(task_name.to_s)
end
end
Rake.application.remove_task('db:schema:dump')
namespace :db do
namespace :schema do
task :dump do
# Overridden to do nothing
end
end
end
How to disable updating of structure.sql in rails?
You can disable that in your config/application.rb
:
config.active_record.dump_schema_after_migration = false
See the configuration guide here.
How do I disable the migrations feature in a Rails app?
This came up again when testing finally came to the front. Thus, I took deeper look and came up with the following thanks, in part, to the comments left on the question. This removes all rake DB capabilities and tests still run fine. (In case anyone is wondering, we clone the test DB from elsewhere when we need to refresh it.)
Add this to the Rakefile
:
# Disable DB migrations, DB test preparing, etc.
Rake::Task.tasks.each do |t|
if t.name[0,3] == "db:"
t.clear
t.add_description("!!! Disabled in favor of enterprise design at Acme.")
end
end
Comment out all the fixtures in test/test_helper.rb
:
#fixtures :all
Keep a table out of schema.rb during migrations
Turns out there's an option for just this situation!
I found it in activerecord-2.3.4/lib/active_record/schema_dumper.rb
:
##
# :singleton-method:
# A list of tables which should not be dumped to the schema.
# Acceptable values are strings as well as regexp.
# This setting is only used if ActiveRecord::Base.schema_format == :ruby
cattr_accessor :ignore_tables
@@ignore_tables = []
So all I had to do was stick this at the end of environment.rb:
ActiveRecord::SchemaDumper.ignore_tables = ["table_name"]
If ActiveRecord.schema_format == :ruby, the array can also contain RegExp. For example, to ignore all tables starting with "MS":
ActiveRecord::SchemaDumper.ignore_tables = [/^MS/]
Loading the DB dumb, and running all the migrations
I would first load the db dump, as it also contains all you data and the current schema structure.
running rake db:migrate will only run the new migration
This depends. If your db dump has a schema_migrations
table, that lists all the previously applied migrations, it will not apply the migrations. Otherwise, it will try to and fail.
You basically need these steps:
- Import your dump
- Create a Rails schema (rake db:schema:dump)
- If you have newer migrations, run them
Rails -- working with an existing db, cannot run migrations without losing data
Migrates should be used to create and changes the tables and fields, not load data, as you can see here Ruby on Rails Guides
If you want to import data you could do it on the seeds, but in your specific case it seems to me that you should create a dump from your origin database and load it on the target database.
Here is a tutorial sqlite3: how to import/export data from/to a file
Related Topics
Storing Arrays in Database Using Activerecord
What Is '-Mix' in a Ruby Regular Expression
How to Test 'Rand()' with Rspec
Disable Sprockets Asset Caching in Development
Converting a Hexadecimal Digest to Base64 in Ruby
Error: While Executing Gem ... (Zlib::Gzipfile::Error) Not in Gzip Format
How to Track the Execution Process of Ruby Program
Why Won't a Longer Token in an Alternation Be Matched
How to Pass Arguments to Define_Method
Error: Error Installing Capybara-Webkit:
How to Execute Custom Actions After Successful Sign in with Devise
Rack::Request - How to Get All Headers
How to Change Column Type in Heroku
Is There a Cucumber Hook to Run Before and After Each Feature
How to Handle a Thread Issue in Zeromq + Ruby