rails-migrations

What's a good way to clean up my migrations in Rails?

匆匆过客 提交于 2019-12-03 09:11:07
问题 So I've been working on this web app for a year now and I would like to compile to schema into ONE migration, that way my text editor loads faster, git working directory isn't so cluttered. Search find will be faster. Any my config/db won't be 4000px long. 回答1: One way to go is to take a blank database and run all the migrations. Now you've got all the template data which you can save to a yaml. The yaml plus the schema should be enough to bring the DB back without running any of your

Are Doctrine migrations usable in production applications?

試著忘記壹切 提交于 2019-12-03 09:04:20
问题 As previously discussed, we are developing a PHP application around Zend Framework that needs to have it's database upgraded quite frequently and in a cross-database way as we move through development stages. We are currently using Rails Migrations for this, although with them being in Ruby (and Ruby on Windows being the mess that it is), we are having a hard time distributing migrations to customers that have Windows-based installs. Even on Linux, access to MS SQL and Oracle databases with

How to reset auto increment field in a ActiveRecord migration?

Deadly 提交于 2019-12-03 06:12:37
In my migration I have: def up MyModel.destroy_all MyModel.create!({:id=>1,:name=>'foo'}) MyModel.create!({:id=>2,:name=>'fooBar'}) MyModel.create!({:id=>3,:name=>'fooNull'}) end because I need to override data that was already on my_models table But Even though I'm specifying the id on MySQL it continues the numbering from the position it already was. I need to rest the counter on the auto increment for id to have only this 3 new records with that id values trough Active Record migration on my Ruby on Rails application. PinnyM You have 2 separate issues. One is that you are trying to specify

How to do Rails migration involving Paperclip

╄→гoц情女王★ 提交于 2019-12-03 06:07:57
How do people write their Rails migrations that involve Paperclip ? I feel that I might be missing something obvious as I have now written my own migration helpers hacks that makes it easier and also take care of doing necessary filesystem changes. And of course you should test run these kinds of migrations in a development (and staging) environment before deploying to production. Paperclip migration rename, add and remove helpers Paperclip change path migration helper (not really a database migration but think it fits quite nice anyway) Are there any better solutions or best practices? some

Couldn't run migration after spring update in Rails

偶尔善良 提交于 2019-12-03 05:39:19
I am facing a error when I run any migration as: raj@notebook-pc:~/Desktop/Projects/invoicemanagement$ rails g migration RemoveDescriptionOfGoodsFromInvoiceDetails description_of_goods:string Warning: You're using Rubygems 1.8.23 with Spring. Upgrade to at least Rubygems 2.1.0 and run `gem pristine --all` for better startup performance. /var/lib/gems/1.9.1/gems/bundler-1.9.0/lib/bundler/runtime.rb:34:in `block in setup': You have already activated spring 1.3.3, but your Gemfile requires spring 1.3.2. Prepending `bundle exec` to your command may solve this. (Gem::LoadError) from /var/lib/gems/1

How do you make remove_column reversible?

吃可爱长大的小学妹 提交于 2019-12-03 05:14:02
I have a migration that removes a column: def change remove_column :foos, :bar, :boolean end When I try to rake db:rollback that migration, I get the following error: remove_column is only reversible if given a type. The ActiveRecord::Migration documentation says that the following is the signature for remove_column : remove_column(table_name, column_name, type, options) So my type in this case should be :boolean , and I expect that migration to be reversible. What am I missing? I can certainly break this out into an up and down migration to avoid this problem, but I'd like to understand why

Managing mongoid migrations

前提是你 提交于 2019-12-03 04:15:10
问题 Can someone give me a short introduction to doing DB migrations in Rails using Mongoid? I'm particularly interested in lazy per document migrations. By this, I mean that whenever you read a document from the database, you migrate it to its latest version and save it again. Has anyone done this sort of thing before? I've come across mongoid_rails_migrations, but it doesn't provide any sort of documentation, and although it looks like it does this, I'm not really sure how to use it. I should

Running migrations with Rails in a Docker container with multiple container instances

。_饼干妹妹 提交于 2019-12-03 03:39:26
问题 I've seen lots of examples of making Docker containers for Rails applications. Typically they run a rails server and have a CMD that runs migrations/setup then brings up the Rails server. If I'm spawning 5 of these containers at the same time, how does Rails handle multiple processes trying to initiate the migrations? I can see Rails checking the current schema version in the general query log (it's a MySQL database): SELECT `schema_migrations`.`version` FROM `schema_migrations` But I can see

How do you skip failed migrations? (rake db:migrate)

一世执手 提交于 2019-12-03 02:13:42
问题 I can't seem to find an option or anything that allows me to skip migrations. I know what you're thinking: "you should never have to do that..." I need to skip a migration that makes changes to specific user records that don't exist in my development database. I don't want to change the migration because it is not part of the source I am supposed to be working with. Is there a way to skip a migration or skip failed migrations? Thanks in advance! 回答1: I think you should fix the offending

How can i remove a column from table using rails console

好久不见. 提交于 2019-12-03 01:26:49
问题 It is easily possible to remove a column using rails migration. class SomeClass < ActiveRecord::Migration def self.up remove_column :table_name, :column_name end end I want to know if there is any way to remove a column from table using console. 回答1: You can run the codes in up method directly in rails console : >> ActiveRecord::Migration.remove_column :table_name, :column_name If you already have a migration file such as " db/migrate/20130418125100_remove_foo.rb ", you can do this: >>