Vagabond asked:

:evolve schema

Tags:

What is it, and why does Og tell me I have an obselete field and I need to set :evolve_schema or take it out of cautious mode?

(4 attempts)

Kashia answered:

Another possibility why Og tells you that there are obsolete fields:

When you use inheritance.

class Foo
  is InheritanceBase # or schema_inheritance
  property :prop_one, String
end

class Bar < Foo
  property :prop_two, String
end

Ruby will first load the Foo class, then Og will look in the Database, and will find 4 columns in the table "ogfoo" :

  • oid
  • type
  • prop_one
  • prop_two

Of course, it doesn't know where "prop_two" came from, the second class didn't get loaded from Ruby yet.

Og complains now about that seemingly obsolete field, but after Ruby loads the Bar class, everything is consistent again.

So, long text short: In case you use inheritance, just don't look at the obsolete field messages.

Rating: 5

Fabian answered:

If :evolve_schema is set and you modify your Model, it changes it in the database too (evolving the tables). If it's set to cautious it doesn't delete properties from the tables I think (not sure though).

Rating: 3

Kashia answered:

Here:

Og.setup(
  :destroy => false,
  :evolve_schema => true,
  :store => :psql,
  :name => 'oxyliquit'
  )

This is, when you set up your Og in a non cautious mode, note the :evolve_schema.

To set Og to cautious again, use:

:evolve_schema_cautious => true

Rating: 3

bsoto answered:

On startup, Og will check that your classes and the database tables match. If your persisted class defines a property that isn't reflected in the database or if the database has a field that you removed, you have a mismatch. That's where :evolveschema and :evolveschema_cautious come in.

If you set :evolve_schema to true in your Og.setup, Og will automatically bring your database up to date by adding any fields you've added to the table.

By default, :evolve_schema is false, so the tables won't be modified unless you change this. The check is still performed and you will get a message in your log informing you about the mismatch.

If you set :evolveschema to true and :evolveschema_cautious to false in your Og.setup, Og will automatically drop any fields that are no longer defined in your classes.

By default, :evolveschemacautious is true. So even if you set :evolve_schema to true, you will still need to change this option as it's rather dangerous and could ruin your day if you make a mistake.

Rating: 0