class Sequel::Migrator

The Migrator class performs migrations based on migration files in a specified directory. The migration files should be named using the following pattern:

<version>_<title>.rb

For example, the following files are considered migration files:

001_create_sessions.rb
002_add_data_column.rb

You can also use timestamps as version numbers:

1273253850_create_sessions.rb
1273257248_add_data_column.rb

If any migration filenames use timestamps as version numbers, Sequel uses the TimestampMigrator to migrate, otherwise it uses the IntegerMigrator. The TimestampMigrator can handle migrations that are run out of order as well as migrations with the same timestamp, while the IntegerMigrator is more strict and raises exceptions for missing or duplicate migration files.

The migration files should contain either one Migration subclass or one Sequel.migration call.

Migrations are generally run via the sequel command line tool, using the -m and -M switches. The -m switch specifies the migration directory, and the -M switch specifies the version to which to migrate.

You can apply migrations using the Migrator API, as well (this is necessary if you want to specify the version from which to migrate in addition to the version to which to migrate). To apply a migrator, the apply method must be invoked with the database instance, the directory of migration files and the target version. If no current version is supplied, it is read from the database. The migrator automatically creates a table (schema_info for integer migrations and schema_migrations for timestamped migrations). in the database to keep track of the current migration version. If no migration version is stored in the database, the version is considered to be 0. If no target version is specified, or the target version specified is greater than the latest version available, the database is migrated to the latest version available in the migration directory.

For example, to migrate the database to the latest version:

Sequel::Migrator.run(DB, '.')

For example, to migrate the database all the way down:

Sequel::Migrator.run(DB, '.', target: 0)

For example, to migrate the database to version 4:

Sequel::Migrator.run(DB, '.', target: 4)

To migrate the database from version 1 to version 5:

Sequel::Migrator.run(DB, '.', target: 5, current: 1)

Part of the migration extension.