Is it possible to create a database and tables in runtime, in a Rails app?
For example: the server receives a request with some data. Then, it should create a database in PostgreSQL, and create also some tables in that new DB. Is this possible?
Yes, Its possible. Perhaps not recommended.
Using the Sequel gem (http://sequel.jeremyevans.net/) it is possible to create databases in runtime, running an SQL script.
I've tried it only with a PostgreSQL database, not sure if it is possible with others.
For a PostgreSQL database
Connect to the PostgreSQL server
To connect to the PostgreSQL server you always have to define a database to connect to. Use the 'postgres' database, a default database created by the PostgreSQL server (more info: Default database named postgres on Postgresql server).
db = Sequel.postgres('postgres', user, password, host, port)
Run the SQL script to create a database
db.run "CREATE DATABASE my_new_db"