0

I need to get scripts from our DB guy to facilitate populating the database with dummy data for testing.

The database is partitioned over multiple files and uses partition schemes to partition the databases. The script generated by generate scripts currently generates calls to the partition schemes.

How do I get the full database (with or without the partition schemes) create script to be run on my dev database?

2
  • 3
    Specifying database platform would be helpful when asking such question. Commented Jul 8, 2011 at 17:16
  • SQLServer. I figured it out... He wasn't generating the dependant objects Commented Jul 12, 2011 at 0:03

1 Answer 1

0

I don't understand at all your question, so I'll give you two answers.

First answer:

After search a lot over the Internet and forums, I think I found a solution for your problem that require just one line of code.

I found a good gem that do exactly what you want, but for single models, array of objects and objects. Also, this gem only works for Rails 3.2 and older. I talked with author and he doesn't want support this gem anymore. So I discovered by myself how to support Rails 4.0 and now I'm maintaining this gem.

Download the "models-to-sql-rails" gem here, supporting Rails 4.0 and older.


With this gem, you can easily do the following. (the examples inside values are just a joke, you will get the correct values when using it in your object).

For objects:

object.to_sql_insert
# INSERT INTO modelName (field1, field2) VALUES ('Wow, amaze gem', 'much doge')

For array of objects:

array_of_objects.to_sql_insert
# INSERT INTO modelName (field1, field2) VALUES ('Awesome doge', "im *Censored* cop")
# INSERT INTO modelName (field1, field2) VALUES ('much profit', 'much doge')
# (...)

For a model:

Model.all.to_sql_insert
# INSERT INTO modelName (field1, field2) VALUES ('Awesome doge', "im *Censored* cop")
# INSERT INTO modelName (field1, field2) VALUES ('much profit', 'much doge')
# (...)

Just see the Github of this project and you'll find how to install and use this wonderful gem.

Second answer:

Following this answer, you can dump all your database simply using mysqldump.

mysqldump [options] db_name [tbl_name ...]

Will generate the script file including the create and inserts necessary for the tables selected. To import the dump you can simply do:

mysql -u <user> -p dbname < mys.dmp

Hope it helps.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.