Oihana PHP Arango

ArangoMigrateAction uses trait:short, trait:short, \oihana\commands\traits\IOTrait

Applies the versioned data migrations of the database — the imperative counterpart of the declarative `doctor` action.

Where doctor reconciles the structure declared in the DI definitions, migrate runs hand-written PHP migrations that transform data already in the database (a backfill, a field reshape, a one-off cleanup) — things that cannot be expressed as configuration. Each migration runs once per database, tracked in the migrations collection (MigrationStore / MigrationAction).

Modes:

  • default : applies the pending migrations, after confirmation (ArangoCommandOption::YES skips the prompt; a non-interactive run without --yes stops, by safety).
  • --status : the applied / pending table.
  • --dry-run : lists the pending migrations without running them.
  • --down[=n] : rolls back the last (n) applied migrations (LIFO).
  • --forget=V : rescue — drops a tracking row without running its down().
  • --create "…": generates an empty migration shell (the engine never fills up() / down()).

The migrations folder, namespace and tracking collection are supplied via the command init keys (ArangoMigrationsTrait).

Tags
author

Marc Alcaraz (ekameleon)

since
1.2.0

Table of Contents

Properties

$migrationsCollection  : string
The tracking collection name (one per database).
$migrationsNamespace  : string
The PHP namespace the version classes are declared in (e.g. `fr\bouney\migrations`).
$migrationsPath  : string|null
The directory holding the `Version*.php` migration files.

Methods

agent()  : string
The acting agent (`user@host`) stamped on the tracking documents — shared by the `migrate` runs and the `doctor --apply` journal.
buildDatabase()  : Database|null
Builds a best-effort {@see Database} HTTP client from the resolved connection settings, or null when no usable endpoint/database is available or the client cannot be constructed.
gitCommit()  : string|null
The current git commit hash, or null outside a git repository — the history link stamped on every tracking document.
migrate()  : int
Applies / inspects / rolls back the data migrations.
resolveDatabase()  : Database|null
Builds the best-effort {@see Database} HTTP client of an action run: every connection setting reads its CLI option first (`--database` / `--endpoint` / `--user` / `--password`) and falls back on the command configuration ({@see ArangoConfigTrait}).
resolveFacade()  : ArangoDB|null
Builds the best-effort high-level {@see ArangoDB} façade of an action run, from the same resolved connection settings as {@see resolveDatabase()} — the migration engine hands this façade to every {@see \oihana\arango\migrations\Migration}. Null when no usable endpoint is configured or the façade cannot be constructed.
buildRunner()  : MigrationRunner|null
Builds the migration runner from the resolved façade and the command configuration, or null (with an error printed) when no database or no migrations path is available.
migrateApply()  : int
Applies the pending migrations, after confirmation.
migrateCreate()  : int
Generates an empty migration shell.
migrateDown()  : int
Rolls back the last `$count` applied migrations.
migrateDryRun()  : int
Lists the pending migrations without running them.
migrateStatus()  : int
Prints the applied / pending status table.

Properties

$migrationsCollection

The tracking collection name (one per database).

public string $migrationsCollection = 'migrations'

$migrationsNamespace

The PHP namespace the version classes are declared in (e.g. `fr\bouney\migrations`).

public string $migrationsNamespace = ''

$migrationsPath

The directory holding the `Version*.php` migration files.

public string|null $migrationsPath = null

Methods

agent()

The acting agent (`user@host`) stamped on the tracking documents — shared by the `migrate` runs and the `doctor --apply` journal.

protected agent() : string
Return values
string

buildDatabase()

Builds a best-effort {@see Database} HTTP client from the resolved connection settings, or null when no usable endpoint/database is available or the client cannot be constructed.

protected buildDatabase(string $endpoint, string $username, string $password, string $database) : Database|null

No network I/O happens here — the connection is only exercised when a request method (e.g. Database::collections()) is later called by the caller.

Parameters
$endpoint : string

The ArangoDB endpoint (e.g. tcp://127.0.0.1:8529).

$username : string

The connection user.

$password : string

The connection password.

$database : string

The target database name.

Return values
Database|null

gitCommit()

The current git commit hash, or null outside a git repository — the history link stamped on every tracking document.

protected gitCommit() : string|null
Return values
string|null

migrate()

Applies / inspects / rolls back the data migrations.

protected migrate(InputInterface $input, OutputInterface $output) : int
Parameters
$input : InputInterface
$output : OutputInterface
Return values
int

resolveDatabase()

Builds the best-effort {@see Database} HTTP client of an action run: every connection setting reads its CLI option first (`--database` / `--endpoint` / `--user` / `--password`) and falls back on the command configuration ({@see ArangoConfigTrait}).

protected resolveDatabase(InputInterface $input) : Database|null

One-stop shop for the actions — see buildDatabase() for the null-on-failure semantics.

Parameters
$input : InputInterface

The action input carrying the optional CLI overrides.

Return values
Database|null

resolveFacade()

Builds the best-effort high-level {@see ArangoDB} façade of an action run, from the same resolved connection settings as {@see resolveDatabase()} — the migration engine hands this façade to every {@see \oihana\arango\migrations\Migration}. Null when no usable endpoint is configured or the façade cannot be constructed.

protected resolveFacade(InputInterface $input) : ArangoDB|null
Parameters
$input : InputInterface

The action input carrying the optional CLI overrides.

Return values
ArangoDB|null

buildRunner()

Builds the migration runner from the resolved façade and the command configuration, or null (with an error printed) when no database or no migrations path is available.

private buildRunner(InputInterface $input, SymfonyStyle $io) : MigrationRunner|null
Parameters
$input : InputInterface
$io : SymfonyStyle
Return values
MigrationRunner|null

migrateApply()

Applies the pending migrations, after confirmation.

private migrateApply(InputInterface $input, OutputInterface $output, SymfonyStyle $io, MigrationRunner $runner, array<string, mixed> $pending) : int
Parameters
$input : InputInterface
$output : OutputInterface
$io : SymfonyStyle
$runner : MigrationRunner
$pending : array<string, mixed>
Tags
throws
ArangoException
Return values
int

migrateCreate()

Generates an empty migration shell.

private migrateCreate(SymfonyStyle $io, string $description) : int
Parameters
$io : SymfonyStyle
$description : string
Return values
int

migrateDryRun()

Lists the pending migrations without running them.

private migrateDryRun(SymfonyStyle $io, array<string, mixed> $pending) : int
Parameters
$io : SymfonyStyle
$pending : array<string, mixed>
Return values
int
On this page

Search results