»
S
I
D
E
B
A
R
«
Evejob Development Environment Installation Part #8: Configuring applications to work with MySQL
Nov 2nd, 2009 by evereq

Django

We will need to use MySQL for Python project for connection from Django Python code to MySQL database. Because I (and hope you also) use Windows 7 64 bit with Python 64 bit, needs to found and install 64 bit version of such library. On original project site, for some reason I could not found (at least in the moment when I write post), so I get it from different site:  http://www.codegood.com/download/3/. Just download and install it (it will automatically found your Python installation if you follow all steps that I write in previous posts).

Let’s configure now, EvejobDJ project to use MySQL database.

First, needs to create “EvejobDJ” database schema using one of the administration tools, for example, described in Part #7 – just create it visually or issue following SQL command:

CREATE DATABASE EvejobDJ;

Open “settings.py” file in root folder of EvejobDJ project inside IntelliJ IDEA IDE and change database engine parameters to following:

DATABASE_ENGINE = 'mysql'           # 'postgresql_psycopg2', 'postgresql', 'mysql', 'sqlite3' or 'oracle'.
DATABASE_NAME = 'evejobdj'         # Or path to database file if using sqlite3.
DATABASE_USER = 'root'                # Not used with sqlite3.
DATABASE_PASSWORD = ''             # Not used with sqlite3.
DATABASE_HOST = ''                     # Set to empty string for localhost. Not used with sqlite3.
DATABASE_PORT = ''                     # Set to empty string for default. Not used with sqlite3.

Now it is time to test connection and create default tables in database (for authentication, sessions etc):

cd C:\Evejob\EvejobDJ
python manage.py syncdb

Hopefully you will get something like this in response:

EvejobDJDatabaseCreate

As you see you will need to create default “superuser” (I just put “admin” as his username and “info at evejob.com” as his email) because Django authentication app enabled by default.

Now you can check in MySQL database administration tool that you really create tables (screenshot from free MySQL Administrator that you probably install with MySQL GUI Tools):

MySQLEvejobDJDatabaseJustCreated

Ruby On Rails

To use MySQL in Ruby On Rails (RoR) we need to install MySQL Adapter, for example:

ruby -S gem install mysql

But here we get into trouble – binaries of this gem (mysql) does not work correctly on Windows 64 bit and on project site there is no version for 64 bit OS…
While on some “Unix” OS it is possible to fix this issue (for example build gem from source…), on Windows it is simply not possible…
Ah, OK, OK… it is possible, but just too complex / time consuming – don’t want to spend time on this NOW and leave this time to focus on coding of Evejob… maybe somebody or author of gem will fix this issue later!

Note: other available adapters for MySQL from Ruby seems also have same problems… at least by now.

So let’s just temporary switch to PostgreSQL for Ruby on Rails version of Evejob.

To setup PostgreSQL for EvejobRoR development it takes just few minutes:

  • Download and install latest PostgreSQL from http://www.enterprisedb.com/products/pgdownload.do#windows. Installation is trivial same like for MySQL (sure same – configuration is NOT trivial for production usage!). Make sure that you remember password that you put for “postgres” login role (default database user name).
  • Create “EvejobRoR_development” database in PgAdmin (this app comes with PostgreSQL… very similar to MySQL Administrator) and select “postgres” role as owner for this database.
  • Open EvejobRoR project in IntelliJ IDEA and copy file “config\database.yml” to “config\database_mysql.yml” (we will need it again when fix issue with MySQL + Ruby)
  • Edit file “config\database.yml” and enter here following information (make sure you put your password instead of my fake “admin”):
    development:
      adapter: postgresql
      encoding: utf8
      reconnect: false
      database: EvejobRoR_development
      pool: 5
      username: postgres
      password: admin
      host: localhost
     
    test:
      adapter: postgresql
      encoding: utf8
      reconnect: false
      database: EvejobRoR_test
      pool: 5
      username: postgres
      password: admin
      host: localhost
     
    production:
      adapter: postgresql
      encoding: utf8
      reconnect: false
      database: EvejobRoR_production
      pool: 5
      username: postgres
      password:  admin
      host: localhost
  • Execute following commands:
    ruby -S gem install postgres-pr

    This will install PostgreSQL adapter for Ruby (gem “postgres-pr” works on Windows x64)

    Now you can try to execute database “migration” that will hopefully create some stuff in development database:

    cd c:\Evejob\EvejobRoR
    c:\ruby\bin\rake db:migrate

    It will be to simple if this will work for you from first attempt! On my machine, I was need to made small “hack” to made this work, i.e. to add following code into new_rails_defaults.rb file in “config\initializers” folder and run db:migrate again:

    def PGconn.quote_ident(name)
        %("#{name}")
    end

    (look for more info about this “hack” here)

