0

I have a rails app setup on a google cloud instance. I want to have the db in a SQL instance for the extra performance. But I cant see how to do this for a rails app.

I understand you create the SQL instance, start it, install mysql, on it but then how can I have the db and tables added? Creating them manually isn't going to be the solution because normally with rails apps you run rake db:create and rake db:migrate create the DB with tables and columns but this just makes a development.sqlite3 file not a mysql db..

I haven't deployed a rails app before so I think I'm missing something.

Here is my config/databast.yml file

default: &default
  adapter: sqlite3
  pool: 5
  timeout: 5000

development:
  <<: *default
  database: db/development.sqlite3

mysql_settings: &mysql_settings
  adapter: mysql2
  encoding: utf8
  pool: 5
  username: root
  password: root
  host: 130.211.71.150
  database: dbname

test:
  <<: *default
  database: db/test.sqlite3

production:
  <<: *default
  database: db/production.sqlite3

I cant find out what needs to be done to have the db be created and tables and columns migrated into the mysql DB.

Rob
  • 1,835
  • 2
  • 25
  • 53

1 Answers1

1

In your gem file you can put the sqlite gem under a development/test block and you can add the mysql gem in a production block.

In your database.yml file you can keep the development settings you have currently but then add another setting for production settings. Here you can include your mysql db settings (including the host and port of your SQL instance node)

When you launch your app, you can then launch it locally in development mode to use sqlite for development, but when deploying you can launch in production mode to utilize the mysql specific settings. From there you should be able to use db:create db:migrate etc to connect to that host and setup your Db.

Here is a nice article describes this process. https://www.digitalocean.com/community/tutorials/scaling-ruby-on-rails-setting-up-a-dedicated-mysql-server-part-2 As a team, we chose to use mysql for local development as it more closely mimics what your prod environment will be like.

Alex Bezek
  • 467
  • 2
  • 7
  • Ok so should I move the whole of `mysql_settings: &mysql_settings` settings to under `production:` and remove `database: db/production.sqlite3` from under production. or just move the settings that are set under `mysql_settings: &mysql_settings` to be under `production:`? – Rob Apr 27 '16 at 05:31
  • I would probably just delete the mysql_settings section, in your production delete the existing lines (including this: <<: *default ) Then just put your settings that were under mysql_settings under production. If you do switch over to using mysql locally for development, I would put all of the mysql settings under default except the host, db name, and maybe username/password. – Alex Bezek Apr 27 '16 at 13:12
  • Thanks for the help so far. I'm just waiting on this question to be answered before I can see if your solution worked http://stackoverflow.com/questions/36905520/getting-this-error-when-trying-to-create-a-db-with-rake-dbcreate-on-google-coul – Rob Apr 28 '16 at 04:53