Migrate to .sql file

Would anyone know how to make "rake migrate" or "rake db:schema:load" produce an SQL file instead of operating directly on the DB?

The reason that I ask is that my ROR hosting (servage) does not seem to allow me to connect to the DB server from the internet or to execute rake.

So am I stuck with creating the SQL manually or will rails do it for me?

rake db:structure:dump # Dump the database structure to a SQL file

also try ‘rake -T’ for a list of helpful rake tasks

Thanks David,

But when I look into databases.rake, it appears that it actually uses the client for the given DB to make the dump from the DB.

It seems that I forgot to mention that I use postgresql for development and my hosting service uses MySQL. So the schema that I get from my development DB is unusable on the hosting service.

I guess that I should just use MySQL for development... ...Or implement "rake db:schema:generate".

If you intention is to be able to use MySQL for your production server and Postgres for your development then you could just set them up in your config/database.yml file as such.

If you use ‘rake db:schema:dump RAILS_ENV=development’ against your Postgres/dev database, this will create a rubified schema of your database. You could then use ‘rake db:schema:load RAILS_ENV=production’ against your MySQL/env database. (This is presuming that you have set your database.yml to reflect these configurations.)

btw…this will not give you a true dump of your database (with all of the data), just the schema.

If the problem is that you do not have shell access to your server and so cannot call ‘rake’ from the command line there, but have to update the database schma through some other web based sql loader, then I would recommend just switching your local database to whatever you are using for your production and save yourself the frustration. Simply solve the problem and solve the problem simply as they say.

Hope this helps.

It did help. I go for "Simply solve the problem and solve the problem simply as they say" and install MySQL.

And then I will dream of having the time and skills to implement "rake db:schema:generate".

Thanks.