Finds the migration files and decides which of them to run. A context looks for files named <version>_<name>.lua in its migration folders (the db/migrate/ folder of the active schema by default), wraps each one in an ActiveRecord::MigrationProxy and offers the operations behind the flux db:* tasks: migrate, up, down, run, rollback, forward and migrations_status. The migrations themselves are run by an ActiveRecord::Migrator that the context creates.

It also installs the migrations that packages and plugins ship in their migrations folder: those files are registered through the 'migrations' pipeline, and install_migrations copies them into the schema's folder when the server starts. An installed copy keeps the version of its source, and the version is recorded in the ar_metadata table, so deleting the copy and starting the server again recreates it under the version the database has already run.

Summary

Functions

Registers a migration file of a package or plugin.
Returns the folder the migrations of the active schema live in, relative to the Lua search path.
Splits a migration file name into its parts.
Returns the scope a registered migration file is installed under: the name of the package, plugin or schema folder it comes from.
sources()shared
Returns the registered package and plugin migration files, in the order they were registered in.

Methods

Records the given version and every older migration as run, without running anything.
Returns the newest version that has been run.
Reverts the migrations that have been run, newest first, down to (but not including) the target version.
Runs the next pending migrations.
Returns the versions of the migrations that have been run.
Creates a context, which provides the migrations of one or more folders.
Installs the migration files registered with .add_source into the schema's migrations folder (the first of the migration paths): each one is copied under the scope it came from, e.g. '20190309120000_create_admin_tables.admin.lua'.
Returns the migration with the newest version.
Runs the migrations that have not been run yet.
Returns the paths of every migration file in the migration folders.
Returns the migrations found in the migration folders, sorted by version.
Returns the status of every migration: the ones found in the migration folders and the versions that have been run but have no file anymore.
Moves a number of migrations up or down from the current version.
Checks whether there are migrations that have not been run yet.
Returns the version a new migration in the schema's migrations folder gets.
Creates a migrator for the migrations of the context without running anything.
Returns the versions of the migrations that have not been run yet.
Reverts the newest migrations.
Runs or reverts a single migration.
Runs the pending migrations up to and including the target version.
Returns the versions that have been run but have no migration file anymore.

Functions

ActiveRecord.MigrationContext.add_source(path)

shared packages/active_record/lib/migrator/migration_context.lua:106

Registers a migration file of a package or plugin. Registered files are installed into the schema's migrations folder by #install_migrations.

Parameters

  • path String path of the file, relative to the Lua search path

ActiveRecord.MigrationContext.default_migrations_path()

shared packages/active_record/lib/migrator/migration_context.lua:99

Returns the folder the migrations of the active schema live in, relative to the Lua search path.

Returns

  • String e.g. 'reborn/db/migrate/'

ActiveRecord.MigrationContext.parse_migration_filename(file_name)

shared packages/active_record/lib/migrator/migration_context.lua:125

Splits a migration file name into its parts.

Parameters

  • file_name String file name or path, e.g. '20190309120000_create_users.admin.lua'

Returns

  • Number version
  • String name
  • String scope; nil if the name does not match

ActiveRecord.MigrationContext.scope_of(path)

shared packages/active_record/lib/migrator/migration_context.lua:137

Returns the scope a registered migration file is installed under: the name of the package, plugin or schema folder it comes from.

Parameters

  • path String path of the file

Returns

  • String

ActiveRecord.MigrationContext.sources()

shared packages/active_record/lib/migrator/migration_context.lua:118

Returns the registered package and plugin migration files, in the order they were registered in.

Returns

  • List<String>

Methods

ActiveRecord.MigrationContext:assume_migrated_upto_version(version)

shared packages/active_record/lib/migrator/migration_context.lua:438

Records the given version and every older migration as run, without running anything. Used after the schema file has been loaded, which brings the database to the state the migrations up to that version describe.

Parameters

  • version Number/String

ActiveRecord.MigrationContext:current_version()

shared packages/active_record/lib/migrator/migration_context.lua:242

Returns the newest version that has been run.

Returns

  • Number 0 if no migration has been run

ActiveRecord.MigrationContext:down(target_version)

shared packages/active_record/lib/migrator/migration_context.lua:314

Reverts the migrations that have been run, newest first, down to (but not including) the target version.

Parameters

  • target_version Number optional, defaults to nil every migration if none is given

Returns

  • List<ActiveRecord::MigrationProxy> migrations that were reverted

ActiveRecord.MigrationContext:forward(steps)

shared packages/active_record/lib/migrator/migration_context.lua:368

Runs the next pending migrations.

Parameters

  • steps Number optional, defaults to 1 amount of migrations to run

Returns

  • List<ActiveRecord::MigrationProxy> migrations that were run

ActiveRecord.MigrationContext:get_all_versions()

shared packages/active_record/lib/migrator/migration_context.lua:236

Returns the versions of the migrations that have been run.

Returns

  • List<Number> sorted, oldest first

ActiveRecord.MigrationContext:init(migrations_paths)

