Jump to content

The ultimate community for Ruby on Rails developers.


Photo

Beginner - dump.sql file into Ruby on Rails


  • Please log in to reply
3 replies to this topic

#1 Ruegen

Ruegen

    Passenger

  • Members
  • 6 posts

Posted 10 March 2014 - 04:24 AM

Hi I'm new to all this

 

I have a database table exported as a dump file "dump.sql" which I have saved into the db folder in my app.

 

How (and I am guessing using the models) do I call the data from the sql database?

 

Do I need to create a .rb file in the models folder that points to the dump.sql?

 

Do I only reference the table name then field?

 

 



#2 james

james

    Guard

  • Moderators
  • 223 posts
  • LocationLeeds, U.K.

Posted 10 March 2014 - 09:37 AM

You should import the dump.sql file into your sqlite database then create a file in the model folder named after the table that is generated from the import.

If the mode is named correctly i.e. camel cased file name that matches the table name then all should be good and all you should need is a standard model class declaration in the file.

 

e.g. If the imported table is called new_imported_table then the file should be called NewImportedTable and the class declaration in the file should be

 

class NewImportedTable < ActiveRecord::Base

 

end

But you are heading for a fall! How are you going to get your imported table into your production and your test databases?

 

I would strongly suggest you use the rails generate model some_table_name command to generate the table and write a migration to import the data from a csv file, that way, if you convert the dump.sql into a csv file that gets added to a folder somewhere (I would suggest the database folder) then when you run rake db:migrate whether you are in your test, development or production mode you will get the data imported automatically for you and you won;t have to worry about your tests or your production environent not haviong the dumped data available to it and your job is done with regards to the imported table.


Programming is just about problem solving!


#3 Ruegen

Ruegen

    Passenger

  • Members
  • 6 posts

Posted 11 March 2014 - 02:25 AM

Gasp  :blink:

 

ok makes perfect sense - I'm crushed there isn't an easier way yet :(

 

I will update once successful with the steps I took

 

Thanks :D



#4 james

james

    Guard

  • Moderators
  • 223 posts
  • LocationLeeds, U.K.

Posted 11 March 2014 - 01:06 PM

O.K. Sorry for scaring you!

It's dead simple really! What is it that you are finding complicated? Perhaps you could explain a little more about your requirements


Programming is just about problem solving!





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users