Monthly Archives: July 2014

Today I’ve migrated the database of Ruby on Rails project from Sqlite to MySQL. It’s not first time I’ve done it. So, I decided to note it as a post.
First of all, it needs to add special yaml_db gem to the project:
gem ‘yaml_db’
It allows us to dump all data from the storage by command like:
RAILS_ENV=production rake db:dump
then switch the storage (production inour case) from Sqlite to MySQL in config/database.yml file and load the data back to the storage:
RAILS_ENV=production rake db:load
in this case into MySQL backend.

It’s a preferred way of such migration because of its pure abstract yaml representation of the data. It doesn’t depend on specific SQL.

Git is used broadly for now. Let’s look at interesting use case. Assume, we have the development machine and the live server. I’m going to hold the project in local git repo on development machine. From time to time it needs to deploy stable version to the live server as a release.

Just for demostration, I use 2 local directories /tmp/dev and /tmp/server:

mkdir /tmp/dev
mkdir /tmp/server

Then I init new repo and add some test file in the release branch on the dev side:

cd /tmp/dev
git init
git checkout -b release
vim test.txt
git add test.txt
git commit -m “initial commit”

Now I create empty repo on the server side and checkout for server branch:

cd /tmp/server
git init
git checkout -b server

Next step is to configure and pushing prepared release to the server:

cd /tmp/dev
git remote add server file:////tmp/server
git push server release

Here we use local file URL. In real situation it needs SSH one, like ssh://login@host:port/path/to/project.
Last stage is to merge just pushed version from release branch to current one (server) on the server:

cd /tmp/server
git merge release

At this point the new version is on the server side.

Usually, we host the repo of the project on github or bitbucket. Last one even allows to create private repo’s if you are not ready to share your code with the world yet. So, described above example should be treated rather as an exception then standard use case.