Skip to content

Commit

Permalink
migration attributes
Browse files Browse the repository at this point in the history
Signed-off-by: Maxence Lange <[email protected]>
  • Loading branch information
ArtificialOwl committed Oct 29, 2024
1 parent 791c2bb commit e1056a2
Showing 1 changed file with 38 additions and 6 deletions.
44 changes: 38 additions & 6 deletions developer_manual/basics/storage/migrations.rst
Original file line number Diff line number Diff line change
Expand Up @@ -100,12 +100,9 @@ instance into your migration class like this:
.. code-block:: php
class Version2404Date20220903071748 extends SimpleMigrationStep {
/** @var IDBConnection */
private $db;
public function __construct(IDBConnection $db) {
$this->db = $db;
public function __construct(
private IDBConnection $db
) {
}
public function postSchemaChange(IOutput $output, \Closure $schemaClosure, array $options) {
Expand All @@ -114,6 +111,41 @@ instance into your migration class like this:
}
}
Migrations and Metadata
-----------------------

Since 30, details about migrations are available to administrator as metadata can be attached to your migration class by adding specific PHP Attributes:

.. code-block:: php
:emphasize-lines: 5-10
use OCP\Migration\Attributes\CreateTable;
use OCP\Migration\Attributes\ColumnType;
use OCP\Migration\Attributes\ModifyColumn;
#[CreateTable(
table: 'new_table',
description: 'Table is used to store things, but also to get more things',
notes: ['this is a notice', 'and another one, if really needed']
)]
#[ModifyColumn(table: 'other_table', name: 'this_field', type: ColumnType::BIGINT)]
class Version30000Date20240729185117 extends SimpleMigrationStep {
public function changeSchema(IOutput $output, Closure $schemaClosure, array $options) {
[...]
}
}
List of available Migration Attributes:

* ``\OCP\Migration\Attributes\AddColumn`` if your migration implies the creation of a new column
* ``\OCP\Migration\Attributes\AddIndex`` if your migration adds a new index
* ``\OCP\Migration\Attributes\CreateTable`` if your migration creates a new table
* ``\OCP\Migration\Attributes\DropColumn`` if your migration drops a column
* ``\OCP\Migration\Attributes\DropIndex`` if your migration drops an index
* ``\OCP\Migration\Attributes\DropTable`` if your migration drops a table
* ``\OCP\Migration\Attributes\ModifyColumn`` if your migration modifies a column

.. _migration_console_command:

Console commands
Expand Down

0 comments on commit e1056a2

Please sign in to comment.