16

koşmaya çalıştım:Tüm geçişleri bir defada Ruby on Rails 3'te nasıl geri alabilirim?

rake db:migrate VERSION=0 

Bu sonuncusu hariç tüm göçler döner.

Sonra koşmaya çalıştım:

rake db:migrate:down VERSION=<timestamp_of_last_migration> 

ama ya geri vermedi. Niye ya ?

Tüm down yöntemlerini aynı anda çalıştıran bir komut var mı?

+1

alınan

son dönecektir, bu soruya tökezledi. Ben sadece bugünlerde (Rails 3.2.9) rake db: migrasyon VERSION = 0'nın iyi çalıştığını ve tüm geçişleri geri döndürdüğünü söylemek istiyorum. – janosrusiczki

+0

Bu soru yanlış ya da güncel değil gibi görünüyor. rake db: migrasyon VERSION = 0 'her geçişi geri alır, ** ilkini içerir **. –

cevap

11

Veritabanınız yalnızca bu projeyle ilişkiliyse ve geçişlerinizde her şeyi geri almaya çalışıyorsanız, yalnızca veritabanını bırakıp komisyon db: create komutunu çalıştırmayı tercih ediyorum.

Daha sonra gitmeye hazır boş bir veritabanınız var.

Ya da aşağı komut dosyalarını çalıştırmaya çalıştığınız başka bir neden var mı?

+0

Sonunda yaptım. Ama yine de yukarıdaki komutların neden işe yaramadığını merak ediyorum ... –

+2

Raylar arasında ilerledikçe görevler tırmandı ve tırmık gibi görünüyor db: drop db: create tek gerçek seçenektir. Göçmenlerin hiçbir şeye geri gitmeme izin vermeyeceklerini söylerdim, çünkü göçmenlerin INSIDE etrafında hareket etmeleri amaçlanmıştı. Sıfırlamaya yeniden değil. – boymc

10

Bu listeyi kontrol edebilirsiniz. esasen her şeyi silerek,

rake db:migrate:down VERSION=<timestamp_of_first_migration> 

Bu ilk göç self.down çalışacaktır:

Belki bu

rake db:create[:all]: If :all not specified then create the database defined in config/database.yml for the current RAILS_ENV. If :all is specified then create all of the databases defined in config/database.yml. 
rake db:fixtures:load: Load fixtures into the current environment's database. Load specific fixtures using FIXTURES=x,y 
rake db:migrate [VERSION=n]: Migrate the database through scripts in db/migrate. Target specific version with VERSION=n 
rake db:migrate:redo [STEP=n]: (2.0.2) Revert the database by rolling back "STEP" number of VERSIONS and re-applying migrations. 
rake db:migrate:reset: (2.0.2) Drop the database, create it and then re-apply all migrations. The considerations outlined in the note to rake db:create apply. 
rake db:reset: Drop and re-create database using db/schema.rb. The considerations outlined in the note to rake db:create apply. 
rake db:rollback [STEP=N]: (2.0.2) Revert migration 1 or n STEPs back. 
rake db:schema:dump: Create a db/schema.rb file that can be portably used against any DB supported by AR 
rake db:schema:load: Load a schema.rb file into the database 
rake db:sessions:clear: Clear the sessions table 
rake db:sessions:create: Creates a sessions table for use with CGI::Session::ActiveRecordStore 
rake db:structure:dump: Dump the database structure to a SQL file 
rake db:test:clone: Recreate the test database from the current environment's database schema 
rake db:test:clone_structure: Recreate the test databases from the development structure 
rake db:test:prepare: Prepare the test database and load the schema 
rake db:test:purge: Empty the test database 
2

deneyin yardımcı olabilir. en azından, benim için sadece yaptı!