Archive for the ‘rails’ category

Haven’t had a dream in a long time

March 18th, 2009

So the latest book, Pro Linux System Administration, is almost done.  One chapter to submit and then the copy-edits and proofs and it’s a done deal.

Must admit this was a lot of hard work.  Incredibly unmotivated on a few occasions and whilst I think I need a little break from writing I’ve got another project to finish this year.

I’ve worked out I’ve written somewhere in the region of a thousand pages in the last five years.  Which is quite a bit really – somewhere in the region of 500,000 words.  Just thinking about it makes me tired.

Migrating a Rails database from Sqlite3 to MySQL

August 25th, 2008

Warning: array_keys() [function.array-keys]: The first argument should be an array in /home/kartar/www/www/wp-content/plugins/simple-tags/inc/client.php on line 1310

Warning: shuffle() expects parameter 1 to be array, null given in /home/kartar/www/www/wp-content/plugins/simple-tags/inc/client.php on line 1311

Warning: Invalid argument supplied for foreach() in /home/kartar/www/www/wp-content/plugins/simple-tags/inc/client.php on line 1312

So when I first looked at Redmine I ran it up and used Sqlite3 as the database back-end. Then when I migrated our Trac data I just left Sqlite3 as the back-end database and migrated our data to that. With that startling lack of forethought aside, I always had the view the database should be MySQL because well:

a) I know it
b) I like it
c) It’s probably more scalable (IMHO)

So today I actually sat down to do the migration piece. I dumped out the sqlite3 database and tried to do some manual/scripted edits to convert it to something MySQL would import. Epic Fail.

So I tried the YAMLdb that abstracts database exports using YAML. A quick installation, some edits to config/database.yml, a rake db:dump and rake db:load and the data was moved:

… Create our database …

$ sudo mysql -p
mysql> create database redmine character set utf8;

… Grant privs to your chosen user …

mysql> GRANT ...

… Configure a test database for our new MySQL database …

$ vim config/database.yml

.. for Rails version 2.1 and later install the plugin …

$ sudo script/plugin install
git://github.com/adamwiggins/yaml_db.git

.. for Rails versions less than 2.1 use …

$ sudo script/plugin install http://github.com/adamwiggins/yaml_db.git

… Dump out the current production database …

$ sudo rake db:dump RAILS_ENV=production

… Load the freshly created db/data.yml file into our test database …

$ sudo rake db:load RAILS_ENV=test

… Reconfigure the application to point to the new MySQL database as production …

$ vim config/database.yml

… Start Redmine …

$ sudo /etc/init.d/mongrel_cluster start

Had one bad field I had to do some manual editing too – still not quite sure what was wrong with the field but whatever I did fixed it – but otherwise very smooth.

Started up and now Redmine runs perfectly with MySQL as the back-end!