<p>I have a rails application where each user has a separate database. (taking Joel Spolsky's advice on this). I want to run DB migrations from the rails application to create a new database and tables for this user. </p>

<p>What is the easiest way to do this? </p>

<p>Maybe the db migration is not the best for this type of thing. Thanks!</p>

<hr>

<p>It would be nice if it could be a completely automated process. The following process would be ideal.</p>

<ol>
<li>A user signs up on our site to use this web app</li>
<li>Migrations are run to create this users database and get tables setup correctly</li>
</ol>

<p>Is there a way of calling a rake task from a ruby application?</p>

[{'answer_id': 38927, 'author': 'roo', 'author_id': 716, 'author_profile': 'https://Stackoverflow.com/users/716', 'pm_score': 1, 'selected': False, 'text': "<p>We use seperate configuration files for each user. So in the config/ dir we would have roo.database.yml which would connect to my personal database, and I would  copy that over the database.yml file that is used by rails.</p>\n\n<p>We were thinking of expanding the rails Rakefile so we could specify the developer as a environment variable, which would then select a specfic datbase configuration, allowing us to only have one database.yml file. We haven't done this though as the above method works well enough.</p>\n"}, {'answer_id': 40015, 'author': 'Jordi Bunster', 'author_id': 4272, 'author_profile': 'https://Stackoverflow.com/users/4272', 'pm_score': 2, 'selected': True, 'text': "<p>To answer part of your question, here's how you'd run a rake task from inside Rails code:</p>\n\n<pre><code>require 'rake'\nload 'path/to/task.rake'\n\nRake::Task['foo:bar:baz'].invoke\n</code></pre>\n\n<p>Mind you, I have no idea how (or why) you could have one database per user.</p>\n"}, {'answer_id': 44484, 'author': 'Kevin Kaske', 'author_id': 2737, 'author_profile': 'https://Stackoverflow.com/users/2737', 'pm_score': 0, 'selected': False, 'text': '<p>Actually I have discovered a good way to run DB migrations from an application:</p>\n\n<blockquote>\n  <p>ActiveRecord::Migrator.migrate("db/migrate/")</p>\n</blockquote>\n'}]
['https://Stackoverflow.com/questions/38922', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/2737/']