What is the best way to dump my development database structure and deploy it to a production server?
Im using capistrano deployment for rails app
how would one migrate changes in development database structure automatic with each cap deploy?
You can add a migration that executes your schema dump. Then use migrations to make changes after that.
Then, you'll execute cap deploy:migrations to deploy your code and run your migrations.
Related
I am working on a rails app with a few git branches. we deploy the production mode using Capistrano::Rails.
What currently struggling me is that I added and deleted a few columns in the user table in a branch, and after merge it into the master branch, I ran rake db:schema:load. So the database in development mode is reset and all data is lost(which is fine). However, I don't want to lose all of my data in the production mode. In the production database, I could accept losing the data in the user table, but I don't want to lose the data in other tables on my production mode.
So what shall I do for that.
We currently use PostgreSQL on AWS RDS.
ActiveRecord migrations were created for this purpose. Rather than run rake db:schema:load, make your database changes through migrations and run rake db:migrate (or rails db:migrate if Rails 5)
I'm trying to learn Capistrano (version 3) and I'm tinkering around deploying to a "test" production server.
When I run:
cap production deploy
If I want to reset and seed the database, do I create a separate task for this? Or is there something already built-in Capistrano to do this?
Rails deployment - how do you do rake db:reset with capistrano?
rake db:reset will automatically run your seeds file
I am assuming I have to use capistrano but still unsure. I want to move my rails app and the databases (since they already have lot of data now) to the server, how can I do it ?
Thanks
to move your database schema... rake db:schema:dump will dump it to schema.rb and rake db:schema:load will load them.
You can use capistrano to build a deployment system. I personally use git to promote my apps to production. I use Engine Yard (www.engineyard.com) and Heroku (www.heroku.com) for hosting. Deployment is super-simple with both.
As far as the database goes it depends on your server implementation. Most likely you'll need to backup and restore the database into production.
I'm a newbie in Rails and I'm trying to deploy my first project.
I'm using rails 3, ruby 1.8.7, Passanger, Mysql and Git
I followed a lot of tutorials to learn about deploying with capistrano and there is a question that i can't figure out.
In the tutorials they never talk about schema.rb
If this file is the responsible for the migrations that i already done and when we deploy the application, capistrano copy all files to the "current" folder (schema.rb to), how can it do the right migrations on production server. Should i tell capistrano to make a simlink to the right schema.rb file for the "current" folder? if yes how can i do that?
Tnks.
The schema.rb file contains the database definition. It is not responsible for any migration.
The migrations are contained in the db/migrations folder. When you deploy a new release and ask Capistrano to migrate the current database, Capistrano invokes rake db:migrate. The migrate task doesn't rely on the schema.rb. It connects to the database, reads the list of executed migrations from the schema table and execute all the files in the db/migrations for which a record doesn't exist in that table.
The schema.rb file is only used when you invoke rake db:schema:load or when you bootstrap Rails. In the latter case, Rails will use the schema to prevent inspecting the database structure every time you access a Model.
That said, the schema.rb file must be versioned in your SCM and you have to include it during deployment. You don't need to do anything special. Capistrano checkout the file from your SCM like all the other files, unless you ignored it.
I have a development database on my computer and a production database on Heroku. I need to run a migration on the production database, to clear certain data, that I don't want to run on the development one. So far I've only been doing migrations that I've wanted to run on both, so I just create it on my computer, run it, then when I upload to Heroku I run it on there too. How can I do a migration only on the production database? Thanks for reading.
Create your migration.
Commit, push, run on heroku with heroku rake db:migrate --app myapp.
Comment out the contents of the up block.
Run the (now-empty) migration locally.
Uncomment or git checkout/reset to get back to normal.
This way both your local db and production db will consider the migration to have been run and not try to run it again.
Migrations are intended to update the structure of your database, not to manipulate data. If you want to manipulate data, you should use the console or a script.
$ heroku console
RAILS_ENV=production rake db:migrate