If you complete everything, you can check that db:migrate actually create one table (”schema_migrations”) in your development database:

pgAdmin_Shema_migrations_table

Grails

Let’s configure last version of Evejob which going to use MySQL database – EvejobGoG.

First, needs to create “evejobGoG_development”, “evejobGoG_test” and “evejobGoG_production” empty databases. You can do this trivial task using MySQL Administrator GUI Tool for example.

Next step is to let know Grails how to connect to just created MySQL databases. Because Grails runs on Groovy and Groovy itself runs in JVM we can use MySQL Connector/J from MySQL site: http://dev.mysql.com/downloads/connector/j/

Download “zip” file, unpack it to temporary folder and copy mysql-connector-java-x.x.xx-bin.jar file to the C:\evejob\EvejobGoG\lib folder.

Now open EvejobGoG project in IntelliJ IDEA and found DataSource.groovy file located in “EvejobGoG\Grails-app\conf” folder. Let’s change some settings in this file:

dataSource {
	pooled = true
	driverClassName = "com.mysql.jdbc.Driver" //"org.hsqldb.jdbcDriver"
	username = "root"
	password = ""
    dialect = "org.hibernate.dialect.MySQL5InnoDBDialect"
}
hibernate {
    cache.use_second_level_cache=true
    cache.use_query_cache=true
    cache.provider_class='com.opensymphony.oscache.hibernate.OSCacheProvider'
}
// environment specific settings
environments {
	development {
		dataSource {
			dbCreate = "update" // one of 'create', 'create-drop','update'
			url = "jdbc:mysql://localhost/evejobGoG_development" // "jdbc:hsqldb:mem:devDB"
		}
	}
	test {
		dataSource {
			dbCreate = "update"
			url = "jdbc:mysql://localhost/evejobGoG_test" // "jdbc:hsqldb:mem:testDb"
		}
	}
	production {
		dataSource {
			dbCreate = "update"
			url = "jdbc:mysql://localhost/evejobGoG_production" // "jdbc:hsqldb:file:prodDb;shutdown=true"
		}
	}
}

Now Grails know how to connect to MySQL. Unfortunately, there is no build-in database migrations functionality in Grails framework yet, so our next step is to install some plug-ins that can help us to maintain database schema versions and migrations. While exists few of such plug-ins, I think most “featured” is LiquiBase (but also you can take a look into “Autobase” if you prefer to dial with DSL instead of XML… just take a note that this plugin works only with Grails, while LiquiBase can be used with Ant, Maven, Spring etc or even independently as database change management solution)

To install LiquiBase do following (you can read more regarding Grails integration with LiquidBase here):

cd C:\evejob\EvejobGoG
grails install-plugin liquibase

Now check that you have following folder (that is empty by now):

C:\evejob\EvejobGoG\grails-app\migrations

If you don’t have folder yet, just create it before continue with migrations – this folder will be used to save migrations change log etc..

Now it’s time to generate change log and migrate database (that is empty for now) to initial version:

grails generate-changelog grails-app\migrations\changelog.xml
grails migrate

After first command (”generate-changelog”) LiquiBase will create initial version of database change log and save it to the “C:\evejob\EvejobGoG\grails-app\migrations\changelog.xml” file. It will looks something like following:

Second command (”grails migrate”) will actually made migration in database. In our case because our domain is empty, LiquiBase will just create changes maintenance tables: “databasechangelog” and “databasechangeloglock”. You can check now this using MySQL Administrator:

LiquiBaseInitialTables

If all steps above completed successfully you finish setup EvejobGoG Grails project to use MySQL Database and have ability to migrate databases!

Evejob Development Environment Installation Part #7: Installation of MySQL Database & Tools
Nov 1st, 2009 by evereq

