How to seed mysql database by running sql scripts in Ruby Rails platform? -


i have been java programmer , beginner ruby rails. in java, seed database ant task run, ant task execute sql script. sql script set of insert statements.

i expect there must equivalent of ant task on ruby rails platform running sql script?

edited in response answer nikita:

although 1 can use migration 1 of way seeding data. don't want rework of writing migration classes corresponding sql scripts. need solution through have exec sql script file only. want manage database through sql code.

i don't using migrations seed large amounts of "static" data. can execute sql statements db/seeds.rb by:

# empty soon-to-be-seeded table mymodel.delete_all  # current db connection connection = activerecord::base.connection();  # execute sql statement connection.execute("insert my_models (id, name) values     (1, 'example 1'),     (2, 'example 2'),     (3, 'example 3');") 

basically, once have current connection, can call sql statement useing connection.execute("sql code here").


Comments

Popular posts from this blog

java - SNMP4J General Variable Binding Error -

windows - Python Service Installation - "Could not find PythonClass entry" -

Determine if a XmlNode is empty or null in C#? -