16

Traté de correr:¿Cómo revertir todas las migraciones a la vez en Ruby on Rails 3?

rake db:migrate VERSION=0 

Se revierte todas las migraciones excepto la última.

Entonces trató de correr:

rake db:migrate:down VERSION=<timestamp_of_last_migration> 

pero no revierten tampoco. Por qué ?

¿Hay algún comando que ejecute todos los métodos down a la vez?

+1

Buscando en la forma de deshacer todas las migraciones, había tropezado con esta cuestión. Solo quiero decir que hoy en día (Rails 3.2.9) 'rake db: migrate VERSION = 0' parece estar funcionando bien, revirtiendo todas las migraciones. – janosrusiczki

+0

Esta pregunta parece estar equivocada o desactualizada. 'rake db: migrate VERSION = 0' retrocede cada migración, ** incluso la primera **. –

Respuesta

11

Si su base de datos solo está relacionada con este proyecto, y está tratando de deshacer todo en sus migraciones, simplemente soltaría la base de datos, y luego ejecutaría rake db: create.

Luego tiene una base de datos vacía lista para funcionar.

¿O existe alguna otra razón por la que intenta ejecutar los scripts hacia abajo?

+0

Eso es lo que hice finalmente. Pero, todavía me pregunto por qué los comandos anteriores no funcionaron ... –

+2

Trolled a través de las tareas de rake de raíles, y parece que rake db: drop db: create es la única opción real. Diría que el motivo por el que las migraciones no te permitirán volver a la nada es porque estaban destinadas a moverse DENTRO de las migraciones. No reiniciando a cero. – boymc

10

Puede consultar esta lista.

Tal vez esto podría ayudarle a

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

intento:

rake db:migrate:down VERSION=<timestamp_of_first_migration> 

esto ejecutará el self.down para su primera migración, secándose en esencia todo lo que fuera. al menos, ¡solo lo hizo por mí!

Cuestiones relacionadas