Engines & Migrations

No sooner does someone add some notes to the wiki than do we get
support for migrations in Engines. If your Engine has a properly
-formed “db/migrate” folder, you can now use the provided “rake
engines_migrate” task to manage its tables in the database. Find this
code in the development branch of engines
(https://opensvn.csie.org/rails_engines/branches/engines).

CAVEAT EMPTOR!

I.E. Big Huge Warning In Flashing Lights.

PLEASE, PLEASE, PLEASE bear in mind that if you are letting someone
ELSE have a say in what tables you are using, you’re basically opening
your application schema open to potential HAVOC. I cannot stress how
serious this is. It is YOUR responsibility to ensure that you trust
the schema and migration information, and that it’s not going to drop
your whole database. You need to inspect these things. YOU do. If you
run these voodoo commands and your database essplodes because you
didn’t double double double check what was going on, your embarassment
will be infinite. And your project will be skroo’d if the migration
isn’t irreversible.

That said, if you are working in a team and you all trust each other,
which is hopefully true, this can be quite useful.

Also you might want to bear in mind if you’re using the development
branch, things might break. These changes will make it into the
‘trunk’ (what gets installed via the script/plugin command) once we’re
sure it doesn’t blow up the world or anything.

ANYWAY!

[Please note this is just an example - the login_engine doesn’t have
any migration information, yet.]

How to use

To migrate all engines to the latest version:

rake engines_migrate

To migrate a single engine:

rake engines_migrate ENGINE=login (or login_engine)

To migrate a single engine to a specific revision:

rake engines_migrate ENGINE=login VERSION=4

This:

rake engines_migrate VERSION=1

… will not work, because we felt it was too dangerous to allow ALL
engines to be migrated to a specific version, since such versions
might be incompatible.

Internals

Rather than polluting the schema_info table, Engines will create its
own version table to manage internal Engine versions. You can see the
task and the little tweaks to Migrations (they are tiny) in the
Engines plugin.

Let me know how it works - bug reports etc etc to the Trac site please!

https://opensvn.csie.org/traccgi/rails_engines/trac.cgi

  • james