shared packages/active_record/lib/migrator/migration_context.lua:154

Creates a context, which provides the migrations of one or more folders.

Parameters

  • migrations_paths List<String> optional, defaults to nil folders to look for migrations in, relative to the Lua search path; the schema's 'db/migrate/' folder by default

Returns

  • ActiveRecord::MigrationContext(self)

ActiveRecord.MigrationContext:install_migrations()

shared packages/active_record/lib/migrator/migration_context.lua:515

Installs the migration files registered with .add_source into the schema's migrations folder (the first of the migration paths): each one is copied under the scope it came from, e.g. '20190309120000_create_admin_tables.admin.lua'. A migration whose name is already present, under any version or scope, is skipped.

The version of a copy is the one recorded in the 'ar_metadata' table for its name, so a deleted copy comes back under the version the database has run; otherwise it is the version of the source file, or a new version for a source file without one. A version already taken by another file is increased until it is free. Files whose name has no version (e.g. 'CreateFoo.lua') hold bare schema statements, which are wrapped into a migration's #change.

Returns

  • List<String> paths of the installed files

ActiveRecord.MigrationContext:last_migration()

shared packages/active_record/lib/migrator/migration_context.lua:229

Returns the migration with the newest version.

Returns

  • ActiveRecord::MigrationProxy or nil if there are no migrations

ActiveRecord.MigrationContext:migrate(target_version)

shared packages/active_record/lib/migrator/migration_context.lua:285

Runs the migrations that have not been run yet. Given a target version, migrates up or down to it instead.

Parameters

  • target_version Number/String optional, defaults to nil

Returns

  • List<ActiveRecord::MigrationProxy> migrations that were run

ActiveRecord.MigrationContext:migration_files()

shared packages/active_record/lib/migrator/migration_context.lua:170

Returns the paths of every migration file in the migration folders.

Returns

  • List<String>

ActiveRecord.MigrationContext:migrations()

shared packages/active_record/lib/migrator/migration_context.lua:188

Returns the migrations found in the migration folders, sorted by version. Files whose name is not '<version>_<name>.lua' are ignored. Two migrations with the same version or the same name are an error.

Returns

  • List<ActiveRecord::MigrationProxy>

ActiveRecord.MigrationContext:migrations_status()

shared packages/active_record/lib/migrator/migration_context.lua:396

Returns the status of every migration: the ones found in the migration folders and the versions that have been run but have no file anymore.

Returns

  • List<Map> entries with status ('up' or 'down'), version (String) and name, sorted by version

ActiveRecord.MigrationContext:move(direction, steps)

shared packages/active_record/lib/migrator/migration_context.lua:330

Moves a number of migrations up or down from the current version.

Parameters

  • direction String 'up' or 'down'
  • steps Number optional, defaults to 1

Returns

  • List<ActiveRecord::MigrationProxy> migrations that were run

ActiveRecord.MigrationContext:needs_migration()

shared packages/active_record/lib/migrator/migration_context.lua:269

Checks whether there are migrations that have not been run yet.

Returns

  • Boolean

ActiveRecord.MigrationContext:next_migration_number()

shared packages/active_record/lib/migrator/migration_context.lua:462

Returns the version a new migration in the schema's migrations folder gets.

Returns

  • String 14-digit version

ActiveRecord.MigrationContext:open(direction, target_version)

shared packages/active_record/lib/migrator/migration_context.lua:277

Creates a migrator for the migrations of the context without running anything.

Parameters

  • direction String optional, defaults to 'up'
  • target_version Number optional, defaults to nil

Returns

  • ActiveRecord::Migrator

ActiveRecord.MigrationContext:pending_migration_versions()

shared packages/active_record/lib/migrator/migration_context.lua:249

Returns the versions of the migrations that have not been run yet.

Returns

  • List<Number>

ActiveRecord.MigrationContext:rollback(steps)

shared packages/active_record/lib/migrator/migration_context.lua:361

Reverts the newest migrations.

Parameters

  • steps Number optional, defaults to 1 amount of migrations to revert

Returns

  • List<ActiveRecord::MigrationProxy> migrations that were reverted

ActiveRecord.MigrationContext:run(direction, target_version)

shared packages/active_record/lib/migrator/migration_context.lua:322

Runs or reverts a single migration.

Parameters

  • direction String 'up' or 'down'
  • target_version Number/String version of the migration

Returns

  • List<ActiveRecord::MigrationProxy> the migration, if it was run

ActiveRecord.MigrationContext:up(target_version)

shared packages/active_record/lib/migrator/migration_context.lua:306

Runs the pending migrations up to and including the target version.

Parameters

  • target_version Number optional, defaults to nil all pending migrations if none is given

Returns

  • List<ActiveRecord::MigrationProxy> migrations that were run

ActiveRecord.MigrationContext:versions_without_file()

shared packages/active_record/lib/migrator/migration_context.lua:374

Returns the versions that have been run but have no migration file anymore.

Returns

  • List<Number> sorted, oldest first

Defined in