We are going to use MySQL database for all “Evejob” versions, except versions for  .NET platform.

So let’s install MySQL Community Edition Server. You can get installation files from http://dev.mysql.com/downloads/mysql/

Be sure that you download 64 bit version for Windows, like Windows MSI Installer (AMD64 / Intel EM64T), from here http://dev.mysql.com/downloads/mysql/5.1.html#winx64 for example.

Installation of MySQL for Windows is simple operation (in contrast to configuration MySQL for production usage), so I will skip installation steps here… We can leave all settings by default – it’s enough for development purposes on local machine.

To manage database you can download GUI Tools from http://dev.mysql.com/downloads/gui-tools/.

Also note that exists A LOT of free / not free and excellent tools to manage / design MySQL databases (for both development and production).

I will list here just some of them:

  • MySQL Workbench – “visual database design application that can be used to efficiently design, manage and document database”
  • Navicat for MySQL – powerful database administration and development tool (without complex visual design features) available in both commercial and Non-commercial (Free) Lite version
  • DevArt dbForge Studio for MySQL – “cutting-edge administration tool and development environment for professional working with MySQL databases” and this is TRUE! Best that I see for MySQL!!! Highly recommended! Sure Express version (that is free) is very limited, so probably after 30 days trial period you will buy Non-Commercial Professional Edition License (cost only 99$) or Commercial for 199$ (more info about versions / prices here)
  • SQLyog MySQL – “the most powerful MySQL manager and admin tool, combining the features of MySQL Query Browser, Administrator, phpMyAdmin and various other MySQL Front Ends and MySQL GUI tools in a single intuitive interface” – actually I think this tools make sense to use more during maintenance period than during development and because they are not free I recommend to skip them for now…

After installation of MySQL, you just need to know for development following information (that you setup during installation):

  1. Server Host (”localhost” in your case, if you install it on your local machine) and port (default 3306)
  2. Username (usually root)
  3. Password (you enter it during installation of MySQL or even possible you leave it blank – sure NOT for production!)

Now using this connection parameters, you can run MySQL Administrator (from GUI MySQL Tools) or any administrator utility and check connectivity. If everything OK and you see all 3 schemes (”information_schema”, “mysql” and “test”), you can move forward and start development using MySQL as primary database.

Evejob Development Environment Installation Part #5: Ruby, JRuby and Rails + AppEngine Installation
Oct 28th, 2009 by evereq

Ruby installation

Let’s start from Ruby installation. We can download Windows One-Click Installer from http://rubyforge.org/frs/?group_id=167, for example ruby186-27_rc2.exe

During installation, make sure that you select at least “Enable RubyGems” option:

RubyInstallation

You can leave default installation folder (C:\Ruby).

Ones you finish installation, you can run both “ruby” and “gem”  from withing your command line.

So it’s time to install Rails, just type in command prompt:

gem install rails

and wait few minutes to finish installation.

JRuby installation

Download installation package from http://jruby.org/download. We will need binary Windows version, for example JRuby 1.4.0RC1 Binary .zip. Extract folder content to C:\JRuby folder and add path to the JRuby to your PATH variable:

JRubyPath

Let’s test installation:

JRubyTestInstallation

Now both Ruby and JRuby installed.

The problems starts when we will try to simultaneously use them (side by side)… First of all, make sure that you delete RUBYOPT environment variable (because it seems like JRuby gems did not work correctly if this variable setup). Now you can invoke each “gem” using following commands:

For Ruby:   ruby -S gem

For JRuby:  jruby -S gem

For example this is what I get on my machine:

GemSideBySide

Note: it is actually not a big problem that I had 2 different versions of Gem on my machine – both versions (1.3.1 and 1.3.5 works well for me… update of gem 1.3.1 fails for some reasons on my machine, so I decide to leave this for now…)

One small thing to do: it is possible that you have old version 1.3.1 of RubyGems like me (in the moment when I write this, latest version is 1.3.5 like was installed for JRuby). If we leave it, we can face some problems in future with IDEA etc, so let’s just update it:

UpdateRubyGems

Also, let’s install jruby-openssl (IDEA generate Error if this gem not installed):

OpenSSLforJRuby

Rails Installation

