Sha256: f51b692c5539f346d0282b074829e8a0f399170625685e0808d577d4f2142495

Contents?: true

Size: 1.27 KB

Versions: 5

Compression:

Stored size: 1.27 KB

Contents

# = Mysql to PostgreSQL migration example.
#
# A simple example to demonstrate the flexibility of
# Og. Two connections to different databases are 
# created and data is copied from a MySQL database
# to a PostgreSQL database.
#
# Og makes it easier to switch to a REAL database :)

require 'og'

# Configure databases.

psql_config = {
	:destroy => true,
	:name => 'test',
	:store => 'psql',
	:user => 'postgres',
	:password => 'navelrulez'
}

mysql_config = {
	:destroy => true,
	:name => 'test',
	:store => 'mysql',
	:user => 'root',
	:password => 'navelrulez'
}

# Initialize Og.

psql = Og.connect(psql_config)
mysql = Og.connect(mysql_config)

# An example managed object.
# Looks like an ordinary Ruby object.

class Article
	property :name, :body, String

	def initialize(name = nil, body = nil)
		@name, @body = name, body
	end
end

# First populate the mysql database.

mysql.manage(Article)

a1 = Article.create('name1', 'body1')
a1 = Article.create('name1', 'body1')
a1 = Article.create('name1', 'body1')

# Read all articles from Mysql.

articles = Article.all

# Switch to PostgreSQL.

psql.manage(Article)

# Store all articles.

for article in articles
	article.insert
end

# Fetch an article from PostgreSQL
# as an example. Lookup by name.

article = Article.find_by_name('name1')

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
og-0.17.0 examples/mysql_to_psql.rb
og-0.18.0 examples/mysql_to_psql.rb
og-0.19.0 examples/mysql_to_psql.rb
og-0.18.1 examples/mysql_to_psql.rb
og-0.20.0 examples/mysql_to_psql.rb