Hi, I have a little dilemma where and how to place a script in my rails application. I work on a reimplementation and the original database structure is changed. The old data needs to be migrated into a new schema. The migration is executed very few times, maybe just once. As the data set might be huge, I also do not wish to execute it often. Currently I placed the script in dir /script, but I think it does not fit the place well, it is meant for other things... isn''t it? I think it should among the migrations, but I don''t want it to be executed always as the others migration when the data model is created. Could you give me advice, how to tackle elegantly this thing? I want to keep my code in the rails project structure, although it will be executed few times, maybe only now. And I''d like to have it at a place which it fits well. Thanks for help! Georg
Fifigyuri wrote:> Hi, > > I have a little dilemma where and how to place a script in my > rails application. I work on a reimplementation and the original > database structure is changed. The old data needs to be migrated into > a new schema. The migration is executed very few times, maybe just > once. As the data set might be huge, I also do not wish to execute it > often. > Currently I placed the script in dir /script, but I think it does > not fit the place well, it is meant for other things... isn''t it? I > think it should among the migrations, but I don''t want it to be > executed always as the others migration when the data model is > created.The preferred way to create the DB is to use rake db:schema:load. Migrations are only for migration. So just write the script as a migration. That''s what migrations are for.> Could you give me advice, how to tackle elegantly this thing? I > want to keep my code in the rails project structure, although it will > be executed few times, maybe only now. And I''d like to have it at a > place which it fits well. Thanks for help! >You are describing a classic use case for a migration. There''s no reason to do it any other way. If you''re worried about it being run when it shouldn''t be, just throw in some if statements. Best, -- Marnen Laibow-Koser http://www.marnen.org marnen-sbuyVjPbboAdnm+yROfE0A@public.gmane.org> Georg-- Posted via http://www.ruby-forum.com/.
Thanks, I followed your advice. And its almost fine. The original script operated with the models, putting it to a migration causes take the migration misses the model. Claims "uninitialized constant" for the model name. I tried to require the model directly. On the other hand I am not sure whether using models in migrations is intended.... currently it seems to be the most convenient way of changing the data. bw On Sep 5, 3:56 pm, Marnen Laibow-Koser <rails-mailing-l...@andreas- s.net> wrote:> Fifigyuri wrote: > > Hi, > > > I have a little dilemma where and how to place a script in my > > rails application. I work on a reimplementation and the original > > database structure is changed. The old data needs to be migrated into > > a new schema. The migration is executed very few times, maybe just > > once. As the data set might be huge, I also do not wish to execute it > > often. > > Currently I placed the script in dir /script, but I think it does > > not fit the place well, it is meant for other things... isn''t it? I > > think it should among the migrations, but I don''t want it to be > > executed always as the others migration when the data model is > > created. > > The preferred way to create the DB is to use rake db:schema:load. > Migrations are only for migration. So just write the script as a > migration. That''s what migrations are for. > > > Could you give me advice, how to tackle elegantly this thing? I > > want to keep my code in the rails project structure, although it will > > be executed few times, maybe only now. And I''d like to have it at a > > place which it fits well. Thanks for help! > > You are describing a classic use case for a migration. There''s no > reason to do it any other way. If you''re worried about it being run > when it shouldn''t be, just throw in some if statements. > > Best, > -- > Marnen Laibow-Koserhttp://www.marnen.org > mar...-sbuyVjPbboAdnm+yROfE0A@public.gmane.org > > > Georg > > -- > Posted viahttp://www.ruby-forum.com/.
I correct myself. The problem was in my code, and thought that not accessing the ActiveRecord::Base from Migrations is intended. No, it is possible, sorry for the false alarm. On Sep 5, 6:46 pm, Fifigyuri <fifigy...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Thanks, I followed your advice. And its almost fine. The original > script operated with the models, putting it to a migration causes take > the migration misses the model. Claims "uninitialized constant" for > the model name. I tried to require the model directly. On the other > hand I am not sure whether using models in migrations is intended.... > currently it seems to be the most convenient way of changing the data. > > bw > > On Sep 5, 3:56 pm, Marnen Laibow-Koser <rails-mailing-l...@andreas- > > s.net> wrote: > > Fifigyuri wrote: > > > Hi, > > > > I have a little dilemma where and how to place a script in my > > > rails application. I work on a reimplementation and the original > > > database structure is changed. The old data needs to be migrated into > > > a new schema. The migration is executed very few times, maybe just > > > once. As the data set might be huge, I also do not wish to execute it > > > often. > > > Currently I placed the script in dir /script, but I think it does > > > not fit the place well, it is meant for other things... isn''t it? I > > > think it should among the migrations, but I don''t want it to be > > > executed always as the others migration when the data model is > > > created. > > > The preferred way to create the DB is to use rake db:schema:load. > > Migrations are only for migration. So just write the script as a > > migration. That''s what migrations are for. > > > > Could you give me advice, how to tackle elegantly this thing? I > > > want to keep my code in the rails project structure, although it will > > > be executed few times, maybe only now. And I''d like to have it at a > > > place which it fits well. Thanks for help! > > > You are describing a classic use case for a migration. There''s no > > reason to do it any other way. If you''re worried about it being run > > when it shouldn''t be, just throw in some if statements. > > > Best, > > -- > > Marnen Laibow-Koserhttp://www.marnen.org > > mar...-sbuyVjPbboAdnm+yROfE0A@public.gmane.org > > > > Georg > > > -- > > Posted viahttp://www.ruby-forum.com/.