Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

migration attributes #12074

Merged
merged 1 commit into from
Oct 31, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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