I am beginning to test ActiveRecord''s Migrations, have run into an issue with migrating back to a previous version, and am looking for some advice. I have two test migrations: 1_create_test_one.rb creates a table called test_one and 2_create_test_two.rb creates a table called test_two. The code for 1_create_test_one.rb looks like: class CreateTestOne < ActiveRecord::Migration def self.up create_table :test_one do |table| table.column :test, :string end end def self.down drop_table :test_one end end The code for 2_create_test_two.rb is similar, except "CreateTestOne" is replaced with "CreateTestTwo" and "test_one" is replaced with "test_two". All is fine after doing a "rake migrate". The schema_info gets updated to version 2 and the two tables are created. When I attempt to "rake migrate VERSION=1", nothing changes. schema_info stays at version 2 and both test_one and test_two tables are still in the database. Does the Migrations class currently (Rails 0.13.1) currently support migrating back? Or is this a Windows issue? If it matters, the development environment here is Rails 0.13.1 on Windows XP with MySQL 4.1.10a and Ruby 1.8.2. -- Dennis Sutch dennis-+mObuC4wx48AvxtiuMwx3w@public.gmane.org
On 8/29/05, Dennis Sutch <dsutch-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> I am beginning to test ActiveRecord''s Migrations, have run into an > issue with migrating back to a previous version, and am looking for > some advice. > > I have two test migrations: 1_create_test_one.rb creates a table > called test_one and 2_create_test_two.rb creates a table called > test_two. > > The code for 1_create_test_one.rb looks like: > > class CreateTestOne < ActiveRecord::Migration > def self.up > create_table :test_one do |table| > table.column :test, :string > end > end > > def self.down > drop_table :test_one > end > end > > The code for 2_create_test_two.rb is similar, except "CreateTestOne" > is replaced with "CreateTestTwo" and "test_one" is replaced with > "test_two". > > All is fine after doing a "rake migrate". The schema_info gets > updated to version 2 and the two tables are created. > > When I attempt to "rake migrate VERSION=1", nothing changes. > schema_info stays at version 2 and both test_one and test_two tables > are still in the database. > > Does the Migrations class currently (Rails 0.13.1) currently support > migrating back? Or is this a Windows issue? If it matters, the > development environment here is Rails 0.13.1 on Windows XP with MySQL > 4.1.10a and Ruby 1.8.2.VERSION needs to be set in the environment. With the bash shell (common one on *nix), including ''VERSION=0'' on the command line is a way to set that option in the env just on that command. I don''t know how to do the same thing on Windows. But that''s what you should be looking for.
I''ve successfully migrated back several times -- it works. I don''t see anything obviously wrong with your migration. Does your db user have permissions to drop the table? I''m not confident that rake/migrate reports problems usefully. And I''ve had a few operator errors. Once I thought migrations were not working correctly. I was trying to migrate the production environment, and I wasn''t specifying the production environment. The migration keep succeeding, but my production database stayed the same... -Kelly On 8/29/05, Dennis Sutch <dsutch-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > I am beginning to test ActiveRecord''s Migrations, have run into an > issue with migrating back to a previous version, and am looking for > some advice. > > I have two test migrations: 1_create_test_one.rb creates a table > called test_one and 2_create_test_two.rb creates a table called > test_two. > > The code for 1_create_test_one.rb looks like: > > class CreateTestOne < ActiveRecord::Migration > def self.up > create_table :test_one do |table| > table.column :test, :string > end > end > > def self.down > drop_table :test_one > end > end > > The code for 2_create_test_two.rb is similar, except "CreateTestOne" > is replaced with "CreateTestTwo" and "test_one" is replaced with > "test_two". > > All is fine after doing a "rake migrate". The schema_info gets > updated to version 2 and the two tables are created. > > When I attempt to "rake migrate VERSION=1", nothing changes. > schema_info stays at version 2 and both test_one and test_two tables > are still in the database. > > Does the Migrations class currently (Rails 0.13.1) currently support > migrating back? Or is this a Windows issue? If it matters, the > development environment here is Rails 0.13.1 on Windows XP with MySQL > 4.1.10a and Ruby 1.8.2. > > -- > Dennis Sutch > dennis-+mObuC4wx48AvxtiuMwx3w@public.gmane.org > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >_______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails
On 8/30/05, Joe Van Dyk <joevandyk-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> VERSION needs to be set in the environment. With the bash shell > (common one on *nix), including ''VERSION=0'' on the command line is a > way to set that option in the env just on that command. > > I don''t know how to do the same thing on Windows. But that''s what you > should be looking for.Windows allows for setting of environment variables using "set VERSION=0". Tried this, but it doesn''t work. One option that works is to do "ruby script\console" and then "ActiveRecord::Migrator.down(''db/migrate'', 0)". Works flawlessly, so it seems to be a problem with rake. -- Dennis Sutch dennis-+mObuC4wx48AvxtiuMwx3w@public.gmane.org