views:

222

answers:

1

Hello, I have an existing table that I'd like to use for a Rails application. It's a simple table with only 4 columns. However it does not yet have id column. And also new data will be added periodically.

I am trying to find a way to add the id column and populate it.

I guess I have two options, but being a noob I am sure there are better ways.

Option 1: I can add the id column and populate it when I parse raw data into CSV files, and then import it to the Rails database. In this case, when I parse the data into CSV files, I need to figure out how to find the last used unique id is.

Option 2: Parse raw data into CSV files, then import to the Rails database. Then my rails application will populate the id column for the new data entries.

If Rails has a built in method or GEM that can populate the id fields for the new entries, that would be great. In that case I will go with the Option 2.

If not, I think it's easier to go with the Option 1.

So I guess the question becomes this: Can Rails automatically populate the id column of entries with blank id field?

Thanks!

+1  A: 

Either option should work because the underlying database will automatically handle the id column since it's the primary key. So create the table using a migration, then parse, import, and add the CSV data to your database via which ever method sits best.

askegg