Tilo asked:

Legacy Databases / Schema

What do i need to do to tell Og to be careful with pre-existing ('legacy') databases, so that: 1) the schema does not get changed 2) no columns / rows / tables get dropped

Can Og determine the schema of a given MySQL Database, and automatically create a skeleton of matching Class definitions? (without relations ..)

Such a reverse engineered mode would be good for people who want to use a legacy database with Og

T.

(1 attempts)

Kashia answered:

You just have to model the Og classes after the real tables and adapt:

class User
   # To use a different pk
   attr_accessor :id, Fixnum, :primary_key => true
 
   # custom join tables
   joins_many :pictures, Picture, :through => ModelPics
end
 
class ModelPics
   # set the sql table
   set_sql_table "join_table_foo"
 
   # has_ones are needed to generate the correct relations
 
   # for example specify a special foreign key
   has_one OgModel, :foreign_key => 'to_model'
   has_one Picture
end
 
class Picture
 
end

This as an example on how to change the primary key, set sql tables, modeling join tables and using custom foreign keys.

Additional to that, if you want to forbid Og to change the Tables at all:

# Completely shut generating off

Og.create_schema = false

# Control generating

# :add/true meaning columns get added, none removed
# :full meaning columns also get removed

Og.manager_options.update(
  :evolve_schema => :add
)

# ..

Og.start

Rating: 5