I have an application in rails in which i am adding a new column in one of the tables. The value for the new column is a bit.ly link and I need to populate this for each record in the table approx. 250 rows will be affected. Q1: Can this be done outside the application? i.e. write a script that can interact with the db and then populate the appropriate column? And is this advisable? or Q2: if the aforementioned idea is not a good way then what will be the best way to update the existing records as any code i will write will only be used to update the table once. One suggestion that has been made is to use migrations but I am not 100% on how i can do that... Plz help -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Quee WM wrote:> I have an application in rails in which i am adding a new column in one > of the tables. The value for the new column is a bit.ly link and I need > to populate this for each record in the table approx. 250 rows will be > affected. > > Q1: Can this be done outside the application? i.e. write a script that > can interact with the db and then populate the appropriate column?Yes.> And > is this advisable?Absolutely not.> > or > > Q2: if the aforementioned idea is not a good way then what will be the > best way to update the existing records as any code i will write will > only be used to update the table once.Use a migration. That''s what they''re for.> > One suggestion that has been made is to use migrations but I am not 100% > on how i can do that...Well, what have you figured out so far? We can help you better if you tell us what you don''t understand. In general, though, *all* DB schema changes should be made through migrations. This makes maintenance easier.> > Plz helpBest, -- Marnen Laibow-Koser http://www.marnen.org marnen-sbuyVjPbboAdnm+yROfE0A@public.gmane.org -- Posted via http://www.ruby-forum.com/. --00032555412a7cf568047c83e921 Content-Type: text/plain; charset=ISO-8859-1 -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en. --00032555412a7cf568047c83e921--
Quee WM wrote:> I have an application in rails in which i am adding a new column in one > of the tables. The value for the new column is a bit.ly link and I need > to populate this for each record in the table approx. 250 rows will be > affected. > > One suggestion that has been made is to use migrations but I am not 100% > on how i can do that... >A migration is a Ruby script. The Rails sugar helps you tell the application (for instance): "Hey there! I need you to add a column to this table. And while you''re at it, check every row, and do this on every row, so we can populate that new column." Start by taking a look at this: http://railsbrain.com/api/rails-2.3.2/doc/index.html?a=M001956&name=add_column -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On Wed, Jan 6, 2010 at 11:35 AM, Aldric Giacomoni <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> Quee WM wrote: >> I have an application in rails in which i am adding a new column in one >> of the tables. The value for the new column is a bit.ly link and I need >> to populate this for each record in the table approx. 250 rows will be >> affected. >> >> One suggestion that has been made is to use migrations but I am not 100% >> on how i can do that... >> > > A migration is a Ruby script. > The Rails sugar helps you tell the application (for instance): > "Hey there! I need you to add a column to this table. And while you''re > at it, check every row, and do this on every row, so we can populate > that new column." >If the value of the column is the same for every row, can''t you just use default value when you create the column? -- Curtis Cooley curtis.cooley-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org home:http://curtiscooley.com blog:http://ponderingobjectorienteddesign.blogspot.com ==============Leadership is a potent combination of strategy and character. But if you must be without one, be without the strategy. -- H. Norman Schwarzkopf -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Curtis Cooley wrote:> On Wed, Jan 6, 2010 at 11:35 AM, Aldric Giacomoni <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> > wrote: >> A migration is a Ruby script. >> The Rails sugar helps you tell the application (for instance): >> "Hey there! I need you to add a column to this table. And while you''re >> at it, check every row, and do this on every row, so we can populate >> that new column." >> > If the value of the column is the same for every row, can''t you just > use default value when you create the column? >That is true - but since he mentioned a bit.ly link, I thought it would be different for every row. -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Aldric Giacomoni wrote:> That is true - but since he mentioned a bit.ly link, I thought it would > be different for every row.You are 100% right that it will be different for each row. With the help of others on this forum I have written a callback function which provides me with a bitly link at creation time of a new record. I believe that I can use the same function and provide it the required information but the biggest question I have right now is how to make that call? I could not see a decent example on google where the database was being populated using a function at creation time. So any help in this regards will keep me going. -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Also I posted the same question on the ruby forum and one suggestion so far is that For one-shot scripts that are not exactly migrations, it should be an acceptable way to use an external script. I find some weight in this as well as what if I need to redeploy the same app on a new server, with fresh data, if the code to add the bitly is in the migration, it will be useless and just adding weight to the app. Thoughts? -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Quee WM wrote:> Aldric Giacomoni wrote: >> That is true - but since he mentioned a bit.ly link, I thought it would >> be different for every row. > > You are 100% right that it will be different for each row. With the help > of others on this forum I have written a callback function which > provides me with a bitly link at creation time of a new record. > > I believe that I can use the same function and provide it the required > information but the biggest question I have right now is how to make > that call? I could not see a decent example on google where the database > was being populated using a function at creation time. So any help in > this regards will keep me going.Your Rails app classes are accessible in migrations, so you can call the bit.ly link generator just like you would from the application itself. At this point, stop asking questions and go write some migration code. If you run into trouble, then come back, ask, and post the code you have. We could talk about this all year, but now is the time for code. Best, -- Marnen Laibow-Koser http://www.marnen.org marnen-sbuyVjPbboAdnm+yROfE0A@public.gmane.org -- Posted via http://www.ruby-forum.com/. --0022158df84ff6ebc8047c95e842 Content-Type: text/plain; charset=ISO-8859-1 -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en. --0022158df84ff6ebc8047c95e842--
Quee WM wrote:> Also I posted the same question on the ruby forum and one suggestion so > far is that > > For one-shot scripts that are not exactly migrations,But this is exactly a migration. It gets the database from one consistent state to the next. That''s the definition of a migration.> it should be an > acceptable way to use an external script.You were told it would be possible, not advisable.> I find some weight in this as > well as what if I need to redeploy the same app on a new server, with > fresh data, if the code to add the bitly is in the migration, it will be > useless and just adding weight to the app.No. If you redeploy the app to a new server, you shouldn''t be running the old migrations. The preferred way to do initial DB setup is with rake db:schema:load. Migrations are only for DB changes.> > Thoughts?I don''t know why you''re being so resistant to migrations when you''re doing the exact task they were meant for. Best, -- Marnen Laibow-Koser http://www.marnen.org marnen-sbuyVjPbboAdnm+yROfE0A@public.gmane.org -- Posted via http://www.ruby-forum.com/. --001485f85a0c251dec047c95f70e Content-Type: text/plain; charset=ISO-8859-1 -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en. --001485f85a0c251dec047c95f70e--
> Your Rails app classes are accessible in migrations, so you can call the > bit.ly link generator just like you would from the application itself.Thanks for the info, did not know this before.> > At this point, stop asking questions and go write some migration code. > If you run into trouble, then come back, ask, and post the code you > have. We could talk about this all year, but now is the time for code. >I would love to start coding, but want to have all my ducks in a row that i do it right. :)> But this is exactly a migration. It gets the database from one > consistent state to the next. That''s the definition of a migration. > > You were told it would be possible, not advisable.Thanks for the clarification and making a very strong point. :)> No. If you redeploy the app to a new server, you shouldn''t be running > the old migrations. The preferred way to do initial DB setup is with > rake db:schema:load. Migrations are only for DB changes.Did not know this as have not reached that point yet and have not come across the issue. I learn and appreciate ruby more and more every day.> I don''t know why you''re being so resistant to migrations when you''re > doing the exact task they were meant for. >Not being resistant at all, just learning. The role of migrations is much more clear to me now so will be fairly confident to play with them. Just as you said time to code, and then come back with questions. Thanks for all the help guys. :) -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.