The database tasks behind the flux db:* console commands: migrating, rolling back, inspecting the migration status and dumping or loading the schema file.

Summary

Functions

Refreshes the models and regenerates the schema file once migrations have run.
context()shared
Returns the migration context of the active schema, creating it if needed.
Runs the next pending migrations (flux db:forward STEP=n).
Records the migrations as run for a database whose newest migration version is stored under the 'version' key of the 'ar_metadata' table, with nothing in the 'ar_schema_migrations' table.
Imports the metadata (indexes, references and primary keys) of a schema file that holds a 'Structure' object.
Runs the pending migrations, or migrates to a version (flux db:migrate VERSION=x).
Reverts a single migration (flux db:migrate:down VERSION=x).
Prints the status of every migration (flux db:migrate:status).
Runs a single migration (flux db:migrate:up VERSION=x).
names()shared
Returns the names of the console tasks.
prepare()shared
Brings the database up to date when the server starts: installs the migrations of the packages and plugins, warns about versions that have been run but have no file anymore, loads the schema file into a fresh database and runs the pending migrations.
Reverts and re-runs migrations (flux db:migrate:redo STEP=n or VERSION=x).
Reverts the newest migrations (flux db:rollback STEP=n).
Runs a task by its console name, e.g. 'migrate:status', with the adapter in sync mode.
Writes the current schema into the schema file (flux db:schema:dump).
Loads the schema file, which creates the tables it describes and records its version and every older migration as run (flux db:schema:load).
Returns the path of the schema file, relative to the game folder.
Checks whether the schema file holds a 'Structure' object (the one-argument form of ActiveRecord.Schema:define).
version()shared
Prints the current schema version (flux db:version).

Functions

Tasks.after_migration(executed)

shared packages/active_record/lib/migrator/tasks.lua:27

Refreshes the models and regenerates the schema file once migrations have run.

Parameters

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

Returns

  • List<ActiveRecord::MigrationProxy> the same list

Returns the migration context of the active schema, creating it if needed.

Returns

  • ActiveRecord::MigrationContext

Runs the next pending migrations (flux db:forward STEP=n).

Parameters

  • steps Number optional, defaults to 1

Returns

  • List<ActiveRecord::MigrationProxy>

Tasks.import_metadata_version()

shared packages/active_record/lib/migrator/tasks.lua:165

Records the migrations as run for a database whose newest migration version is stored under the 'version' key of the 'ar_metadata' table, with nothing in the 'ar_schema_migrations' table. Every migration file up to that version is considered run, the key is deleted, and the indexes and foreign keys of a schema file that holds a 'Structure' object are imported into the metadata.

Tasks.import_structure_metadata(metadata)

shared packages/active_record/lib/migrator/tasks.lua:189

Imports the metadata (indexes, references and primary keys) of a schema file that holds a 'Structure' object.

Parameters

  • metadata Map

Tasks.migrate(version)

shared packages/active_record/lib/migrator/tasks.lua:40

Runs the pending migrations, or migrates to a version (flux db:migrate VERSION=x).

Parameters

  • version Number/String optional, defaults to nil

Returns

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

Tasks.migrate_down(version)

shared packages/active_record/lib/migrator/tasks.lua:64

Reverts a single migration (flux db:migrate:down VERSION=x).

Parameters

  • version Number/String

Returns

  • List<ActiveRecord::MigrationProxy>

Prints the status of every migration (flux db:migrate:status).

Tasks.migrate_up(version)

shared packages/active_record/lib/migrator/tasks.lua:53

Runs a single migration (flux db:migrate:up VERSION=x).

Parameters

  • version Number/String

Returns

  • List<ActiveRecord::MigrationProxy>

Returns the names of the console tasks.

Returns

  • List<String> sorted

Brings the database up to date when the server starts: installs the migrations of the packages and plugins, warns about versions that have been run but have no file anymore, loads the schema file into a fresh database and runs the pending migrations.

Returns

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

Tasks.redo(steps, version)

shared packages/active_record/lib/migrator/tasks.lua:90

Reverts and re-runs migrations (flux db:migrate:redo STEP=n or VERSION=x).

Parameters

  • steps Number optional, defaults to 1
  • version Number/String optional, defaults to nil a single migration to redo

Returns

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

Reverts the newest migrations (flux db:rollback STEP=n).

Parameters

  • steps Number optional, defaults to 1

Returns

  • List<ActiveRecord::MigrationProxy>

Runs a task by its console name, e.g. 'migrate:status', with the adapter in sync mode. Errors are printed instead of raised.

Parameters

  • name String
  • env Map optional, defaults to nil KEY=VALUE arguments of the command, e.g. { VERSION = '2019...' }

Returns

  • Boolean whether the task ran without an error

Writes the current schema into the schema file (flux db:schema:dump).

Returns

  • String path of the file

Loads the schema file, which creates the tables it describes and records its version and every older migration as run (flux db:schema:load).

Returns the path of the schema file, relative to the game folder.

Returns

  • String e.g. 'gamemodes/reborn/db/schema.lua'

Tasks.structure_schema_file()

shared packages/active_record/lib/migrator/tasks.lua:133

Checks whether the schema file holds a 'Structure' object (the one-argument form of ActiveRecord.Schema:define). Such a file cannot be loaded.

Returns

  • Boolean

Prints the current schema version (flux db:version).

Defined in