Jim Maher 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.
>> 
>> 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.
> 
> 
> Can you update the database outside of your Rails application?  Yes.
> 
> Should you?  Many would say NO, but in practice I have never yet 
> encountered an app that was ALWAYS updated only with the app.  

You should see my apps, then.  Unless the DB is corrupted (which has 
only happened once), I usually use script/console for data tweaking.

> The DB 
> itself, various utilities, one-time scripts, external apps (e.g., Excel, 
> etc.) are often used.  Be careful, have a backup, be careful again, 
> test, then be VERY careful.

Yes. And this is one reason that I always recommend having data 
integrity constraints in the DB, not just the app.

> 
> Using a plain Ruby script to interact with the datavbase is certainly 
> possible, and not necessarily using ActiveRecord.  You might consider 
> using something like Sequel (v3.8.0), which is a database toolkit for 
> Ruby (I have NOT used this myself).

I have.  But in a Rails app such as the OP has, it is safer not to do 
this.

> 
> But, again, be VERY careful.  Any updates you do outside your app may 
> NOT conform to your business rules.  That's up to you.
> 
> j

Best,
--
Marnen Laibow-Koser
http://www.marnen.org
marnen / marnen.org
-- 
Posted via http://www.ruby-forum.com/.