Next step is installation of Rails – just type following commands (it is better to just install Rails twice than to share same installation for both Ruby and JRuby):

ruby -S gem install rails
jruby -S gem install rails

EvejobRoR and EvejobRoRG Project

We going to create 2 separate projects now:

EvejobRoR – will use Rails build in ActiveRecord + MySQL database

EvejobRoRG – will use App Engine hosting, datastore and Google Accounts for user authentication APIs

Let’s start from more simple EvejobRoR:

cd c:\evejob
rails EvejobRoR -d mysql

Now let’s open this “template” project in IDEA:

File -> New Project -> Create project from scratch:

CreateRubyProjectInIDEA

Change here “Project files location” to the “C:\evejob\EvejobRoR”, select “Ruby Module” and press next (see screenshot above)

Now you need to specify the Ruby SDK (current version of IDEA can’t detect SDK locations from environment variables). Press “Configure…” button and press “+” button in “Configure JDK” window:

AddRubySDK

Select “Ruby SDK” in popup and than select Ruby interpreter path:

SetRubyPath

I Hope you will get something like this:

RubySDKAddedToIDEA

If so, just press “OK” and continue IDEA project creation Wizard:

ContinueRubyProjectCreationWizardInIDEA

Select “Ruby on Rails” on next screen and press “More…”  for Rails Facet configuration:

SelectRubyOnRailsTechnology

RailsFacetSettings

Make sure that you select “Use existing Rails application” and “Preconfigure for selected database” to “mysql” like (see picture above)

Now fill free to finish project creation Wizard. Done! We get EvejobRoR project loaded into IDEA.

Same steps we need to made for EvejobRoRG project, with small difference that this time we need to add JRuby SDK, instead of Ruby SDK like before and that we don’t want to support mysql as we are going to use Google App Engine API instead.

So, first type:

cd c:\evejob
rails EvejobRoRG

Then same like before, create new project in IDEA, put here “C:\evejob\EvejobRoRG” path and in “Specify the Ruby SDK” press “Configure…” and add JRuby SDK:

JRubySDKInIDEA

After made same steps like was done for EvejobRoR project, just make sure that you unselect “Preconfigure for selected database” check box in Rails Facet Settings dialog and process steps like before to finish Wizard.

Hopefully you get EvejobRoRG project opened in IDEA!

Prepare JRuby / Rails for Google App Engine

Google App Engine runs Java applications, so we need to make sure that we can assemble our JRails applications into a Java Web Archive (.war). To do such tasks easy, let’s first install “warbler” gem:

jruby -S gem install warbler

Now it is time to check that you add Java JDK path to windows PATH environment variable (because “warbler” gem use JDK):

JDKPathToPATHVariable

Next step, to run following commands from application root folder (c:\evejob\EvejobRoRG):

jruby -S warble pluginize
jruby -S warble config

(make sure you type “warble”, not “warbler” that is just Gem name)

Now you can just check that “Warbler” works:

jruby -S warble

As result you must see EvejobRoRG.war file generated in application root folder (c:\evejob\EvejobRoRG)

We can’t use this .war file directly for Google App Engine for few reasons, but at least we see that we can get some .war file :)

I specially not use all appengine-jruby project gems for few reasons:

  • google-appengine gem install own “tuned” version of JRuby that we want to avoid for reasons, for example for quick updates as we don’t want to depend on this special version of JRuby etc (means that project must be installed using Ruby, not JRuby! And only after installation it download and install customized, ‘frozen’ version of JRuby)
  • google-appengine helps to run JRuby on Google App Engine, but not to run Rails on Google App Engine ! :) All problems related to Rails on App Engine are still exists (read more at http://code.google.com/p/appengine-jruby/wiki/RunningRails)

But what I do use is one of the gems from appengine-ruby project – “appengine-apis”, so let’s install it:

jruby -S gem install appengine-apis

Read this for now to get more information about Rails and Google App Engine specific things:

http://olabini.com/blog/2009/04/jruby-on-rails-on-google-app-engine/

http://www.railshacks.com/2009/4/25/run-your-ruby-on-rails-app-on-google-app-engine

We will get back to this later…

»  Substance: WordPress   »  Style: Ahren Ahimsa
© Copyright 2008–2009 EvereQ.com All rights reserved.