From 38269350eb63eccafcde30ff0fc4ba54aae6538b Mon Sep 17 00:00:00 2001 From: Alexander Makarov Date: Fri, 26 Dec 2025 01:40:17 +0300 Subject: [PATCH 1/8] Update migrations guide --- src/guide/databases/db-migrations.md | 554 +++++++++++++++++++++++++-- 1 file changed, 528 insertions(+), 26 deletions(-) diff --git a/src/guide/databases/db-migrations.md b/src/guide/databases/db-migrations.md index 115bfb3c..5be2b40f 100644 --- a/src/guide/databases/db-migrations.md +++ b/src/guide/databases/db-migrations.md @@ -1,58 +1,294 @@ # Migrations +During the course of developing and maintaining a database-driven application, the structure of the database +being used evolves just like the source code does. For example, during the development of an application, +a new table may be found necessary; after the application is deployed to production, it may be discovered +that an index should be created to improve the query performance; and so on. Because a database structure change +often requires some source code changes, Yii supports the so-called *database migration* feature that allows +you to keep track of database changes in terms of *database migrations* which are version-controlled together +with the source code. + +The following steps show how database migration can be used by a team during development: + +1. Tim creates a new migration (e.g. creates a new table, changes a column definition, etc.). +2. Tim commits the new migration into the source control system (e.g. Git, Mercurial). +3. Doug updates his repository from the source control system and receives the new migration. +4. Doug applies the migration to his local development database, thereby synchronizing his database + to reflect the changes that Tim has made. + +And the following steps show how to deploy a new release with database migrations to production: + +1. Scott creates a release tag for the project repository that contains some new database migrations. +2. Scott updates the source code on the production server to the release tag. +3. Scott applies any accumulated database migrations to the production database. + +Yii provides a set of migration command line tools that allow you to: + +* create new migrations; +* apply migrations; +* revert migrations; +* re-apply migrations; +* show migration history and status. + +All these tools are accessible through the command `yii migrate`. In this section we will describe in detail +how to accomplish various tasks using these tools. + +> [!TIP] +> Migrations could affect not only database schema but adjust existing data to fit new schema, create RBAC +hierarchy or clean up cache. + +> [!NOTE] +> When manipulating data using a migration you may find that using your Active Record or entity classes +> for this might be useful because some of the logic is already implemented there. Keep in mind however, that in contrast +> to code written in the migrations, whose nature is to stay constant forever, application logic is subject to change. +> So when using Active Record or entity classes in migration code, changes to the logic in the source code +> may accidentally break the existing migrations. For this reason migration code should be kept independent of other +> application logic such. + +## Initial configuration + To use migrations, install [yiisoft/db-migration](https://github.com/yiisoft/db-migration/) package: ```shell -composer require yiisoft/db-migration +make composer require yiisoft/db-migration ``` -### Example usage +Create a directory to store migrations `src/Migration` right in the project root. -First, configure a DI container. Create `config/common/db.php` with the following content: +Add the following configuration to `config/common/params.php`: + +```php +'yiisoft/db-migration' => [ + 'newMigrationNamespace' => 'App\\Migration', + 'sourceNamespaces' => ['App\\Migration'], +], +``` + +You need a database connection configured as well. See [Working with databases](../start/databases.md) for an example +of configuring it for PostgreSQL. + +### Creating a migration + +To create a new empty migration, run the following command: + +```sh +make yii migrate:create +``` + +The required `name` argument gives a brief description about the new migration. For example, if +the migration is about creating a new table named *news*, you may use the name `create_news_table` +and run the following command: + +``` +make yii migrate:create create_news_table +``` + + +> [!NOTE] +> Because the `name` argument will be used as part of the generated migration class name, +> it should only contain letters, digits, and/or underscore characters. + +The above command will create a new PHP class file named `src/Migration/M251225221906CreateNewsTable.php`. +The file contains the following code which mainly declares a migration class with the skeleton code: ```php [ - 'class' => SqliteConnection::class, - '__construct()' => [ - 'dsn' => 'sqlite:' . __DIR__ . '/Data/yiitest.sq3' - ] - ] -]; +use Yiisoft\Db\Migration\MigrationBuilder; +use Yiisoft\Db\Migration\RevertibleMigrationInterface; + +final class M251225221906CreateNewsTable implements RevertibleMigrationInterface +{ + public function up(MigrationBuilder $b): void + { + // TODO: Implement the logic to apply the migration. + } + + public function down(MigrationBuilder $b): void + { + // TODO: Implement the logic to revert the migration. + } +} ``` -Add the following to `config/params.php`: +In the migration class, you are expected to write code in the `up()` method that makes changes to the database structure. +You may also want to write code in the `down()` method to revert the changes made by `up()`. The `up()` method is invoked +when you upgrade the database with this migration, while the `down()` method is invoked when you downgrade the database. +The following code shows how you may implement the migration class to create a `news` table: ```php -... -'yiisoft/db-migration' => [ - 'newMigrationNamespace' => 'App\\Migration', - 'sourceNamespaces' => ['App\\Migration'], -], -... +columnBuilder(); + + $b->createTable('news', [ + 'id' => $cb::uuidPrimaryKey(), + 'title' => $cb::string()->notNull(), + 'content' => $cb::text(), + ]); + } + + public function down(MigrationBuilder $b): void + { + $b->dropTable('news'); + } +} ``` -Now test if it works: +TODO: explain $b and $qb +Below is the list of all these database accessing methods: -```shell -./yii list migrate +### Irreversible migrations + +Not all migrations are reversible. For example, if the `up()` method deletes a row of a table, you may +not be able to recover this row in the `down()` method. Sometimes, you may be just too lazy to implement +the `down()`, because it is not very common to revert database migrations. In this case, you should implement +`Yiisoft\Db\Migration\MigrationInterface` that has `up()` only. + + +### Transactional migrations (TODO: update!!!) + +While performing complex DB migrations, it is important to ensure each migration to either succeed or fail as a whole +so that the database can maintain integrity and consistency. To achieve this goal, it is recommended that you +enclose the DB operations of each migration in a [transaction](db-dao.md#performing-transactions). + +An even easier way of implementing transactional migrations is to put migration code in the `safeUp()` and `safeDown()` +methods. These two methods differ from `up()` and `down()` in that they are enclosed implicitly in a transaction. +As a result, if any operation in these methods fails, all prior operations will be rolled back automatically. + +In the following example, besides creating the `news` table we also insert an initial row into this table. + +```php +createTable('news', [ + 'id' => $this->primaryKey(), + 'title' => $this->string()->notNull(), + 'content' => $this->text(), + ]); + + $this->insert('news', [ + 'title' => 'test 1', + 'content' => 'content 1', + ]); + } + + public function safeDown() + { + $this->delete('news', ['id' => 1]); + $this->dropTable('news'); + } +} ``` -### Creating a migration +Note that usually when you perform multiple DB operations in `safeUp()`, you should reverse their execution order +in `safeDown()`. In the above example we first create the table and then insert a row in `safeUp()`; while +in `safeDown()` we first delete the row and then drop the table. + +> Note: Not all DBMS support transactions. And some DB queries cannot be put into a transaction. For some examples, +please refer to [implicit commit](https://dev.mysql.com/doc/refman/5.7/en/implicit-commit.html). If this is the case, +you should still implement `up()` and `down()`, instead. + +TODO: TransactionalMigrationInterface + + + +## TODO: update + +The base migration class [[yii\db\Migration]] exposes a database connection via the [[yii\db\Migration::db|db]] +property. You can use it to manipulate the database schema using the methods as described in +[Working with Database Schema](db-dao.md#database-schema). + +Rather than using physical types, when creating a table or column you should use *abstract types* +so that your migrations are independent of specific DBMS. The [[yii\db\Schema]] class defines +a set of constants to represent the supported abstract types. These constants are named in the format +of `TYPE_`. For example, `TYPE_PK` refers to auto-incremental primary key type; `TYPE_STRING` +refers to a string type. When a migration is applied to a particular database, the abstract types +will be translated into the corresponding physical types. In the case of MySQL, `TYPE_PK` will be turned +into `int(11) NOT NULL AUTO_INCREMENT PRIMARY KEY`, while `TYPE_STRING` becomes `varchar(255)`. + +You can append additional constraints when using abstract types. In the above example, ` NOT NULL` is appended +to `Schema::TYPE_STRING` to specify that the column cannot be `null`. -To work with migrations, you can use the provided [view](https://github.com/yiisoft/db-migration/tree/master/resources/views). +> Info: The mapping between abstract types and physical types is specified by +the [[yii\db\QueryBuilder::$typeMap|$typeMap]] property in each concrete `QueryBuilder` class. + +Since version 2.0.6, you can make use of the newly introduced schema builder which provides more convenient way of defining column schema. +So the migration above could be written like the following: + +```php +createTable('news', [ + 'id' => $this->primaryKey(), + 'title' => $this->string()->notNull(), + 'content' => $this->text(), + ]); + } + + public function down() + { + $this->dropTable('news'); + } +} +``` + +A list of all available methods for defining the column types is available in the API documentation of [[yii\db\SchemaBuilderTrait]]. + +> Info: The generated file permissions and ownership will be determined by the current environment. This might lead to +inaccessible files. This could, for example, happen when the migration is created within a docker container +and the files are edited on the host. In this case the `newFileMode` and/or `newFileOwnership` of the MigrateController +can be changed. E.g. in the application config: + ```php + [ + 'migrate' => [ + 'class' => 'yii\console\controllers\MigrateController', + 'newFileOwnership' => '1000:1000', # Default WSL user id + 'newFileMode' => 0660, + ], + ], + ]; + ``` + +## Generating Migrations (TODO: likely is OK but...) + +The command provides a convenient way to create migrations using the provided [view](https://github.com/yiisoft/db-migration/tree/master/resources/views): ```shell -./yii migrate:create my_first_table --command=table --fields=name,example --table-comment=my_first_table +make yii migrate:create my_first_table --command=table --fields=name,example --table-comment=my_first_table ``` + + That would generate the following: ```php @@ -91,6 +327,272 @@ final class M240115143455CreateMyFirstTableTable implements RevertibleMigrationI For more information [see](https://github.com/yiisoft/db-migration/tree/master/docs/guide/en) + +## Applying Migrations + +To upgrade a database to its latest structure, you should apply all available new migrations using the following command: + +``` +yii migrate +``` + +This command will list all migrations that have not been applied so far. If you confirm that you want to apply +these migrations, it will run the `up()` or `safeUp()` method in every new migration class, one after another, +in the order of their timestamp values. If any of the migrations fails, the command will quit without applying +the rest of the migrations. + +> Tip: In case you don't have command line at your server you may try [web shell](https://github.com/samdark/yii2-webshell) +> extension. + +For each migration that has been successfully applied, the command will insert a row into a database table named +`migration` to record the successful application of the migration. This will allow the migration tool to identify +which migrations have been applied and which have not. + +> Info: The migration tool will automatically create the `migration` table in the database specified by +the [[yii\console\controllers\MigrateController::db|db]] option of the command. By default, the database +is specified by the `db` [application component](structure-application-components.md). + +Sometimes, you may only want to apply one or a few new migrations, instead of all available migrations. +You can do so by specifying the number of migrations that you want to apply when running the command. +For example, the following command will try to apply the next three available migrations: + +``` +yii migrate 3 +``` + +You can also explicitly specify a particular migration to which the database should be migrated +by using the `migrate/to` command in one of the following formats: + +``` +yii migrate/to 150101_185401 # using timestamp to specify the migration +yii migrate/to "2015-01-01 18:54:01" # using a string that can be parsed by strtotime() +yii migrate/to m150101_185401_create_news_table # using full name +yii migrate/to 1392853618 # using UNIX timestamp +``` + +If there are any unapplied migrations earlier than the specified one, they will all be applied before the specified +migration is applied. + +If the specified migration has already been applied before, any later applied migrations will be reverted. + + +## Reverting Migrations + +To revert (undo) one or multiple migrations that have been applied before, you can run the following command: + +``` +yii migrate/down # revert the most recently applied migration +yii migrate/down 3 # revert the most 3 recently applied migrations +``` + +> Note: Not all migrations are reversible. Trying to revert such migrations will cause an error and stop the +entire reverting process. + + +## Redoing Migrations + +Redoing migrations means first reverting the specified migrations and then applying again. This can be done +as follows: + +``` +yii migrate/redo # redo the last applied migration +yii migrate/redo 3 # redo the last 3 applied migrations +``` + +> Note: If a migration is not reversible, you will not be able to redo it. + +## Refreshing Migrations + +Since Yii 2.0.13 you can delete all tables and foreign keys from the database and apply all migrations from the beginning. + +``` +yii migrate/fresh # truncate the database and apply all migrations from the beginning +``` + +## Listing Migrations + +To list which migrations have been applied and which are not, you may use the following commands: + +``` +yii migrate/history # showing the last 10 applied migrations +yii migrate/history 5 # showing the last 5 applied migrations +yii migrate/history all # showing all applied migrations + +yii migrate/new # showing the first 10 new migrations +yii migrate/new 5 # showing the first 5 new migrations +yii migrate/new all # showing all new migrations +``` + + +## Modifying Migration History + +Instead of actually applying or reverting migrations, sometimes you may simply want to mark that your database +has been upgraded to a particular migration. This often happens when you manually change the database to a particular +state and you do not want the migration(s) for that change to be re-applied later. You can achieve this goal with +the following command: + +``` +yii migrate/mark 150101_185401 # using timestamp to specify the migration +yii migrate/mark "2015-01-01 18:54:01" # using a string that can be parsed by strtotime() +yii migrate/mark m150101_185401_create_news_table # using full name +yii migrate/mark 1392853618 # using UNIX timestamp +``` + +The command will modify the `migration` table by adding or deleting certain rows to indicate that the database +has been applied migrations to the specified one. No migrations will be applied or reverted by this command. + + +## Customizing Migrations + +There are several ways to customize the migration command. + + +### Using Command Line Options + +The migration command comes with a few command-line options that can be used to customize its behaviors: + +* `interactive`: boolean (defaults to `true`), specifies whether to perform migrations in an interactive mode. + When this is `true`, the user will be prompted before the command performs certain actions. + You may want to set this to `false` if the command is being used in a background process. + +* `migrationPath`: string|array (defaults to `@app/migrations`), specifies the directory storing all migration + class files. This can be specified as either a directory path or a path [alias](concept-aliases.md). + Note that the directory must exist, or the command may trigger an error. Since version 2.0.12 an array can be + specified for loading migrations from multiple sources. + +* `migrationTable`: string (defaults to `migration`), specifies the name of the database table for storing + migration history information. The table will be automatically created by the command if it does not exist. + You may also manually create it using the structure `version varchar(255) primary key, apply_time integer`. + +* `db`: string (defaults to `db`), specifies the ID of the database [application component](structure-application-components.md). + It represents the database that will be migrated using this command. + +* `templateFile`: string (defaults to `@yii/views/migration.php`), specifies the path of the template file + that is used for generating skeleton migration class files. This can be specified as either a file path + or a path [alias](concept-aliases.md). The template file is a PHP script in which you can use a predefined variable + named `$className` to get the migration class name. + +* `generatorTemplateFiles`: array (defaults to `[ + 'create_table' => '@yii/views/createTableMigration.php', + 'drop_table' => '@yii/views/dropTableMigration.php', + 'add_column' => '@yii/views/addColumnMigration.php', + 'drop_column' => '@yii/views/dropColumnMigration.php', + 'create_junction' => '@yii/views/createTableMigration.php' + ]`), specifies template files for generating migration code. See "[Generating Migrations](#generating-migrations)" + for more details. + +* `fields`: array of column definition strings used for creating migration code. Defaults to `[]`. The format of each + definition is `COLUMN_NAME:COLUMN_TYPE:COLUMN_DECORATOR`. For example, `--fields=name:string(12):notNull` produces + a string column of size 12 which is not `null`. + +The following example shows how you can use these options. + +For example, if we want to migrate a `forum` module whose migration files +are located within the module's `migrations` directory, we can use the following +command: + +``` +# migrate the migrations in a forum module non-interactively +yii migrate --migrationPath=@app/modules/forum/migrations --interactive=0 +``` + +### Separated Migrations + + +Sometimes using single migration history for all project migrations is not desirable. For example: you may install some +'blog' extension, which contains fully separated functionality and contain its own migrations, which should not affect +the ones dedicated to main project functionality. + +If you want several migrations to be applied and tracked down completely separated from each other, you can configure multiple +migration commands which will use different namespaces and migration history tables: + +```php +return [ + 'controllerMap' => [ + // Common migrations for the whole application + 'migrate-app' => [ + 'class' => 'yii\console\controllers\MigrateController', + 'migrationNamespaces' => ['app\migrations'], + 'migrationTable' => 'migration_app', + 'migrationPath' => null, + ], + // Migrations for the specific project's module + 'migrate-module' => [ + 'class' => 'yii\console\controllers\MigrateController', + 'migrationNamespaces' => ['module\migrations'], + 'migrationTable' => 'migration_module', + 'migrationPath' => null, + ], + // Migrations for the specific extension + 'migrate-rbac' => [ + 'class' => 'yii\console\controllers\MigrateController', + 'migrationPath' => '@yii/rbac/migrations', + 'migrationTable' => 'migration_rbac', + ], + ], +]; +``` + +Note that to synchronize database you now need to run multiple commands instead of one: + +``` +yii migrate-app +yii migrate-module +yii migrate-rbac +``` + +## Migrating Multiple Databases + +By default, migrations are applied to the same database specified by the `db` [application component](structure-application-components.md). +If you want them to be applied to a different database, you may specify the `db` command-line option like shown below, + +``` +yii migrate --db=db2 +``` + +The above command will apply migrations to the `db2` database. + +Sometimes it may happen that you want to apply *some* of the migrations to one database, while some others to another +database. To achieve this goal, when implementing a migration class you should explicitly specify the DB component +ID that the migration would use, like the following: + +```php +db = 'db2'; + parent::init(); + } +} +``` + +The above migration will be applied to `db2`, even if you specify a different database through the `db` command-line +option. Note that the migration history will still be recorded in the database specified by the `db` command-line option. + +If you have multiple migrations that use the same database, it is recommended that you create a base migration class +with the above `init()` code. Then each migration class can extend from this base class. + +> Tip: Besides setting the [[yii\db\Migration::db|db]] property, you can also operate on different databases +by creating new database connections to them in your migration classes. You then use the [DAO methods](db-dao.md) +with these connections to manipulate different databases. + +Another strategy that you can take to migrate multiple databases is to keep migrations for different databases in +different migration paths. Then you can migrate these databases in separate commands like the following: + +``` +yii migrate --migrationPath=@app/migrations/db1 --db=db1 +yii migrate --migrationPath=@app/migrations/db2 --db=db2 +... +``` + +The first command will apply migrations in `@app/migrations/db1` to the `db1` database, the second command +will apply migrations in `@app/migrations/db2` to `db2`, and so on. + ### Upgrading from Yii2 Migrations in Yii2 and the [yiisoft/db-migration](https://github.com/yiisoft/db-migration/) package are not compatible, From c19c2701d451a3f112436f6dedf3aed1be65267e Mon Sep 17 00:00:00 2001 From: samdark <47294+samdark@users.noreply.github.com> Date: Thu, 25 Dec 2025 22:41:43 +0000 Subject: [PATCH 2/8] Update translation --- .../po/es/guide_databases_db-migrations.md.po | 902 +++++++++++++- .../po/es/guide_start_creating-project.md.po | 14 +- .../po/es/guide_start_databases.md.po | 50 +- _translations/po/es/guide_start_hello.md.po | 16 +- .../po/es/guide_views_template-engines.md.po | 8 +- _translations/po/es/guide_views_view.md.po | 62 +- .../po/id/guide_databases_db-migrations.md.po | 903 +++++++++++++- .../po/id/guide_start_creating-project.md.po | 10 +- .../po/id/guide_start_databases.md.po | 51 +- _translations/po/id/guide_start_hello.md.po | 16 +- .../po/id/guide_views_template-engines.md.po | 8 +- _translations/po/id/guide_views_view.md.po | 62 +- .../po/ru/guide_databases_db-migrations.md.po | 916 +++++++++++++- .../po/ru/guide_start_creating-project.md.po | 14 +- .../po/ru/guide_start_databases.md.po | 50 +- _translations/po/ru/guide_start_hello.md.po | 16 +- .../po/ru/guide_views_template-engines.md.po | 8 +- _translations/po/ru/guide_views_view.md.po | 62 +- .../pot/guide_databases_db-migrations.md.pot | 1079 ++++++++++++++++- .../pot/guide_start_creating-project.md.pot | 10 +- .../pot/guide_start_databases.md.pot | 52 +- _translations/pot/guide_start_hello.md.pot | 16 +- .../pot/guide_views_template-engines.md.pot | 8 +- _translations/pot/guide_views_view.md.pot | 62 +- src/es/guide/databases/db-migrations.md | 623 +++++++++- src/es/guide/start/creating-project.md | 7 +- src/es/guide/start/databases.md | 16 +- src/es/guide/start/hello.md | 12 +- src/es/guide/views/template-engines.md | 6 +- src/id/guide/databases/db-migrations.md | 623 +++++++++- src/id/guide/start/creating-project.md | 7 +- src/id/guide/start/databases.md | 16 +- src/id/guide/start/hello.md | 12 +- src/id/guide/views/template-engines.md | 6 +- src/ru/guide/databases/db-migrations.md | 623 +++++++++- src/ru/guide/start/creating-project.md | 7 +- src/ru/guide/start/databases.md | 16 +- src/ru/guide/start/hello.md | 12 +- src/ru/guide/views/template-engines.md | 6 +- 39 files changed, 5771 insertions(+), 616 deletions(-) diff --git a/_translations/po/es/guide_databases_db-migrations.md.po b/_translations/po/es/guide_databases_db-migrations.md.po index 007c2261..6ace1db9 100644 --- a/_translations/po/es/guide_databases_db-migrations.md.po +++ b/_translations/po/es/guide_databases_db-migrations.md.po @@ -6,7 +6,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" -"POT-Creation-Date: 2025-11-03 12:48+0000\n" +"POT-Creation-Date: 2025-12-25 22:40+0000\n" "PO-Revision-Date: 2025-09-04 11:19+0500\n" "Last-Translator: Automatically generated\n" "Language-Team: none\n" @@ -17,106 +17,483 @@ msgstr "" "Plural-Forms: nplurals=2; plural=(n != 1);\n" #. type: Title # -#: ../../guide/en/databases/db-migrations.md +#: ../src/guide/databases/db-migrations.md #, no-wrap msgid "Migrations" msgstr "" #. type: Plain text -#: ../../guide/en/databases/db-migrations.md +#: ../src/guide/databases/db-migrations.md +msgid "During the course of developing and maintaining a database-driven application, the structure of the database being used evolves just like the source code does. For example, during the development of an application, a new table may be found necessary; after the application is deployed to production, it may be discovered that an index should be created to improve the query performance; and so on. Because a database structure change often requires some source code changes, Yii supports the so-called *database migration* feature that allows you to keep track of database changes in terms of *database migrations* which are version-controlled together with the source code." +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +msgid "The following steps show how database migration can be used by a team during development:" +msgstr "" + +#. type: Bullet: '1. ' +#: ../src/guide/databases/db-migrations.md +msgid "Tim creates a new migration (e.g. creates a new table, changes a column definition, etc.)." +msgstr "" + +#. type: Bullet: '2. ' +#: ../src/guide/databases/db-migrations.md +msgid "Tim commits the new migration into the source control system (e.g. Git, Mercurial)." +msgstr "" + +#. type: Bullet: '3. ' +#: ../src/guide/databases/db-migrations.md +msgid "Doug updates his repository from the source control system and receives the new migration." +msgstr "" + +#. type: Bullet: '4. ' +#: ../src/guide/databases/db-migrations.md +msgid "Doug applies the migration to his local development database, thereby synchronizing his database to reflect the changes that Tim has made." +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +msgid "And the following steps show how to deploy a new release with database migrations to production:" +msgstr "" + +#. type: Bullet: '1. ' +#: ../src/guide/databases/db-migrations.md +msgid "Scott creates a release tag for the project repository that contains some new database migrations." +msgstr "" + +#. type: Bullet: '2. ' +#: ../src/guide/databases/db-migrations.md +msgid "Scott updates the source code on the production server to the release tag." +msgstr "" + +#. type: Bullet: '3. ' +#: ../src/guide/databases/db-migrations.md +msgid "Scott applies any accumulated database migrations to the production database." +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +msgid "Yii provides a set of migration command line tools that allow you to:" +msgstr "" + +#. type: Bullet: '* ' +#: ../src/guide/databases/db-migrations.md +msgid "create new migrations;" +msgstr "" + +#. type: Bullet: '* ' +#: ../src/guide/databases/db-migrations.md +msgid "apply migrations;" +msgstr "" + +#. type: Bullet: '* ' +#: ../src/guide/databases/db-migrations.md +msgid "revert migrations;" +msgstr "" + +#. type: Bullet: '* ' +#: ../src/guide/databases/db-migrations.md +msgid "re-apply migrations;" +msgstr "" + +#. type: Bullet: '* ' +#: ../src/guide/databases/db-migrations.md +msgid "show migration history and status." +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +msgid "All these tools are accessible through the command `yii migrate`. In this section we will describe in detail how to accomplish various tasks using these tools." +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +#, no-wrap +msgid "" +"> [!TIP]\n" +"> Migrations could affect not only database schema but adjust existing data to fit new schema, create RBAC\n" +"hierarchy or clean up cache.\n" +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +#, no-wrap +msgid "" +"> [!NOTE]\n" +"> When manipulating data using a migration you may find that using your Active Record or entity classes\n" +"> for this might be useful because some of the logic is already implemented there. Keep in mind however, that in contrast\n" +"> to code written in the migrations, whose nature is to stay constant forever, application logic is subject to change.\n" +"> So when using Active Record or entity classes in migration code, changes to the logic in the source code\n" +"> may accidentally break the existing migrations. For this reason migration code should be kept independent of other\n" +"> application logic such.\n" +msgstr "" + +#. type: Title ## +#: ../src/guide/databases/db-migrations.md +#, fuzzy, no-wrap +#| msgid "Introduction +" +msgid "Initial configuration" +msgstr "Introducción" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md msgid "To use migrations, install [yiisoft/db-migration](https://github.com/yiisoft/db-migration/) package:" msgstr "" -#. type: Fenced code block (shell) -#: ../../guide/en/databases/db-migrations.md +#. type: Fenced code block (sh) +#: ../src/guide/databases/db-migrations.md ../src/guide/start/databases.md #, no-wrap -msgid "composer require yiisoft/db-migration\n" +msgid "make composer require yiisoft/db-migration\n" +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +msgid "Create a directory to store migrations `src/Migration` right in the project root." +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +msgid "Add the following configuration to `config/common/params.php`:" +msgstr "" + +#. type: Fenced code block (php) +#: ../src/guide/databases/db-migrations.md ../src/guide/start/databases.md +#, no-wrap +msgid "" +"'yiisoft/db-migration' => [\n" +" 'newMigrationNamespace' => 'App\\\\Migration',\n" +" 'sourceNamespaces' => ['App\\\\Migration'],\n" +"],\n" +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +msgid "You need a database connection configured as well. See [Working with databases](../start/databases.md) for an example of configuring it for PostgreSQL." msgstr "" #. type: Title ### -#: ../../guide/en/databases/db-migrations.md +#: ../src/guide/databases/db-migrations.md +#, no-wrap +msgid "Creating a migration" +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +msgid "To create a new empty migration, run the following command:" +msgstr "" + +#. type: Fenced code block (sh) +#: ../src/guide/databases/db-migrations.md +#, no-wrap +msgid "make yii migrate:create \n" +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +msgid "The required `name` argument gives a brief description about the new migration. For example, if the migration is about creating a new table named *news*, you may use the name `create_news_table` and run the following command:" +msgstr "" + +#. type: Fenced code block +#: ../src/guide/databases/db-migrations.md #, no-wrap -msgid "Example usage" +msgid "make yii migrate:create create_news_table\n" msgstr "" #. type: Plain text -#: ../../guide/en/databases/db-migrations.md -msgid "First, configure a DI container. Create `config/common/db.php` with the following content:" +#: ../src/guide/databases/db-migrations.md +#, no-wrap +msgid "" +"> [!NOTE]\n" +"> Because the `name` argument will be used as part of the generated migration class name,\n" +"> it should only contain letters, digits, and/or underscore characters.\n" +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +msgid "The above command will create a new PHP class file named `src/Migration/M251225221906CreateNewsTable.php`. The file contains the following code which mainly declares a migration class with the skeleton code:" msgstr "" #. type: Fenced code block (php) -#: ../../guide/en/databases/db-migrations.md +#: ../src/guide/databases/db-migrations.md #, no-wrap msgid "" " [\n" -" 'class' => SqliteConnection::class,\n" -" '__construct()' => [\n" -" 'dsn' => 'sqlite:' . __DIR__ . '/Data/yiitest.sq3'\n" -" ]\n" -" ]\n" -"];\n" +"use Yiisoft\\Db\\Migration\\MigrationBuilder;\n" +"use Yiisoft\\Db\\Migration\\RevertibleMigrationInterface;\n" +"\n" +"final class M251225221906CreateNewsTable implements RevertibleMigrationInterface\n" +"{\n" +" public function up(MigrationBuilder $b): void\n" +" {\n" +" // TODO: Implement the logic to apply the migration.\n" +" }\n" +"\n" +" public function down(MigrationBuilder $b): void\n" +" {\n" +" // TODO: Implement the logic to revert the migration.\n" +" }\n" +"}\n" msgstr "" #. type: Plain text -#: ../../guide/en/databases/db-migrations.md -msgid "Add the following to `config/params.php`:" +#: ../src/guide/databases/db-migrations.md +msgid "In the migration class, you are expected to write code in the `up()` method that makes changes to the database structure. You may also want to write code in the `down()` method to revert the changes made by `up()`. The `up()` method is invoked when you upgrade the database with this migration, while the `down()` method is invoked when you downgrade the database. The following code shows how you may implement the migration class to create a `news` table:" msgstr "" #. type: Fenced code block (php) -#: ../../guide/en/databases/db-migrations.md +#: ../src/guide/databases/db-migrations.md #, no-wrap msgid "" -"...\n" -"'yiisoft/db-migration' => [\n" -" 'newMigrationNamespace' => 'App\\\\Migration',\n" -" 'sourceNamespaces' => ['App\\\\Migration'],\n" -"],\n" -"...\n" +"columnBuilder();\n" +"\n" +" $b->createTable('news', [\n" +" 'id' => $cb::uuidPrimaryKey(),\n" +" 'title' => $cb::string()->notNull(),\n" +" 'content' => $cb::text(),\n" +" ]);\n" +" }\n" +"\n" +" public function down(MigrationBuilder $b): void\n" +" {\n" +" $b->dropTable('news');\n" +" }\n" +"}\n" msgstr "" #. type: Plain text -#: ../../guide/en/databases/db-migrations.md -msgid "Now test if it works:" +#: ../src/guide/databases/db-migrations.md +#, no-wrap +msgid "" +"TODO: explain $b and $qb\n" +"Below is the list of all these database accessing methods:\n" msgstr "" -#. type: Fenced code block (shell) -#: ../../guide/en/databases/db-migrations.md +#. type: Title ### +#: ../src/guide/databases/db-migrations.md #, no-wrap -msgid "./yii list migrate\n" +msgid "Irreversible migrations" +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +msgid "Not all migrations are reversible. For example, if the `up()` method deletes a row of a table, you may not be able to recover this row in the `down()` method. Sometimes, you may be just too lazy to implement the `down()`, because it is not very common to revert database migrations. In this case, you should implement `Yiisoft\\Db\\Migration\\MigrationInterface` that has `up()` only." msgstr "" #. type: Title ### -#: ../../guide/en/databases/db-migrations.md +#: ../src/guide/databases/db-migrations.md #, no-wrap -msgid "Creating a migration" +msgid "Transactional migrations (TODO: update!!!)" +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +msgid "While performing complex DB migrations, it is important to ensure each migration to either succeed or fail as a whole so that the database can maintain integrity and consistency. To achieve this goal, it is recommended that you enclose the DB operations of each migration in a [transaction](db-dao.md#performing-transactions)." +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +msgid "An even easier way of implementing transactional migrations is to put migration code in the `safeUp()` and `safeDown()` methods. These two methods differ from `up()` and `down()` in that they are enclosed implicitly in a transaction. As a result, if any operation in these methods fails, all prior operations will be rolled back automatically." +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +msgid "In the following example, besides creating the `news` table we also insert an initial row into this table." +msgstr "" + +#. type: Fenced code block (php) +#: ../src/guide/databases/db-migrations.md +#, no-wrap +msgid "" +"createTable('news', [\n" +" 'id' => $this->primaryKey(),\n" +" 'title' => $this->string()->notNull(),\n" +" 'content' => $this->text(),\n" +" ]);\n" +"\n" +" $this->insert('news', [\n" +" 'title' => 'test 1',\n" +" 'content' => 'content 1',\n" +" ]);\n" +" }\n" +"\n" +" public function safeDown()\n" +" {\n" +" $this->delete('news', ['id' => 1]);\n" +" $this->dropTable('news');\n" +" }\n" +"}\n" +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +msgid "Note that usually when you perform multiple DB operations in `safeUp()`, you should reverse their execution order in `safeDown()`. In the above example we first create the table and then insert a row in `safeUp()`; while in `safeDown()` we first delete the row and then drop the table." +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +#, no-wrap +msgid "" +"> Note: Not all DBMS support transactions. And some DB queries cannot be put into a transaction. For some examples,\n" +"please refer to [implicit commit](https://dev.mysql.com/doc/refman/5.7/en/implicit-commit.html). If this is the case,\n" +"you should still implement `up()` and `down()`, instead.\n" +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +#, no-wrap +msgid "TODO: TransactionalMigrationInterface\n" +msgstr "" + +#. type: Title ## +#: ../src/guide/databases/db-migrations.md +#, no-wrap +msgid "TODO: update" +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +msgid "The base migration class [[yii\\db\\Migration]] exposes a database connection via the [[yii\\db\\Migration::db|db]] property. You can use it to manipulate the database schema using the methods as described in [Working with Database Schema](db-dao.md#database-schema)." +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +#, no-wrap +msgid "" +"Rather than using physical types, when creating a table or column you should use *abstract types*\n" +"so that your migrations are independent of specific DBMS. The [[yii\\db\\Schema]] class defines\n" +"a set of constants to represent the supported abstract types. These constants are named in the format\n" +"of `TYPE_`. For example, `TYPE_PK` refers to auto-incremental primary key type; `TYPE_STRING`\n" +"refers to a string type. When a migration is applied to a particular database, the abstract types\n" +"will be translated into the corresponding physical types. In the case of MySQL, `TYPE_PK` will be turned\n" +"into `int(11) NOT NULL AUTO_INCREMENT PRIMARY KEY`, while `TYPE_STRING` becomes `varchar(255)`.\n" +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +msgid "You can append additional constraints when using abstract types. In the above example, ` NOT NULL` is appended to `Schema::TYPE_STRING` to specify that the column cannot be `null`." +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +#, no-wrap +msgid "" +"> Info: The mapping between abstract types and physical types is specified by\n" +"the [[yii\\db\\QueryBuilder::$typeMap|$typeMap]] property in each concrete `QueryBuilder` class.\n" +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +msgid "Since version 2.0.6, you can make use of the newly introduced schema builder which provides more convenient way of defining column schema. So the migration above could be written like the following:" +msgstr "" + +#. type: Fenced code block (php) +#: ../src/guide/databases/db-migrations.md +#, no-wrap +msgid "" +"createTable('news', [\n" +" 'id' => $this->primaryKey(),\n" +" 'title' => $this->string()->notNull(),\n" +" 'content' => $this->text(),\n" +" ]);\n" +" }\n" +"\n" +" public function down()\n" +" {\n" +" $this->dropTable('news');\n" +" }\n" +"}\n" +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +msgid "A list of all available methods for defining the column types is available in the API documentation of [[yii\\db\\SchemaBuilderTrait]]." +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +#, no-wrap +msgid "" +"> Info: The generated file permissions and ownership will be determined by the current environment. This might lead to\n" +"inaccessible files. This could, for example, happen when the migration is created within a docker container\n" +"and the files are edited on the host. In this case the `newFileMode` and/or `newFileOwnership` of the MigrateController\n" +"can be changed. E.g. in the application config:\n" +msgstr "" + +#. type: Fenced code block (php) +#: ../src/guide/databases/db-migrations.md +#, no-wrap +msgid "" +" [\n" +" 'migrate' => [\n" +" 'class' => 'yii\\console\\controllers\\MigrateController',\n" +" 'newFileOwnership' => '1000:1000', # Default WSL user id\n" +" 'newFileMode' => 0660,\n" +" ],\n" +" ],\n" +" ];\n" +msgstr "" + +#. type: Title ## +#: ../src/guide/databases/db-migrations.md +#, no-wrap +msgid "Generating Migrations (TODO: likely is OK but...)" msgstr "" #. type: Plain text -#: ../../guide/en/databases/db-migrations.md -msgid "To work with migrations, you can use the provided [view](https://github.com/yiisoft/db-migration/tree/master/resources/views)." +#: ../src/guide/databases/db-migrations.md +msgid "The command provides a convenient way to create migrations using the provided [view](https://github.com/yiisoft/db-migration/tree/master/resources/views):" msgstr "" #. type: Fenced code block (shell) -#: ../../guide/en/databases/db-migrations.md +#: ../src/guide/databases/db-migrations.md #, no-wrap -msgid "./yii migrate:create my_first_table --command=table --fields=name,example --table-comment=my_first_table\n" +msgid "make yii migrate:create my_first_table --command=table --fields=name,example --table-comment=my_first_table\n" msgstr "" #. type: Plain text -#: ../../guide/en/databases/db-migrations.md +#: ../src/guide/databases/db-migrations.md msgid "That would generate the following:" msgstr "" #. type: Fenced code block (php) -#: ../../guide/en/databases/db-migrations.md +#: ../src/guide/databases/db-migrations.md #, no-wrap msgid "" " Tip: In case you don't have command line at your server you may try [web shell](https://github.com/samdark/yii2-webshell)\n" +"> extension.\n" +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +msgid "For each migration that has been successfully applied, the command will insert a row into a database table named `migration` to record the successful application of the migration. This will allow the migration tool to identify which migrations have been applied and which have not." +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +#, no-wrap +msgid "" +"> Info: The migration tool will automatically create the `migration` table in the database specified by\n" +"the [[yii\\console\\controllers\\MigrateController::db|db]] option of the command. By default, the database\n" +"is specified by the `db` [application component](structure-application-components.md).\n" +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +msgid "Sometimes, you may only want to apply one or a few new migrations, instead of all available migrations. You can do so by specifying the number of migrations that you want to apply when running the command. For example, the following command will try to apply the next three available migrations:" +msgstr "" + +#. type: Fenced code block +#: ../src/guide/databases/db-migrations.md +#, no-wrap +msgid "yii migrate 3\n" +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +msgid "You can also explicitly specify a particular migration to which the database should be migrated by using the `migrate/to` command in one of the following formats:" +msgstr "" + +#. type: Fenced code block +#: ../src/guide/databases/db-migrations.md +#, no-wrap +msgid "" +"yii migrate/to 150101_185401 # using timestamp to specify the migration\n" +"yii migrate/to \"2015-01-01 18:54:01\" # using a string that can be parsed by strtotime()\n" +"yii migrate/to m150101_185401_create_news_table # using full name\n" +"yii migrate/to 1392853618 # using UNIX timestamp\n" +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +msgid "If there are any unapplied migrations earlier than the specified one, they will all be applied before the specified migration is applied." +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +msgid "If the specified migration has already been applied before, any later applied migrations will be reverted." +msgstr "" + +#. type: Title ## +#: ../src/guide/databases/db-migrations.md +#, fuzzy, no-wrap +#| msgid "Resolving aliases " +msgid "Reverting Migrations " +msgstr "Resolución de Alias " + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +msgid "To revert (undo) one or multiple migrations that have been applied before, you can run the following command:" +msgstr "" + +#. type: Fenced code block +#: ../src/guide/databases/db-migrations.md +#, no-wrap +msgid "" +"yii migrate/down # revert the most recently applied migration\n" +"yii migrate/down 3 # revert the most 3 recently applied migrations\n" +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +#, no-wrap +msgid "" +"> Note: Not all migrations are reversible. Trying to revert such migrations will cause an error and stop the\n" +"entire reverting process.\n" +msgstr "" + +#. type: Title ## +#: ../src/guide/databases/db-migrations.md +#, fuzzy, no-wrap +#| msgid "Resolving aliases " +msgid "Redoing Migrations " +msgstr "Resolución de Alias " + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +msgid "Redoing migrations means first reverting the specified migrations and then applying again. This can be done as follows:" +msgstr "" + +#. type: Fenced code block +#: ../src/guide/databases/db-migrations.md +#, no-wrap +msgid "" +"yii migrate/redo # redo the last applied migration\n" +"yii migrate/redo 3 # redo the last 3 applied migrations\n" +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +#, no-wrap +msgid "> Note: If a migration is not reversible, you will not be able to redo it.\n" +msgstr "" + +#. type: Title ## +#: ../src/guide/databases/db-migrations.md +#, fuzzy, no-wrap +#| msgid "Resolving aliases " +msgid "Refreshing Migrations " +msgstr "Resolución de Alias " + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +msgid "Since Yii 2.0.13 you can delete all tables and foreign keys from the database and apply all migrations from the beginning." +msgstr "" + +#. type: Fenced code block +#: ../src/guide/databases/db-migrations.md +#, no-wrap +msgid "yii migrate/fresh # truncate the database and apply all migrations from the beginning\n" +msgstr "" + +#. type: Title ## +#: ../src/guide/databases/db-migrations.md +#, fuzzy, no-wrap +#| msgid "Raising events " +msgid "Listing Migrations " +msgstr "Lanzamiento de Eventos " + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +msgid "To list which migrations have been applied and which are not, you may use the following commands:" +msgstr "" + +#. type: Fenced code block +#: ../src/guide/databases/db-migrations.md +#, no-wrap +msgid "" +"yii migrate/history # showing the last 10 applied migrations\n" +"yii migrate/history 5 # showing the last 5 applied migrations\n" +"yii migrate/history all # showing all applied migrations\n" +"\n" +"yii migrate/new # showing the first 10 new migrations\n" +"yii migrate/new 5 # showing the first 5 new migrations\n" +"yii migrate/new all # showing all new migrations\n" +msgstr "" + +#. type: Title ## +#: ../src/guide/databases/db-migrations.md +#, no-wrap +msgid "Modifying Migration History " +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +msgid "Instead of actually applying or reverting migrations, sometimes you may simply want to mark that your database has been upgraded to a particular migration. This often happens when you manually change the database to a particular state and you do not want the migration(s) for that change to be re-applied later. You can achieve this goal with the following command:" +msgstr "" + +#. type: Fenced code block +#: ../src/guide/databases/db-migrations.md +#, no-wrap +msgid "" +"yii migrate/mark 150101_185401 # using timestamp to specify the migration\n" +"yii migrate/mark \"2015-01-01 18:54:01\" # using a string that can be parsed by strtotime()\n" +"yii migrate/mark m150101_185401_create_news_table # using full name\n" +"yii migrate/mark 1392853618 # using UNIX timestamp\n" +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +msgid "The command will modify the `migration` table by adding or deleting certain rows to indicate that the database has been applied migrations to the specified one. No migrations will be applied or reverted by this command." +msgstr "" + +#. type: Title ## +#: ../src/guide/databases/db-migrations.md +#, fuzzy, no-wrap +#| msgid "Raising events " +msgid "Customizing Migrations " +msgstr "Lanzamiento de Eventos " + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +msgid "There are several ways to customize the migration command." +msgstr "" + +#. type: Title ### +#: ../src/guide/databases/db-migrations.md +#, fuzzy, no-wrap +#| msgid "Resolving aliases " +msgid "Using Command Line Options " +msgstr "Resolución de Alias " + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +msgid "The migration command comes with a few command-line options that can be used to customize its behaviors:" +msgstr "" + +#. type: Bullet: '* ' +#: ../src/guide/databases/db-migrations.md +msgid "`interactive`: boolean (defaults to `true`), specifies whether to perform migrations in an interactive mode. When this is `true`, the user will be prompted before the command performs certain actions. You may want to set this to `false` if the command is being used in a background process." +msgstr "" + +#. type: Bullet: '* ' +#: ../src/guide/databases/db-migrations.md +msgid "`migrationPath`: string|array (defaults to `@app/migrations`), specifies the directory storing all migration class files. This can be specified as either a directory path or a path [alias](concept-aliases.md). Note that the directory must exist, or the command may trigger an error. Since version 2.0.12 an array can be specified for loading migrations from multiple sources." +msgstr "" + +#. type: Bullet: '* ' +#: ../src/guide/databases/db-migrations.md +msgid "`migrationTable`: string (defaults to `migration`), specifies the name of the database table for storing migration history information. The table will be automatically created by the command if it does not exist. You may also manually create it using the structure `version varchar(255) primary key, apply_time integer`." +msgstr "" + +#. type: Bullet: '* ' +#: ../src/guide/databases/db-migrations.md +msgid "`db`: string (defaults to `db`), specifies the ID of the database [application component](structure-application-components.md). It represents the database that will be migrated using this command." +msgstr "" + +#. type: Bullet: '* ' +#: ../src/guide/databases/db-migrations.md +msgid "`templateFile`: string (defaults to `@yii/views/migration.php`), specifies the path of the template file that is used for generating skeleton migration class files. This can be specified as either a file path or a path [alias](concept-aliases.md). The template file is a PHP script in which you can use a predefined variable named `$className` to get the migration class name." +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +#, no-wrap +msgid "" +"* `generatorTemplateFiles`: array (defaults to `[\n" +" 'create_table' => '@yii/views/createTableMigration.php',\n" +" 'drop_table' => '@yii/views/dropTableMigration.php',\n" +" 'add_column' => '@yii/views/addColumnMigration.php',\n" +" 'drop_column' => '@yii/views/dropColumnMigration.php',\n" +" 'create_junction' => '@yii/views/createTableMigration.php'\n" +" ]`), specifies template files for generating migration code. See \"[Generating Migrations](#generating-migrations)\"\n" +" for more details.\n" +msgstr "" + +#. type: Bullet: '* ' +#: ../src/guide/databases/db-migrations.md +msgid "`fields`: array of column definition strings used for creating migration code. Defaults to `[]`. The format of each definition is `COLUMN_NAME:COLUMN_TYPE:COLUMN_DECORATOR`. For example, `--fields=name:string(12):notNull` produces a string column of size 12 which is not `null`." +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +msgid "The following example shows how you can use these options." +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +msgid "For example, if we want to migrate a `forum` module whose migration files are located within the module's `migrations` directory, we can use the following command:" +msgstr "" + +#. type: Fenced code block +#: ../src/guide/databases/db-migrations.md +#, no-wrap +msgid "" +"# migrate the migrations in a forum module non-interactively\n" +"yii migrate --migrationPath=@app/modules/forum/migrations --interactive=0\n" +msgstr "" + +#. type: Title ### +#: ../src/guide/databases/db-migrations.md +#, no-wrap +msgid "Separated Migrations" +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +msgid "Sometimes using single migration history for all project migrations is not desirable. For example: you may install some 'blog' extension, which contains fully separated functionality and contain its own migrations, which should not affect the ones dedicated to main project functionality." +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +msgid "If you want several migrations to be applied and tracked down completely separated from each other, you can configure multiple migration commands which will use different namespaces and migration history tables:" +msgstr "" + +#. type: Fenced code block (php) +#: ../src/guide/databases/db-migrations.md +#, no-wrap +msgid "" +"return [\n" +" 'controllerMap' => [\n" +" // Common migrations for the whole application\n" +" 'migrate-app' => [\n" +" 'class' => 'yii\\console\\controllers\\MigrateController',\n" +" 'migrationNamespaces' => ['app\\migrations'],\n" +" 'migrationTable' => 'migration_app',\n" +" 'migrationPath' => null,\n" +" ],\n" +" // Migrations for the specific project's module\n" +" 'migrate-module' => [\n" +" 'class' => 'yii\\console\\controllers\\MigrateController',\n" +" 'migrationNamespaces' => ['module\\migrations'],\n" +" 'migrationTable' => 'migration_module',\n" +" 'migrationPath' => null,\n" +" ],\n" +" // Migrations for the specific extension\n" +" 'migrate-rbac' => [\n" +" 'class' => 'yii\\console\\controllers\\MigrateController',\n" +" 'migrationPath' => '@yii/rbac/migrations',\n" +" 'migrationTable' => 'migration_rbac',\n" +" ],\n" +" ],\n" +"];\n" +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +msgid "Note that to synchronize database you now need to run multiple commands instead of one:" +msgstr "" + +#. type: Fenced code block +#: ../src/guide/databases/db-migrations.md +#, no-wrap +msgid "" +"yii migrate-app\n" +"yii migrate-module\n" +"yii migrate-rbac\n" +msgstr "" + +#. type: Title ## +#: ../src/guide/databases/db-migrations.md +#, fuzzy, no-wrap +#| msgid "Defining aliases " +msgid "Migrating Multiple Databases " +msgstr "Definir Alias " + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +msgid "By default, migrations are applied to the same database specified by the `db` [application component](structure-application-components.md). If you want them to be applied to a different database, you may specify the `db` command-line option like shown below," +msgstr "" + +#. type: Fenced code block +#: ../src/guide/databases/db-migrations.md +#, no-wrap +msgid "yii migrate --db=db2\n" +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +msgid "The above command will apply migrations to the `db2` database." +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +msgid "Sometimes it may happen that you want to apply *some* of the migrations to one database, while some others to another database. To achieve this goal, when implementing a migration class you should explicitly specify the DB component ID that the migration would use, like the following:" +msgstr "" + +#. type: Fenced code block (php) +#: ../src/guide/databases/db-migrations.md +#, no-wrap +msgid "" +"db = 'db2';\n" +" parent::init();\n" +" }\n" +"}\n" +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +msgid "The above migration will be applied to `db2`, even if you specify a different database through the `db` command-line option. Note that the migration history will still be recorded in the database specified by the `db` command-line option." +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +msgid "If you have multiple migrations that use the same database, it is recommended that you create a base migration class with the above `init()` code. Then each migration class can extend from this base class." +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +#, no-wrap +msgid "" +"> Tip: Besides setting the [[yii\\db\\Migration::db|db]] property, you can also operate on different databases\n" +"by creating new database connections to them in your migration classes. You then use the [DAO methods](db-dao.md)\n" +"with these connections to manipulate different databases.\n" +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +msgid "Another strategy that you can take to migrate multiple databases is to keep migrations for different databases in different migration paths. Then you can migrate these databases in separate commands like the following:" +msgstr "" + +#. type: Fenced code block +#: ../src/guide/databases/db-migrations.md +#, no-wrap +msgid "" +"yii migrate --migrationPath=@app/migrations/db1 --db=db1\n" +"yii migrate --migrationPath=@app/migrations/db2 --db=db2\n" +"...\n" +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +msgid "The first command will apply migrations in `@app/migrations/db1` to the `db1` database, the second command will apply migrations in `@app/migrations/db2` to `db2`, and so on." +msgstr "" + #. type: Title ### -#: ../../guide/en/databases/db-migrations.md +#: ../src/guide/databases/db-migrations.md #, no-wrap msgid "Upgrading from Yii2" msgstr "" #. type: Plain text -#: ../../guide/en/databases/db-migrations.md +#: ../src/guide/databases/db-migrations.md msgid "Migrations in Yii2 and the [yiisoft/db-migration](https://github.com/yiisoft/db-migration/) package are not compatible, and the `migration` table is also not compatible. A probable solution is to use structure dumps and rename the old `migration` table. Upon the initial execution of migrations, a new `migration` table with new fields will be created. All further changes in the database schema are applied using the new `migration` component and recorded in the new migration table." msgstr "" diff --git a/_translations/po/es/guide_start_creating-project.md.po b/_translations/po/es/guide_start_creating-project.md.po index d18ed6d0..33f40b05 100644 --- a/_translations/po/es/guide_start_creating-project.md.po +++ b/_translations/po/es/guide_start_creating-project.md.po @@ -6,7 +6,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" -"POT-Creation-Date: 2025-12-24 13:00+0000\n" +"POT-Creation-Date: 2025-12-25 22:40+0000\n" "PO-Revision-Date: 2025-09-04 11:19+0500\n" "Last-Translator: Automatically generated\n" "Language-Team: none\n" @@ -33,7 +33,7 @@ msgstr "" msgid "" "> [!NOTE]\n" "> If you want to use another web server,\n" -"> see [\"Configuring web servers\"](../../../cookbook/en/configuring-webservers/general.md).\n" +"> see [\"Configuring web servers\"](../../cookbook/configuring-webservers/general.md).\n" msgstr "" #. type: Plain text @@ -54,13 +54,17 @@ msgstr "" #. type: Plain text #: ../src/guide/start/creating-project.md -msgid "Docker users can run the following command:" -msgstr "" +#, fuzzy +#| msgid "Events are raised like the following:" +msgid "Docker users can run the following commands:" +msgstr "Los eventos se lanzan de la siguiente forma:" #. type: Fenced code block (sh) #: ../src/guide/start/creating-project.md #, no-wrap -msgid "docker run --rm -it -v \"$(pwd):/app\" composer/composer create-project yiisoft/app your_project\n" +msgid "" +"docker run --rm -it -v \"$(pwd):/app\" composer/composer create-project yiisoft/app your_project\n" +"sudo chown -R $(id -u):$(id -g) your_project\n" msgstr "" #. type: Plain text diff --git a/_translations/po/es/guide_start_databases.md.po b/_translations/po/es/guide_start_databases.md.po index 884cabc0..6f5ff752 100644 --- a/_translations/po/es/guide_start_databases.md.po +++ b/_translations/po/es/guide_start_databases.md.po @@ -6,7 +6,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" -"POT-Creation-Date: 2025-12-24 13:00+0000\n" +"POT-Creation-Date: 2025-12-25 22:40+0000\n" "PO-Revision-Date: 2025-09-04 11:19+0500\n" "Last-Translator: Automatically generated\n" "Language-Team: none\n" @@ -16,6 +16,22 @@ msgstr "" "Content-Transfer-Encoding: 8bit\n" "Plural-Forms: nplurals=2; plural=(n != 1);\n" +#. type: Fenced code block (sh) +#: ../src/guide/databases/db-migrations.md ../src/guide/start/databases.md +#, no-wrap +msgid "make composer require yiisoft/db-migration\n" +msgstr "" + +#. type: Fenced code block (php) +#: ../src/guide/databases/db-migrations.md ../src/guide/start/databases.md +#, no-wrap +msgid "" +"'yiisoft/db-migration' => [\n" +" 'newMigrationNamespace' => 'App\\\\Migration',\n" +" 'sourceNamespaces' => ['App\\\\Migration'],\n" +"],\n" +msgstr "" + #. type: Title # #: ../src/guide/index.md ../src/guide/start/databases.md #, no-wrap @@ -165,18 +181,13 @@ msgstr "" #. type: Plain text #: ../src/guide/start/databases.md -msgid "Let's use latest versions to be released. Change your `minimum-stability` to `dev` in `composer.json` first." -msgstr "" - -#. type: Plain text -#: ../src/guide/start/databases.md -msgid "Then we need a package to be installed:" +msgid "First we need a package to be installed:" msgstr "" #. type: Fenced code block (sh) #: ../src/guide/start/databases.md #, no-wrap -msgid "make composer require yiisoft/db-pgsql dev-master\n" +msgid "make composer require yiisoft/db-pgsql\n" msgstr "" #. type: Plain text @@ -257,27 +268,11 @@ msgstr "" msgid "To use migrations we need another package installed:" msgstr "" -#. type: Fenced code block (sh) -#: ../src/guide/start/databases.md -#, no-wrap -msgid "composer require yiisoft/db-migration dev-master\n" -msgstr "" - #. type: Plain text #: ../src/guide/start/databases.md msgid "Create a directory to store migrations `src/Migration` right in the project root. Add the following configuration to `config/common/params.php`:" msgstr "" -#. type: Fenced code block (php) -#: ../src/guide/start/databases.md -#, no-wrap -msgid "" -"'yiisoft/db-migration' => [\n" -" 'newMigrationNamespace' => 'App\\\\Migration',\n" -" 'sourceNamespaces' => ['App\\\\Migration'],\n" -"],\n" -msgstr "" - #. type: Plain text #: ../src/guide/start/databases.md msgid "Now you can use `make yii migrate:create page` to create a new migration. For our example we need a `page` table with some columns:" @@ -296,9 +291,6 @@ msgid "" "use Yiisoft\\Db\\Migration\\MigrationBuilder;\n" "use Yiisoft\\Db\\Migration\\RevertibleMigrationInterface;\n" "\n" -"/**\n" -" * Class M251102141707Page\n" -" */\n" "final class M251102141707Page implements RevertibleMigrationInterface\n" "{\n" " public function up(MigrationBuilder $b): void\n" @@ -350,6 +342,8 @@ msgstr "" msgid "" "responseFactory->createResponse();\n" " $response->getBody()->write('The message is: ' . Html::encode($message));\n" @@ -226,7 +228,7 @@ msgid "To use the view, you need to change `src/Web/Echo/Action.php`:" msgstr "" #. type: Fenced code block (php) -#: ../src/guide/start/hello.md ../src/guide/views/view.md +#: ../src/guide/start/hello.md #, no-wrap msgid "" "viewRenderer->render(__DIR__ . '/template', [\n" " 'message' => $message,\n" diff --git a/_translations/po/es/guide_views_template-engines.md.po b/_translations/po/es/guide_views_template-engines.md.po index 8ab61d0c..f61970d4 100644 --- a/_translations/po/es/guide_views_template-engines.md.po +++ b/_translations/po/es/guide_views_template-engines.md.po @@ -6,7 +6,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" -"POT-Creation-Date: 2025-12-24 13:00+0000\n" +"POT-Creation-Date: 2025-12-25 22:40+0000\n" "PO-Revision-Date: 2025-12-24 08:02+0000\n" "Last-Translator: Automatically generated\n" "Language-Team: none\n" @@ -259,10 +259,12 @@ msgstr "" #: ../src/guide/views/template-engines.md #, no-wrap msgid "" +"use Yiisoft\\Container\\Reference;\n" +"\n" "// In configuration\n" "'yiisoft/view' => [\n" " 'renderers' => [\n" -" 'md' => App\\View\\MarkdownRenderer::class,\n" +" 'md' => Reference::to(App\\View\\MarkdownRenderer::class),\n" " ],\n" "],\n" msgstr "" @@ -286,7 +288,7 @@ msgid "" "\n" "Welcome, {{username}}!\n" "\n" -"This is a markdown template with **bold** and *italic* text.\n" +"This is a Markdown template with **bold** and *italic* text.\n" "\n" "- Feature 1\n" "- Feature 2\n" diff --git a/_translations/po/es/guide_views_view.md.po b/_translations/po/es/guide_views_view.md.po index cefb161f..47a179b0 100644 --- a/_translations/po/es/guide_views_view.md.po +++ b/_translations/po/es/guide_views_view.md.po @@ -6,7 +6,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" -"POT-Creation-Date: 2025-12-24 13:00+0000\n" +"POT-Creation-Date: 2025-12-25 22:40+0000\n" "PO-Revision-Date: 2025-12-24 08:02+0000\n" "Last-Translator: Automatically generated\n" "Language-Team: none\n" @@ -44,36 +44,6 @@ msgid "" "

The message is:

\n" msgstr "" -#. type: Fenced code block (php) -#: ../src/guide/start/hello.md ../src/guide/views/view.md -#, no-wrap -msgid "" -"viewRenderer->render(__DIR__ . '/template', [\n" -" 'message' => $message,\n" -" ]);\n" -" }\n" -"}\n" -msgstr "" - #. type: Title ## #: ../src/guide/views/asset.md ../src/guide/views/view.md #: ../src/guide/views/widget.md @@ -139,6 +109,36 @@ msgstr "" msgid "Here `$message` is a view data that is passed when you render a template with the help of `ViewRenderer`. For example, `src/Web/Echo/Action.php`:" msgstr "" +#. type: Fenced code block (php) +#: ../src/guide/views/view.md +#, no-wrap +msgid "" +"viewRenderer->render(__DIR__ . '/template', [\n" +" 'message' => $message,\n" +" ]);\n" +" }\n" +"}\n" +msgstr "" + #. type: Plain text #: ../src/guide/views/view.md msgid "First argument of the `render()` method is a path to the template file. In the `yiisoft/app`, template files are typically stored alongside their actions. The result is ready to be rendered to the browser so we return it immediately." diff --git a/_translations/po/id/guide_databases_db-migrations.md.po b/_translations/po/id/guide_databases_db-migrations.md.po index c9dc03f8..9ae91ea4 100644 --- a/_translations/po/id/guide_databases_db-migrations.md.po +++ b/_translations/po/id/guide_databases_db-migrations.md.po @@ -6,7 +6,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" -"POT-Creation-Date: 2025-11-03 12:48+0000\n" +"POT-Creation-Date: 2025-12-25 22:40+0000\n" "PO-Revision-Date: 2025-09-04 11:19+0500\n" "Last-Translator: Automatically generated\n" "Language-Team: none\n" @@ -16,106 +16,483 @@ msgstr "" "Content-Transfer-Encoding: 8bit\n" #. type: Title # -#: ../../guide/en/databases/db-migrations.md +#: ../src/guide/databases/db-migrations.md #, no-wrap msgid "Migrations" msgstr "" #. type: Plain text -#: ../../guide/en/databases/db-migrations.md +#: ../src/guide/databases/db-migrations.md +msgid "During the course of developing and maintaining a database-driven application, the structure of the database being used evolves just like the source code does. For example, during the development of an application, a new table may be found necessary; after the application is deployed to production, it may be discovered that an index should be created to improve the query performance; and so on. Because a database structure change often requires some source code changes, Yii supports the so-called *database migration* feature that allows you to keep track of database changes in terms of *database migrations* which are version-controlled together with the source code." +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +msgid "The following steps show how database migration can be used by a team during development:" +msgstr "" + +#. type: Bullet: '1. ' +#: ../src/guide/databases/db-migrations.md +msgid "Tim creates a new migration (e.g. creates a new table, changes a column definition, etc.)." +msgstr "" + +#. type: Bullet: '2. ' +#: ../src/guide/databases/db-migrations.md +msgid "Tim commits the new migration into the source control system (e.g. Git, Mercurial)." +msgstr "" + +#. type: Bullet: '3. ' +#: ../src/guide/databases/db-migrations.md +msgid "Doug updates his repository from the source control system and receives the new migration." +msgstr "" + +#. type: Bullet: '4. ' +#: ../src/guide/databases/db-migrations.md +msgid "Doug applies the migration to his local development database, thereby synchronizing his database to reflect the changes that Tim has made." +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +msgid "And the following steps show how to deploy a new release with database migrations to production:" +msgstr "" + +#. type: Bullet: '1. ' +#: ../src/guide/databases/db-migrations.md +msgid "Scott creates a release tag for the project repository that contains some new database migrations." +msgstr "" + +#. type: Bullet: '2. ' +#: ../src/guide/databases/db-migrations.md +msgid "Scott updates the source code on the production server to the release tag." +msgstr "" + +#. type: Bullet: '3. ' +#: ../src/guide/databases/db-migrations.md +msgid "Scott applies any accumulated database migrations to the production database." +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +msgid "Yii provides a set of migration command line tools that allow you to:" +msgstr "" + +#. type: Bullet: '* ' +#: ../src/guide/databases/db-migrations.md +msgid "create new migrations;" +msgstr "" + +#. type: Bullet: '* ' +#: ../src/guide/databases/db-migrations.md +msgid "apply migrations;" +msgstr "" + +#. type: Bullet: '* ' +#: ../src/guide/databases/db-migrations.md +msgid "revert migrations;" +msgstr "" + +#. type: Bullet: '* ' +#: ../src/guide/databases/db-migrations.md +msgid "re-apply migrations;" +msgstr "" + +#. type: Bullet: '* ' +#: ../src/guide/databases/db-migrations.md +msgid "show migration history and status." +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +msgid "All these tools are accessible through the command `yii migrate`. In this section we will describe in detail how to accomplish various tasks using these tools." +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +#, no-wrap +msgid "" +"> [!TIP]\n" +"> Migrations could affect not only database schema but adjust existing data to fit new schema, create RBAC\n" +"hierarchy or clean up cache.\n" +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +#, no-wrap +msgid "" +"> [!NOTE]\n" +"> When manipulating data using a migration you may find that using your Active Record or entity classes\n" +"> for this might be useful because some of the logic is already implemented there. Keep in mind however, that in contrast\n" +"> to code written in the migrations, whose nature is to stay constant forever, application logic is subject to change.\n" +"> So when using Active Record or entity classes in migration code, changes to the logic in the source code\n" +"> may accidentally break the existing migrations. For this reason migration code should be kept independent of other\n" +"> application logic such.\n" +msgstr "" + +#. type: Title ## +#: ../src/guide/databases/db-migrations.md +#, fuzzy, no-wrap +#| msgid "Container configuration" +msgid "Initial configuration" +msgstr "Konfigurasi container" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md msgid "To use migrations, install [yiisoft/db-migration](https://github.com/yiisoft/db-migration/) package:" msgstr "" -#. type: Fenced code block (shell) -#: ../../guide/en/databases/db-migrations.md +#. type: Fenced code block (sh) +#: ../src/guide/databases/db-migrations.md ../src/guide/start/databases.md +#, fuzzy, no-wrap +msgid "make composer require yiisoft/db-migration\n" +msgstr "composer require yiisoft/cache\n" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +msgid "Create a directory to store migrations `src/Migration` right in the project root." +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +msgid "Add the following configuration to `config/common/params.php`:" +msgstr "" + +#. type: Fenced code block (php) +#: ../src/guide/databases/db-migrations.md ../src/guide/start/databases.md #, no-wrap -msgid "composer require yiisoft/db-migration\n" +msgid "" +"'yiisoft/db-migration' => [\n" +" 'newMigrationNamespace' => 'App\\\\Migration',\n" +" 'sourceNamespaces' => ['App\\\\Migration'],\n" +"],\n" +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +msgid "You need a database connection configured as well. See [Working with databases](../start/databases.md) for an example of configuring it for PostgreSQL." msgstr "" #. type: Title ### -#: ../../guide/en/databases/db-migrations.md +#: ../src/guide/databases/db-migrations.md +#, no-wrap +msgid "Creating a migration" +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +msgid "To create a new empty migration, run the following command:" +msgstr "" + +#. type: Fenced code block (sh) +#: ../src/guide/databases/db-migrations.md +#, no-wrap +msgid "make yii migrate:create \n" +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +msgid "The required `name` argument gives a brief description about the new migration. For example, if the migration is about creating a new table named *news*, you may use the name `create_news_table` and run the following command:" +msgstr "" + +#. type: Fenced code block +#: ../src/guide/databases/db-migrations.md +#, no-wrap +msgid "make yii migrate:create create_news_table\n" +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md #, no-wrap -msgid "Example usage" +msgid "" +"> [!NOTE]\n" +"> Because the `name` argument will be used as part of the generated migration class name,\n" +"> it should only contain letters, digits, and/or underscore characters.\n" msgstr "" #. type: Plain text -#: ../../guide/en/databases/db-migrations.md -msgid "First, configure a DI container. Create `config/common/db.php` with the following content:" +#: ../src/guide/databases/db-migrations.md +msgid "The above command will create a new PHP class file named `src/Migration/M251225221906CreateNewsTable.php`. The file contains the following code which mainly declares a migration class with the skeleton code:" msgstr "" #. type: Fenced code block (php) -#: ../../guide/en/databases/db-migrations.md +#: ../src/guide/databases/db-migrations.md #, no-wrap msgid "" " [\n" -" 'class' => SqliteConnection::class,\n" -" '__construct()' => [\n" -" 'dsn' => 'sqlite:' . __DIR__ . '/Data/yiitest.sq3'\n" -" ]\n" -" ]\n" -"];\n" +"use Yiisoft\\Db\\Migration\\MigrationBuilder;\n" +"use Yiisoft\\Db\\Migration\\RevertibleMigrationInterface;\n" +"\n" +"final class M251225221906CreateNewsTable implements RevertibleMigrationInterface\n" +"{\n" +" public function up(MigrationBuilder $b): void\n" +" {\n" +" // TODO: Implement the logic to apply the migration.\n" +" }\n" +"\n" +" public function down(MigrationBuilder $b): void\n" +" {\n" +" // TODO: Implement the logic to revert the migration.\n" +" }\n" +"}\n" msgstr "" #. type: Plain text -#: ../../guide/en/databases/db-migrations.md -msgid "Add the following to `config/params.php`:" +#: ../src/guide/databases/db-migrations.md +msgid "In the migration class, you are expected to write code in the `up()` method that makes changes to the database structure. You may also want to write code in the `down()` method to revert the changes made by `up()`. The `up()` method is invoked when you upgrade the database with this migration, while the `down()` method is invoked when you downgrade the database. The following code shows how you may implement the migration class to create a `news` table:" msgstr "" #. type: Fenced code block (php) -#: ../../guide/en/databases/db-migrations.md +#: ../src/guide/databases/db-migrations.md #, no-wrap msgid "" -"...\n" -"'yiisoft/db-migration' => [\n" -" 'newMigrationNamespace' => 'App\\\\Migration',\n" -" 'sourceNamespaces' => ['App\\\\Migration'],\n" -"],\n" -"...\n" +"columnBuilder();\n" +"\n" +" $b->createTable('news', [\n" +" 'id' => $cb::uuidPrimaryKey(),\n" +" 'title' => $cb::string()->notNull(),\n" +" 'content' => $cb::text(),\n" +" ]);\n" +" }\n" +"\n" +" public function down(MigrationBuilder $b): void\n" +" {\n" +" $b->dropTable('news');\n" +" }\n" +"}\n" msgstr "" #. type: Plain text -#: ../../guide/en/databases/db-migrations.md -msgid "Now test if it works:" +#: ../src/guide/databases/db-migrations.md +#, no-wrap +msgid "" +"TODO: explain $b and $qb\n" +"Below is the list of all these database accessing methods:\n" msgstr "" -#. type: Fenced code block (shell) -#: ../../guide/en/databases/db-migrations.md +#. type: Title ### +#: ../src/guide/databases/db-migrations.md #, no-wrap -msgid "./yii list migrate\n" +msgid "Irreversible migrations" +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +msgid "Not all migrations are reversible. For example, if the `up()` method deletes a row of a table, you may not be able to recover this row in the `down()` method. Sometimes, you may be just too lazy to implement the `down()`, because it is not very common to revert database migrations. In this case, you should implement `Yiisoft\\Db\\Migration\\MigrationInterface` that has `up()` only." msgstr "" #. type: Title ### -#: ../../guide/en/databases/db-migrations.md +#: ../src/guide/databases/db-migrations.md #, no-wrap -msgid "Creating a migration" +msgid "Transactional migrations (TODO: update!!!)" +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +msgid "While performing complex DB migrations, it is important to ensure each migration to either succeed or fail as a whole so that the database can maintain integrity and consistency. To achieve this goal, it is recommended that you enclose the DB operations of each migration in a [transaction](db-dao.md#performing-transactions)." +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +msgid "An even easier way of implementing transactional migrations is to put migration code in the `safeUp()` and `safeDown()` methods. These two methods differ from `up()` and `down()` in that they are enclosed implicitly in a transaction. As a result, if any operation in these methods fails, all prior operations will be rolled back automatically." +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +msgid "In the following example, besides creating the `news` table we also insert an initial row into this table." +msgstr "" + +#. type: Fenced code block (php) +#: ../src/guide/databases/db-migrations.md +#, no-wrap +msgid "" +"createTable('news', [\n" +" 'id' => $this->primaryKey(),\n" +" 'title' => $this->string()->notNull(),\n" +" 'content' => $this->text(),\n" +" ]);\n" +"\n" +" $this->insert('news', [\n" +" 'title' => 'test 1',\n" +" 'content' => 'content 1',\n" +" ]);\n" +" }\n" +"\n" +" public function safeDown()\n" +" {\n" +" $this->delete('news', ['id' => 1]);\n" +" $this->dropTable('news');\n" +" }\n" +"}\n" +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +msgid "Note that usually when you perform multiple DB operations in `safeUp()`, you should reverse their execution order in `safeDown()`. In the above example we first create the table and then insert a row in `safeUp()`; while in `safeDown()` we first delete the row and then drop the table." +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +#, no-wrap +msgid "" +"> Note: Not all DBMS support transactions. And some DB queries cannot be put into a transaction. For some examples,\n" +"please refer to [implicit commit](https://dev.mysql.com/doc/refman/5.7/en/implicit-commit.html). If this is the case,\n" +"you should still implement `up()` and `down()`, instead.\n" +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +#, no-wrap +msgid "TODO: TransactionalMigrationInterface\n" +msgstr "" + +#. type: Title ## +#: ../src/guide/databases/db-migrations.md +#, no-wrap +msgid "TODO: update" +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +msgid "The base migration class [[yii\\db\\Migration]] exposes a database connection via the [[yii\\db\\Migration::db|db]] property. You can use it to manipulate the database schema using the methods as described in [Working with Database Schema](db-dao.md#database-schema)." +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +#, no-wrap +msgid "" +"Rather than using physical types, when creating a table or column you should use *abstract types*\n" +"so that your migrations are independent of specific DBMS. The [[yii\\db\\Schema]] class defines\n" +"a set of constants to represent the supported abstract types. These constants are named in the format\n" +"of `TYPE_`. For example, `TYPE_PK` refers to auto-incremental primary key type; `TYPE_STRING`\n" +"refers to a string type. When a migration is applied to a particular database, the abstract types\n" +"will be translated into the corresponding physical types. In the case of MySQL, `TYPE_PK` will be turned\n" +"into `int(11) NOT NULL AUTO_INCREMENT PRIMARY KEY`, while `TYPE_STRING` becomes `varchar(255)`.\n" +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +msgid "You can append additional constraints when using abstract types. In the above example, ` NOT NULL` is appended to `Schema::TYPE_STRING` to specify that the column cannot be `null`." +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +#, no-wrap +msgid "" +"> Info: The mapping between abstract types and physical types is specified by\n" +"the [[yii\\db\\QueryBuilder::$typeMap|$typeMap]] property in each concrete `QueryBuilder` class.\n" +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +msgid "Since version 2.0.6, you can make use of the newly introduced schema builder which provides more convenient way of defining column schema. So the migration above could be written like the following:" +msgstr "" + +#. type: Fenced code block (php) +#: ../src/guide/databases/db-migrations.md +#, no-wrap +msgid "" +"createTable('news', [\n" +" 'id' => $this->primaryKey(),\n" +" 'title' => $this->string()->notNull(),\n" +" 'content' => $this->text(),\n" +" ]);\n" +" }\n" +"\n" +" public function down()\n" +" {\n" +" $this->dropTable('news');\n" +" }\n" +"}\n" +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +msgid "A list of all available methods for defining the column types is available in the API documentation of [[yii\\db\\SchemaBuilderTrait]]." +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +#, no-wrap +msgid "" +"> Info: The generated file permissions and ownership will be determined by the current environment. This might lead to\n" +"inaccessible files. This could, for example, happen when the migration is created within a docker container\n" +"and the files are edited on the host. In this case the `newFileMode` and/or `newFileOwnership` of the MigrateController\n" +"can be changed. E.g. in the application config:\n" +msgstr "" + +#. type: Fenced code block (php) +#: ../src/guide/databases/db-migrations.md +#, no-wrap +msgid "" +" [\n" +" 'migrate' => [\n" +" 'class' => 'yii\\console\\controllers\\MigrateController',\n" +" 'newFileOwnership' => '1000:1000', # Default WSL user id\n" +" 'newFileMode' => 0660,\n" +" ],\n" +" ],\n" +" ];\n" +msgstr "" + +#. type: Title ## +#: ../src/guide/databases/db-migrations.md +#, no-wrap +msgid "Generating Migrations (TODO: likely is OK but...)" msgstr "" #. type: Plain text -#: ../../guide/en/databases/db-migrations.md -msgid "To work with migrations, you can use the provided [view](https://github.com/yiisoft/db-migration/tree/master/resources/views)." +#: ../src/guide/databases/db-migrations.md +msgid "The command provides a convenient way to create migrations using the provided [view](https://github.com/yiisoft/db-migration/tree/master/resources/views):" msgstr "" #. type: Fenced code block (shell) -#: ../../guide/en/databases/db-migrations.md +#: ../src/guide/databases/db-migrations.md #, no-wrap -msgid "./yii migrate:create my_first_table --command=table --fields=name,example --table-comment=my_first_table\n" +msgid "make yii migrate:create my_first_table --command=table --fields=name,example --table-comment=my_first_table\n" msgstr "" #. type: Plain text -#: ../../guide/en/databases/db-migrations.md +#: ../src/guide/databases/db-migrations.md msgid "That would generate the following:" msgstr "" #. type: Fenced code block (php) -#: ../../guide/en/databases/db-migrations.md +#: ../src/guide/databases/db-migrations.md #, no-wrap msgid "" " Tip: In case you don't have command line at your server you may try [web shell](https://github.com/samdark/yii2-webshell)\n" +"> extension.\n" +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +msgid "For each migration that has been successfully applied, the command will insert a row into a database table named `migration` to record the successful application of the migration. This will allow the migration tool to identify which migrations have been applied and which have not." +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +#, no-wrap +msgid "" +"> Info: The migration tool will automatically create the `migration` table in the database specified by\n" +"the [[yii\\console\\controllers\\MigrateController::db|db]] option of the command. By default, the database\n" +"is specified by the `db` [application component](structure-application-components.md).\n" +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +msgid "Sometimes, you may only want to apply one or a few new migrations, instead of all available migrations. You can do so by specifying the number of migrations that you want to apply when running the command. For example, the following command will try to apply the next three available migrations:" +msgstr "" + +#. type: Fenced code block +#: ../src/guide/databases/db-migrations.md +#, no-wrap +msgid "yii migrate 3\n" +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +msgid "You can also explicitly specify a particular migration to which the database should be migrated by using the `migrate/to` command in one of the following formats:" +msgstr "" + +#. type: Fenced code block +#: ../src/guide/databases/db-migrations.md +#, no-wrap +msgid "" +"yii migrate/to 150101_185401 # using timestamp to specify the migration\n" +"yii migrate/to \"2015-01-01 18:54:01\" # using a string that can be parsed by strtotime()\n" +"yii migrate/to m150101_185401_create_news_table # using full name\n" +"yii migrate/to 1392853618 # using UNIX timestamp\n" +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +msgid "If there are any unapplied migrations earlier than the specified one, they will all be applied before the specified migration is applied." +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +msgid "If the specified migration has already been applied before, any later applied migrations will be reverted." +msgstr "" + +#. type: Title ## +#: ../src/guide/databases/db-migrations.md +#, fuzzy, no-wrap +#| msgid "Resolving aliases " +msgid "Reverting Migrations " +msgstr "Me-resolve alias " + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +msgid "To revert (undo) one or multiple migrations that have been applied before, you can run the following command:" +msgstr "" + +#. type: Fenced code block +#: ../src/guide/databases/db-migrations.md +#, no-wrap +msgid "" +"yii migrate/down # revert the most recently applied migration\n" +"yii migrate/down 3 # revert the most 3 recently applied migrations\n" +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +#, no-wrap +msgid "" +"> Note: Not all migrations are reversible. Trying to revert such migrations will cause an error and stop the\n" +"entire reverting process.\n" +msgstr "" + +#. type: Title ## +#: ../src/guide/databases/db-migrations.md +#, fuzzy, no-wrap +#| msgid "Resolving aliases " +msgid "Redoing Migrations " +msgstr "Me-resolve alias " + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +msgid "Redoing migrations means first reverting the specified migrations and then applying again. This can be done as follows:" +msgstr "" + +#. type: Fenced code block +#: ../src/guide/databases/db-migrations.md +#, no-wrap +msgid "" +"yii migrate/redo # redo the last applied migration\n" +"yii migrate/redo 3 # redo the last 3 applied migrations\n" +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +#, no-wrap +msgid "> Note: If a migration is not reversible, you will not be able to redo it.\n" +msgstr "" + +#. type: Title ## +#: ../src/guide/databases/db-migrations.md +#, fuzzy, no-wrap +#| msgid "Resolving aliases " +msgid "Refreshing Migrations " +msgstr "Me-resolve alias " + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +msgid "Since Yii 2.0.13 you can delete all tables and foreign keys from the database and apply all migrations from the beginning." +msgstr "" + +#. type: Fenced code block +#: ../src/guide/databases/db-migrations.md +#, no-wrap +msgid "yii migrate/fresh # truncate the database and apply all migrations from the beginning\n" +msgstr "" + +#. type: Title ## +#: ../src/guide/databases/db-migrations.md +#, fuzzy, no-wrap +#| msgid "Using aliases in configuration " +msgid "Listing Migrations " +msgstr "Menggunakan aliases di konfigurasi " + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +msgid "To list which migrations have been applied and which are not, you may use the following commands:" +msgstr "" + +#. type: Fenced code block +#: ../src/guide/databases/db-migrations.md +#, no-wrap +msgid "" +"yii migrate/history # showing the last 10 applied migrations\n" +"yii migrate/history 5 # showing the last 5 applied migrations\n" +"yii migrate/history all # showing all applied migrations\n" +"\n" +"yii migrate/new # showing the first 10 new migrations\n" +"yii migrate/new 5 # showing the first 5 new migrations\n" +"yii migrate/new all # showing all new migrations\n" +msgstr "" + +#. type: Title ## +#: ../src/guide/databases/db-migrations.md +#, no-wrap +msgid "Modifying Migration History " +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +msgid "Instead of actually applying or reverting migrations, sometimes you may simply want to mark that your database has been upgraded to a particular migration. This often happens when you manually change the database to a particular state and you do not want the migration(s) for that change to be re-applied later. You can achieve this goal with the following command:" +msgstr "" + +#. type: Fenced code block +#: ../src/guide/databases/db-migrations.md +#, no-wrap +msgid "" +"yii migrate/mark 150101_185401 # using timestamp to specify the migration\n" +"yii migrate/mark \"2015-01-01 18:54:01\" # using a string that can be parsed by strtotime()\n" +"yii migrate/mark m150101_185401_create_news_table # using full name\n" +"yii migrate/mark 1392853618 # using UNIX timestamp\n" +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +msgid "The command will modify the `migration` table by adding or deleting certain rows to indicate that the database has been applied migrations to the specified one. No migrations will be applied or reverted by this command." +msgstr "" + +#. type: Title ## +#: ../src/guide/databases/db-migrations.md +#, fuzzy, no-wrap +#| msgid "Using aliases in configuration " +msgid "Customizing Migrations " +msgstr "Menggunakan aliases di konfigurasi " + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +msgid "There are several ways to customize the migration command." +msgstr "" + +#. type: Title ### +#: ../src/guide/databases/db-migrations.md +#, fuzzy, no-wrap +#| msgid "Using aliases in configuration " +msgid "Using Command Line Options " +msgstr "Menggunakan aliases di konfigurasi " + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +msgid "The migration command comes with a few command-line options that can be used to customize its behaviors:" +msgstr "" + +#. type: Bullet: '* ' +#: ../src/guide/databases/db-migrations.md +msgid "`interactive`: boolean (defaults to `true`), specifies whether to perform migrations in an interactive mode. When this is `true`, the user will be prompted before the command performs certain actions. You may want to set this to `false` if the command is being used in a background process." +msgstr "" + +#. type: Bullet: '* ' +#: ../src/guide/databases/db-migrations.md +msgid "`migrationPath`: string|array (defaults to `@app/migrations`), specifies the directory storing all migration class files. This can be specified as either a directory path or a path [alias](concept-aliases.md). Note that the directory must exist, or the command may trigger an error. Since version 2.0.12 an array can be specified for loading migrations from multiple sources." +msgstr "" + +#. type: Bullet: '* ' +#: ../src/guide/databases/db-migrations.md +msgid "`migrationTable`: string (defaults to `migration`), specifies the name of the database table for storing migration history information. The table will be automatically created by the command if it does not exist. You may also manually create it using the structure `version varchar(255) primary key, apply_time integer`." +msgstr "" + +#. type: Bullet: '* ' +#: ../src/guide/databases/db-migrations.md +msgid "`db`: string (defaults to `db`), specifies the ID of the database [application component](structure-application-components.md). It represents the database that will be migrated using this command." +msgstr "" + +#. type: Bullet: '* ' +#: ../src/guide/databases/db-migrations.md +msgid "`templateFile`: string (defaults to `@yii/views/migration.php`), specifies the path of the template file that is used for generating skeleton migration class files. This can be specified as either a file path or a path [alias](concept-aliases.md). The template file is a PHP script in which you can use a predefined variable named `$className` to get the migration class name." +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +#, no-wrap +msgid "" +"* `generatorTemplateFiles`: array (defaults to `[\n" +" 'create_table' => '@yii/views/createTableMigration.php',\n" +" 'drop_table' => '@yii/views/dropTableMigration.php',\n" +" 'add_column' => '@yii/views/addColumnMigration.php',\n" +" 'drop_column' => '@yii/views/dropColumnMigration.php',\n" +" 'create_junction' => '@yii/views/createTableMigration.php'\n" +" ]`), specifies template files for generating migration code. See \"[Generating Migrations](#generating-migrations)\"\n" +" for more details.\n" +msgstr "" + +#. type: Bullet: '* ' +#: ../src/guide/databases/db-migrations.md +msgid "`fields`: array of column definition strings used for creating migration code. Defaults to `[]`. The format of each definition is `COLUMN_NAME:COLUMN_TYPE:COLUMN_DECORATOR`. For example, `--fields=name:string(12):notNull` produces a string column of size 12 which is not `null`." +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +msgid "The following example shows how you can use these options." +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +msgid "For example, if we want to migrate a `forum` module whose migration files are located within the module's `migrations` directory, we can use the following command:" +msgstr "" + +#. type: Fenced code block +#: ../src/guide/databases/db-migrations.md +#, no-wrap +msgid "" +"# migrate the migrations in a forum module non-interactively\n" +"yii migrate --migrationPath=@app/modules/forum/migrations --interactive=0\n" +msgstr "" + +#. type: Title ### +#: ../src/guide/databases/db-migrations.md +#, no-wrap +msgid "Separated Migrations" +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +msgid "Sometimes using single migration history for all project migrations is not desirable. For example: you may install some 'blog' extension, which contains fully separated functionality and contain its own migrations, which should not affect the ones dedicated to main project functionality." +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +msgid "If you want several migrations to be applied and tracked down completely separated from each other, you can configure multiple migration commands which will use different namespaces and migration history tables:" +msgstr "" + +#. type: Fenced code block (php) +#: ../src/guide/databases/db-migrations.md +#, no-wrap +msgid "" +"return [\n" +" 'controllerMap' => [\n" +" // Common migrations for the whole application\n" +" 'migrate-app' => [\n" +" 'class' => 'yii\\console\\controllers\\MigrateController',\n" +" 'migrationNamespaces' => ['app\\migrations'],\n" +" 'migrationTable' => 'migration_app',\n" +" 'migrationPath' => null,\n" +" ],\n" +" // Migrations for the specific project's module\n" +" 'migrate-module' => [\n" +" 'class' => 'yii\\console\\controllers\\MigrateController',\n" +" 'migrationNamespaces' => ['module\\migrations'],\n" +" 'migrationTable' => 'migration_module',\n" +" 'migrationPath' => null,\n" +" ],\n" +" // Migrations for the specific extension\n" +" 'migrate-rbac' => [\n" +" 'class' => 'yii\\console\\controllers\\MigrateController',\n" +" 'migrationPath' => '@yii/rbac/migrations',\n" +" 'migrationTable' => 'migration_rbac',\n" +" ],\n" +" ],\n" +"];\n" +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +msgid "Note that to synchronize database you now need to run multiple commands instead of one:" +msgstr "" + +#. type: Fenced code block +#: ../src/guide/databases/db-migrations.md +#, no-wrap +msgid "" +"yii migrate-app\n" +"yii migrate-module\n" +"yii migrate-rbac\n" +msgstr "" + +#. type: Title ## +#: ../src/guide/databases/db-migrations.md +#, fuzzy, no-wrap +#| msgid "Defining aliases " +msgid "Migrating Multiple Databases " +msgstr "Defining aliases " + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +msgid "By default, migrations are applied to the same database specified by the `db` [application component](structure-application-components.md). If you want them to be applied to a different database, you may specify the `db` command-line option like shown below," +msgstr "" + +#. type: Fenced code block +#: ../src/guide/databases/db-migrations.md +#, no-wrap +msgid "yii migrate --db=db2\n" +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +msgid "The above command will apply migrations to the `db2` database." +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +msgid "Sometimes it may happen that you want to apply *some* of the migrations to one database, while some others to another database. To achieve this goal, when implementing a migration class you should explicitly specify the DB component ID that the migration would use, like the following:" +msgstr "" + +#. type: Fenced code block (php) +#: ../src/guide/databases/db-migrations.md +#, no-wrap +msgid "" +"db = 'db2';\n" +" parent::init();\n" +" }\n" +"}\n" +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +msgid "The above migration will be applied to `db2`, even if you specify a different database through the `db` command-line option. Note that the migration history will still be recorded in the database specified by the `db` command-line option." +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +msgid "If you have multiple migrations that use the same database, it is recommended that you create a base migration class with the above `init()` code. Then each migration class can extend from this base class." +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +#, no-wrap +msgid "" +"> Tip: Besides setting the [[yii\\db\\Migration::db|db]] property, you can also operate on different databases\n" +"by creating new database connections to them in your migration classes. You then use the [DAO methods](db-dao.md)\n" +"with these connections to manipulate different databases.\n" +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +msgid "Another strategy that you can take to migrate multiple databases is to keep migrations for different databases in different migration paths. Then you can migrate these databases in separate commands like the following:" +msgstr "" + +#. type: Fenced code block +#: ../src/guide/databases/db-migrations.md +#, no-wrap +msgid "" +"yii migrate --migrationPath=@app/migrations/db1 --db=db1\n" +"yii migrate --migrationPath=@app/migrations/db2 --db=db2\n" +"...\n" +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +msgid "The first command will apply migrations in `@app/migrations/db1` to the `db1` database, the second command will apply migrations in `@app/migrations/db2` to `db2`, and so on." +msgstr "" + #. type: Title ### -#: ../../guide/en/databases/db-migrations.md +#: ../src/guide/databases/db-migrations.md #, no-wrap msgid "Upgrading from Yii2" msgstr "" #. type: Plain text -#: ../../guide/en/databases/db-migrations.md +#: ../src/guide/databases/db-migrations.md msgid "Migrations in Yii2 and the [yiisoft/db-migration](https://github.com/yiisoft/db-migration/) package are not compatible, and the `migration` table is also not compatible. A probable solution is to use structure dumps and rename the old `migration` table. Upon the initial execution of migrations, a new `migration` table with new fields will be created. All further changes in the database schema are applied using the new `migration` component and recorded in the new migration table." msgstr "" diff --git a/_translations/po/id/guide_start_creating-project.md.po b/_translations/po/id/guide_start_creating-project.md.po index 35e11a50..d7e9a493 100644 --- a/_translations/po/id/guide_start_creating-project.md.po +++ b/_translations/po/id/guide_start_creating-project.md.po @@ -6,7 +6,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" -"POT-Creation-Date: 2025-12-24 13:00+0000\n" +"POT-Creation-Date: 2025-12-25 22:40+0000\n" "PO-Revision-Date: 2025-09-04 11:19+0500\n" "Last-Translator: Automatically generated\n" "Language-Team: none\n" @@ -32,7 +32,7 @@ msgstr "" msgid "" "> [!NOTE]\n" "> If you want to use another web server,\n" -"> see [\"Configuring web servers\"](../../../cookbook/en/configuring-webservers/general.md).\n" +"> see [\"Configuring web servers\"](../../cookbook/configuring-webservers/general.md).\n" msgstr "" #. type: Plain text @@ -53,13 +53,15 @@ msgstr "" #. type: Plain text #: ../src/guide/start/creating-project.md -msgid "Docker users can run the following command:" +msgid "Docker users can run the following commands:" msgstr "" #. type: Fenced code block (sh) #: ../src/guide/start/creating-project.md #, no-wrap -msgid "docker run --rm -it -v \"$(pwd):/app\" composer/composer create-project yiisoft/app your_project\n" +msgid "" +"docker run --rm -it -v \"$(pwd):/app\" composer/composer create-project yiisoft/app your_project\n" +"sudo chown -R $(id -u):$(id -g) your_project\n" msgstr "" #. type: Plain text diff --git a/_translations/po/id/guide_start_databases.md.po b/_translations/po/id/guide_start_databases.md.po index a8e888f8..867094fc 100644 --- a/_translations/po/id/guide_start_databases.md.po +++ b/_translations/po/id/guide_start_databases.md.po @@ -6,7 +6,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" -"POT-Creation-Date: 2025-12-24 13:00+0000\n" +"POT-Creation-Date: 2025-12-25 22:40+0000\n" "PO-Revision-Date: 2025-09-04 11:19+0500\n" "Last-Translator: Automatically generated\n" "Language-Team: none\n" @@ -15,6 +15,22 @@ msgstr "" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: 8bit\n" +#. type: Fenced code block (sh) +#: ../src/guide/databases/db-migrations.md ../src/guide/start/databases.md +#, fuzzy, no-wrap +msgid "make composer require yiisoft/db-migration\n" +msgstr "composer require yiisoft/cache\n" + +#. type: Fenced code block (php) +#: ../src/guide/databases/db-migrations.md ../src/guide/start/databases.md +#, no-wrap +msgid "" +"'yiisoft/db-migration' => [\n" +" 'newMigrationNamespace' => 'App\\\\Migration',\n" +" 'sourceNamespaces' => ['App\\\\Migration'],\n" +"],\n" +msgstr "" + #. type: Title # #: ../src/guide/index.md ../src/guide/start/databases.md #, no-wrap @@ -164,19 +180,14 @@ msgstr "" #. type: Plain text #: ../src/guide/start/databases.md -msgid "Let's use latest versions to be released. Change your `minimum-stability` to `dev` in `composer.json` first." -msgstr "" - -#. type: Plain text -#: ../src/guide/start/databases.md -msgid "Then we need a package to be installed:" +msgid "First we need a package to be installed:" msgstr "" #. type: Fenced code block (sh) #: ../src/guide/start/databases.md #, fuzzy, no-wrap #| msgid "composer require yiisoft/cache\n" -msgid "make composer require yiisoft/db-pgsql dev-master\n" +msgid "make composer require yiisoft/db-pgsql\n" msgstr "composer require yiisoft/cache\n" #. type: Plain text @@ -257,28 +268,11 @@ msgstr "" msgid "To use migrations we need another package installed:" msgstr "" -#. type: Fenced code block (sh) -#: ../src/guide/start/databases.md -#, fuzzy, no-wrap -#| msgid "composer require yiisoft/cache\n" -msgid "composer require yiisoft/db-migration dev-master\n" -msgstr "composer require yiisoft/cache\n" - #. type: Plain text #: ../src/guide/start/databases.md msgid "Create a directory to store migrations `src/Migration` right in the project root. Add the following configuration to `config/common/params.php`:" msgstr "" -#. type: Fenced code block (php) -#: ../src/guide/start/databases.md -#, no-wrap -msgid "" -"'yiisoft/db-migration' => [\n" -" 'newMigrationNamespace' => 'App\\\\Migration',\n" -" 'sourceNamespaces' => ['App\\\\Migration'],\n" -"],\n" -msgstr "" - #. type: Plain text #: ../src/guide/start/databases.md msgid "Now you can use `make yii migrate:create page` to create a new migration. For our example we need a `page` table with some columns:" @@ -297,9 +291,6 @@ msgid "" "use Yiisoft\\Db\\Migration\\MigrationBuilder;\n" "use Yiisoft\\Db\\Migration\\RevertibleMigrationInterface;\n" "\n" -"/**\n" -" * Class M251102141707Page\n" -" */\n" "final class M251102141707Page implements RevertibleMigrationInterface\n" "{\n" " public function up(MigrationBuilder $b): void\n" @@ -351,6 +342,8 @@ msgstr "" msgid "" "responseFactory->createResponse();\n" " $response->getBody()->write('The message is: ' . Html::encode($message));\n" @@ -225,7 +227,7 @@ msgid "To use the view, you need to change `src/Web/Echo/Action.php`:" msgstr "" #. type: Fenced code block (php) -#: ../src/guide/start/hello.md ../src/guide/views/view.md +#: ../src/guide/start/hello.md #, no-wrap msgid "" "viewRenderer->render(__DIR__ . '/template', [\n" " 'message' => $message,\n" diff --git a/_translations/po/id/guide_views_template-engines.md.po b/_translations/po/id/guide_views_template-engines.md.po index 9e12bd10..c0e7a835 100644 --- a/_translations/po/id/guide_views_template-engines.md.po +++ b/_translations/po/id/guide_views_template-engines.md.po @@ -6,7 +6,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" -"POT-Creation-Date: 2025-12-24 13:00+0000\n" +"POT-Creation-Date: 2025-12-25 22:40+0000\n" "PO-Revision-Date: 2025-12-24 08:02+0000\n" "Last-Translator: Automatically generated\n" "Language-Team: none\n" @@ -259,10 +259,12 @@ msgstr "" #: ../src/guide/views/template-engines.md #, no-wrap msgid "" +"use Yiisoft\\Container\\Reference;\n" +"\n" "// In configuration\n" "'yiisoft/view' => [\n" " 'renderers' => [\n" -" 'md' => App\\View\\MarkdownRenderer::class,\n" +" 'md' => Reference::to(App\\View\\MarkdownRenderer::class),\n" " ],\n" "],\n" msgstr "" @@ -286,7 +288,7 @@ msgid "" "\n" "Welcome, {{username}}!\n" "\n" -"This is a markdown template with **bold** and *italic* text.\n" +"This is a Markdown template with **bold** and *italic* text.\n" "\n" "- Feature 1\n" "- Feature 2\n" diff --git a/_translations/po/id/guide_views_view.md.po b/_translations/po/id/guide_views_view.md.po index 6bcaff6e..d10c9500 100644 --- a/_translations/po/id/guide_views_view.md.po +++ b/_translations/po/id/guide_views_view.md.po @@ -6,7 +6,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" -"POT-Creation-Date: 2025-12-24 13:00+0000\n" +"POT-Creation-Date: 2025-12-25 22:40+0000\n" "PO-Revision-Date: 2025-12-24 08:02+0000\n" "Last-Translator: Automatically generated\n" "Language-Team: none\n" @@ -43,36 +43,6 @@ msgid "" "

The message is:

\n" msgstr "" -#. type: Fenced code block (php) -#: ../src/guide/start/hello.md ../src/guide/views/view.md -#, no-wrap -msgid "" -"viewRenderer->render(__DIR__ . '/template', [\n" -" 'message' => $message,\n" -" ]);\n" -" }\n" -"}\n" -msgstr "" - #. type: Title ## #: ../src/guide/views/asset.md ../src/guide/views/view.md #: ../src/guide/views/widget.md @@ -139,6 +109,36 @@ msgstr "" msgid "Here `$message` is a view data that is passed when you render a template with the help of `ViewRenderer`. For example, `src/Web/Echo/Action.php`:" msgstr "" +#. type: Fenced code block (php) +#: ../src/guide/views/view.md +#, no-wrap +msgid "" +"viewRenderer->render(__DIR__ . '/template', [\n" +" 'message' => $message,\n" +" ]);\n" +" }\n" +"}\n" +msgstr "" + #. type: Plain text #: ../src/guide/views/view.md msgid "First argument of the `render()` method is a path to the template file. In the `yiisoft/app`, template files are typically stored alongside their actions. The result is ready to be rendered to the browser so we return it immediately." diff --git a/_translations/po/ru/guide_databases_db-migrations.md.po b/_translations/po/ru/guide_databases_db-migrations.md.po index 545975f2..1975e647 100644 --- a/_translations/po/ru/guide_databases_db-migrations.md.po +++ b/_translations/po/ru/guide_databases_db-migrations.md.po @@ -6,7 +6,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" -"POT-Creation-Date: 2025-11-03 12:48+0000\n" +"POT-Creation-Date: 2025-12-25 22:40+0000\n" "PO-Revision-Date: 2025-09-04 11:19+0500\n" "Last-Translator: Automatically generated\n" "Language-Team: none\n" @@ -17,110 +17,492 @@ msgstr "" "Plural-Forms: nplurals=3; plural=(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2);\n" #. type: Title # -#: ../../guide/en/databases/db-migrations.md +#: ../src/guide/databases/db-migrations.md #, no-wrap msgid "Migrations" msgstr "" #. type: Plain text -#: ../../guide/en/databases/db-migrations.md +#: ../src/guide/databases/db-migrations.md +msgid "During the course of developing and maintaining a database-driven application, the structure of the database being used evolves just like the source code does. For example, during the development of an application, a new table may be found necessary; after the application is deployed to production, it may be discovered that an index should be created to improve the query performance; and so on. Because a database structure change often requires some source code changes, Yii supports the so-called *database migration* feature that allows you to keep track of database changes in terms of *database migrations* which are version-controlled together with the source code." +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +msgid "The following steps show how database migration can be used by a team during development:" +msgstr "" + +#. type: Bullet: '1. ' +#: ../src/guide/databases/db-migrations.md +msgid "Tim creates a new migration (e.g. creates a new table, changes a column definition, etc.)." +msgstr "" + +#. type: Bullet: '2. ' +#: ../src/guide/databases/db-migrations.md +msgid "Tim commits the new migration into the source control system (e.g. Git, Mercurial)." +msgstr "" + +#. type: Bullet: '3. ' +#: ../src/guide/databases/db-migrations.md +msgid "Doug updates his repository from the source control system and receives the new migration." +msgstr "" + +#. type: Bullet: '4. ' +#: ../src/guide/databases/db-migrations.md +msgid "Doug applies the migration to his local development database, thereby synchronizing his database to reflect the changes that Tim has made." +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +msgid "And the following steps show how to deploy a new release with database migrations to production:" +msgstr "" + +#. type: Bullet: '1. ' +#: ../src/guide/databases/db-migrations.md +msgid "Scott creates a release tag for the project repository that contains some new database migrations." +msgstr "" + +#. type: Bullet: '2. ' +#: ../src/guide/databases/db-migrations.md +msgid "Scott updates the source code on the production server to the release tag." +msgstr "" + +#. type: Bullet: '3. ' +#: ../src/guide/databases/db-migrations.md +msgid "Scott applies any accumulated database migrations to the production database." +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +msgid "Yii provides a set of migration command line tools that allow you to:" +msgstr "" + +#. type: Bullet: '* ' +#: ../src/guide/databases/db-migrations.md +#, fuzzy +#| msgid "Sentry integration" +msgid "create new migrations;" +msgstr "Интеграция с Sentry" + +#. type: Bullet: '* ' +#: ../src/guide/databases/db-migrations.md +msgid "apply migrations;" +msgstr "" + +#. type: Bullet: '* ' +#: ../src/guide/databases/db-migrations.md +#, fuzzy +#| msgid "Sentry integration" +msgid "revert migrations;" +msgstr "Интеграция с Sentry" + +#. type: Bullet: '* ' +#: ../src/guide/databases/db-migrations.md +msgid "re-apply migrations;" +msgstr "" + +#. type: Bullet: '* ' +#: ../src/guide/databases/db-migrations.md +msgid "show migration history and status." +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +msgid "All these tools are accessible through the command `yii migrate`. In this section we will describe in detail how to accomplish various tasks using these tools." +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +#, no-wrap +msgid "" +"> [!TIP]\n" +"> Migrations could affect not only database schema but adjust existing data to fit new schema, create RBAC\n" +"hierarchy or clean up cache.\n" +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +#, no-wrap +msgid "" +"> [!NOTE]\n" +"> When manipulating data using a migration you may find that using your Active Record or entity classes\n" +"> for this might be useful because some of the logic is already implemented there. Keep in mind however, that in contrast\n" +"> to code written in the migrations, whose nature is to stay constant forever, application logic is subject to change.\n" +"> So when using Active Record or entity classes in migration code, changes to the logic in the source code\n" +"> may accidentally break the existing migrations. For this reason migration code should be kept independent of other\n" +"> application logic such.\n" +msgstr "" + +#. type: Title ## +#: ../src/guide/databases/db-migrations.md +#, fuzzy, no-wrap +msgid "Initial configuration" +msgstr "Безопасная конфигурация сервера" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md msgid "To use migrations, install [yiisoft/db-migration](https://github.com/yiisoft/db-migration/) package:" msgstr "" -#. type: Fenced code block (shell) -#: ../../guide/en/databases/db-migrations.md +#. type: Fenced code block (sh) +#: ../src/guide/databases/db-migrations.md ../src/guide/start/databases.md #, fuzzy, no-wrap -msgid "composer require yiisoft/db-migration\n" +msgid "make composer require yiisoft/db-migration\n" msgstr "composer install yiisoft/security\n" +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +msgid "Create a directory to store migrations `src/Migration` right in the project root." +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +#, fuzzy +#| msgid "Add the following to your php.ini:" +msgid "Add the following configuration to `config/common/params.php`:" +msgstr "Добавьте в свой php.ini следующее:" + +#. type: Fenced code block (php) +#: ../src/guide/databases/db-migrations.md ../src/guide/start/databases.md +#, no-wrap +msgid "" +"'yiisoft/db-migration' => [\n" +" 'newMigrationNamespace' => 'App\\\\Migration',\n" +" 'sourceNamespaces' => ['App\\\\Migration'],\n" +"],\n" +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +msgid "You need a database connection configured as well. See [Working with databases](../start/databases.md) for an example of configuring it for PostgreSQL." +msgstr "" + #. type: Title ### -#: ../../guide/en/databases/db-migrations.md +#: ../src/guide/databases/db-migrations.md +#, no-wrap +msgid "Creating a migration" +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +#, fuzzy +#| msgid "To install the packages, run the following command:" +msgid "To create a new empty migration, run the following command:" +msgstr "Для установки пакетов выполните в консоли следующую команду:" + +#. type: Fenced code block (sh) +#: ../src/guide/databases/db-migrations.md +#, no-wrap +msgid "make yii migrate:create \n" +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +msgid "The required `name` argument gives a brief description about the new migration. For example, if the migration is about creating a new table named *news*, you may use the name `create_news_table` and run the following command:" +msgstr "" + +#. type: Fenced code block +#: ../src/guide/databases/db-migrations.md #, no-wrap -msgid "Example usage" +msgid "make yii migrate:create create_news_table\n" msgstr "" #. type: Plain text -#: ../../guide/en/databases/db-migrations.md -msgid "First, configure a DI container. Create `config/common/db.php` with the following content:" +#: ../src/guide/databases/db-migrations.md +#, no-wrap +msgid "" +"> [!NOTE]\n" +"> Because the `name` argument will be used as part of the generated migration class name,\n" +"> it should only contain letters, digits, and/or underscore characters.\n" +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +msgid "The above command will create a new PHP class file named `src/Migration/M251225221906CreateNewsTable.php`. The file contains the following code which mainly declares a migration class with the skeleton code:" msgstr "" #. type: Fenced code block (php) -#: ../../guide/en/databases/db-migrations.md +#: ../src/guide/databases/db-migrations.md #, no-wrap msgid "" " [\n" -" 'class' => SqliteConnection::class,\n" -" '__construct()' => [\n" -" 'dsn' => 'sqlite:' . __DIR__ . '/Data/yiitest.sq3'\n" -" ]\n" -" ]\n" -"];\n" +"final class M251225221906CreateNewsTable implements RevertibleMigrationInterface\n" +"{\n" +" public function up(MigrationBuilder $b): void\n" +" {\n" +" // TODO: Implement the logic to apply the migration.\n" +" }\n" +"\n" +" public function down(MigrationBuilder $b): void\n" +" {\n" +" // TODO: Implement the logic to revert the migration.\n" +" }\n" +"}\n" msgstr "" #. type: Plain text -#: ../../guide/en/databases/db-migrations.md -#, fuzzy -#| msgid "Add the following to your php.ini:" -msgid "Add the following to `config/params.php`:" -msgstr "Добавьте в свой php.ini следующее:" +#: ../src/guide/databases/db-migrations.md +msgid "In the migration class, you are expected to write code in the `up()` method that makes changes to the database structure. You may also want to write code in the `down()` method to revert the changes made by `up()`. The `up()` method is invoked when you upgrade the database with this migration, while the `down()` method is invoked when you downgrade the database. The following code shows how you may implement the migration class to create a `news` table:" +msgstr "" #. type: Fenced code block (php) -#: ../../guide/en/databases/db-migrations.md +#: ../src/guide/databases/db-migrations.md #, no-wrap msgid "" -"...\n" -"'yiisoft/db-migration' => [\n" -" 'newMigrationNamespace' => 'App\\\\Migration',\n" -" 'sourceNamespaces' => ['App\\\\Migration'],\n" -"],\n" -"...\n" +"columnBuilder();\n" +"\n" +" $b->createTable('news', [\n" +" 'id' => $cb::uuidPrimaryKey(),\n" +" 'title' => $cb::string()->notNull(),\n" +" 'content' => $cb::text(),\n" +" ]);\n" +" }\n" +"\n" +" public function down(MigrationBuilder $b): void\n" +" {\n" +" $b->dropTable('news');\n" +" }\n" +"}\n" msgstr "" #. type: Plain text -#: ../../guide/en/databases/db-migrations.md -msgid "Now test if it works:" +#: ../src/guide/databases/db-migrations.md +#, no-wrap +msgid "" +"TODO: explain $b and $qb\n" +"Below is the list of all these database accessing methods:\n" msgstr "" -#. type: Fenced code block (shell) -#: ../../guide/en/databases/db-migrations.md +#. type: Title ### +#: ../src/guide/databases/db-migrations.md #, no-wrap -msgid "./yii list migrate\n" +msgid "Irreversible migrations" +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +msgid "Not all migrations are reversible. For example, if the `up()` method deletes a row of a table, you may not be able to recover this row in the `down()` method. Sometimes, you may be just too lazy to implement the `down()`, because it is not very common to revert database migrations. In this case, you should implement `Yiisoft\\Db\\Migration\\MigrationInterface` that has `up()` only." msgstr "" #. type: Title ### -#: ../../guide/en/databases/db-migrations.md +#: ../src/guide/databases/db-migrations.md #, no-wrap -msgid "Creating a migration" +msgid "Transactional migrations (TODO: update!!!)" +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +msgid "While performing complex DB migrations, it is important to ensure each migration to either succeed or fail as a whole so that the database can maintain integrity and consistency. To achieve this goal, it is recommended that you enclose the DB operations of each migration in a [transaction](db-dao.md#performing-transactions)." +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +msgid "An even easier way of implementing transactional migrations is to put migration code in the `safeUp()` and `safeDown()` methods. These two methods differ from `up()` and `down()` in that they are enclosed implicitly in a transaction. As a result, if any operation in these methods fails, all prior operations will be rolled back automatically." msgstr "" #. type: Plain text -#: ../../guide/en/databases/db-migrations.md -msgid "To work with migrations, you can use the provided [view](https://github.com/yiisoft/db-migration/tree/master/resources/views)." +#: ../src/guide/databases/db-migrations.md +msgid "In the following example, besides creating the `news` table we also insert an initial row into this table." +msgstr "" + +#. type: Fenced code block (php) +#: ../src/guide/databases/db-migrations.md +#, no-wrap +msgid "" +"createTable('news', [\n" +" 'id' => $this->primaryKey(),\n" +" 'title' => $this->string()->notNull(),\n" +" 'content' => $this->text(),\n" +" ]);\n" +"\n" +" $this->insert('news', [\n" +" 'title' => 'test 1',\n" +" 'content' => 'content 1',\n" +" ]);\n" +" }\n" +"\n" +" public function safeDown()\n" +" {\n" +" $this->delete('news', ['id' => 1]);\n" +" $this->dropTable('news');\n" +" }\n" +"}\n" +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +msgid "Note that usually when you perform multiple DB operations in `safeUp()`, you should reverse their execution order in `safeDown()`. In the above example we first create the table and then insert a row in `safeUp()`; while in `safeDown()` we first delete the row and then drop the table." +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +#, no-wrap +msgid "" +"> Note: Not all DBMS support transactions. And some DB queries cannot be put into a transaction. For some examples,\n" +"please refer to [implicit commit](https://dev.mysql.com/doc/refman/5.7/en/implicit-commit.html). If this is the case,\n" +"you should still implement `up()` and `down()`, instead.\n" +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +#, no-wrap +msgid "TODO: TransactionalMigrationInterface\n" +msgstr "" + +#. type: Title ## +#: ../src/guide/databases/db-migrations.md +#, no-wrap +msgid "TODO: update" +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +msgid "The base migration class [[yii\\db\\Migration]] exposes a database connection via the [[yii\\db\\Migration::db|db]] property. You can use it to manipulate the database schema using the methods as described in [Working with Database Schema](db-dao.md#database-schema)." +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +#, no-wrap +msgid "" +"Rather than using physical types, when creating a table or column you should use *abstract types*\n" +"so that your migrations are independent of specific DBMS. The [[yii\\db\\Schema]] class defines\n" +"a set of constants to represent the supported abstract types. These constants are named in the format\n" +"of `TYPE_`. For example, `TYPE_PK` refers to auto-incremental primary key type; `TYPE_STRING`\n" +"refers to a string type. When a migration is applied to a particular database, the abstract types\n" +"will be translated into the corresponding physical types. In the case of MySQL, `TYPE_PK` will be turned\n" +"into `int(11) NOT NULL AUTO_INCREMENT PRIMARY KEY`, while `TYPE_STRING` becomes `varchar(255)`.\n" +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +msgid "You can append additional constraints when using abstract types. In the above example, ` NOT NULL` is appended to `Schema::TYPE_STRING` to specify that the column cannot be `null`." +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +#, no-wrap +msgid "" +"> Info: The mapping between abstract types and physical types is specified by\n" +"the [[yii\\db\\QueryBuilder::$typeMap|$typeMap]] property in each concrete `QueryBuilder` class.\n" +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +msgid "Since version 2.0.6, you can make use of the newly introduced schema builder which provides more convenient way of defining column schema. So the migration above could be written like the following:" +msgstr "" + +#. type: Fenced code block (php) +#: ../src/guide/databases/db-migrations.md +#, no-wrap +msgid "" +"createTable('news', [\n" +" 'id' => $this->primaryKey(),\n" +" 'title' => $this->string()->notNull(),\n" +" 'content' => $this->text(),\n" +" ]);\n" +" }\n" +"\n" +" public function down()\n" +" {\n" +" $this->dropTable('news');\n" +" }\n" +"}\n" +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +msgid "A list of all available methods for defining the column types is available in the API documentation of [[yii\\db\\SchemaBuilderTrait]]." +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +#, no-wrap +msgid "" +"> Info: The generated file permissions and ownership will be determined by the current environment. This might lead to\n" +"inaccessible files. This could, for example, happen when the migration is created within a docker container\n" +"and the files are edited on the host. In this case the `newFileMode` and/or `newFileOwnership` of the MigrateController\n" +"can be changed. E.g. in the application config:\n" +msgstr "" + +#. type: Fenced code block (php) +#: ../src/guide/databases/db-migrations.md +#, no-wrap +msgid "" +" [\n" +" 'migrate' => [\n" +" 'class' => 'yii\\console\\controllers\\MigrateController',\n" +" 'newFileOwnership' => '1000:1000', # Default WSL user id\n" +" 'newFileMode' => 0660,\n" +" ],\n" +" ],\n" +" ];\n" +msgstr "" + +#. type: Title ## +#: ../src/guide/databases/db-migrations.md +#, no-wrap +msgid "Generating Migrations (TODO: likely is OK but...)" +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +msgid "The command provides a convenient way to create migrations using the provided [view](https://github.com/yiisoft/db-migration/tree/master/resources/views):" msgstr "" #. type: Fenced code block (shell) -#: ../../guide/en/databases/db-migrations.md +#: ../src/guide/databases/db-migrations.md #, no-wrap -msgid "./yii migrate:create my_first_table --command=table --fields=name,example --table-comment=my_first_table\n" +msgid "make yii migrate:create my_first_table --command=table --fields=name,example --table-comment=my_first_table\n" msgstr "" #. type: Plain text -#: ../../guide/en/databases/db-migrations.md +#: ../src/guide/databases/db-migrations.md #, fuzzy #| msgid "That's equal to the following:" msgid "That would generate the following:" msgstr "Это соответствует:" #. type: Fenced code block (php) -#: ../../guide/en/databases/db-migrations.md +#: ../src/guide/databases/db-migrations.md #, no-wrap msgid "" " Tip: In case you don't have command line at your server you may try [web shell](https://github.com/samdark/yii2-webshell)\n" +"> extension.\n" +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +msgid "For each migration that has been successfully applied, the command will insert a row into a database table named `migration` to record the successful application of the migration. This will allow the migration tool to identify which migrations have been applied and which have not." +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +#, no-wrap +msgid "" +"> Info: The migration tool will automatically create the `migration` table in the database specified by\n" +"the [[yii\\console\\controllers\\MigrateController::db|db]] option of the command. By default, the database\n" +"is specified by the `db` [application component](structure-application-components.md).\n" +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +msgid "Sometimes, you may only want to apply one or a few new migrations, instead of all available migrations. You can do so by specifying the number of migrations that you want to apply when running the command. For example, the following command will try to apply the next three available migrations:" +msgstr "" + +#. type: Fenced code block +#: ../src/guide/databases/db-migrations.md +#, no-wrap +msgid "yii migrate 3\n" +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +msgid "You can also explicitly specify a particular migration to which the database should be migrated by using the `migrate/to` command in one of the following formats:" +msgstr "" + +#. type: Fenced code block +#: ../src/guide/databases/db-migrations.md +#, no-wrap +msgid "" +"yii migrate/to 150101_185401 # using timestamp to specify the migration\n" +"yii migrate/to \"2015-01-01 18:54:01\" # using a string that can be parsed by strtotime()\n" +"yii migrate/to m150101_185401_create_news_table # using full name\n" +"yii migrate/to 1392853618 # using UNIX timestamp\n" +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +msgid "If there are any unapplied migrations earlier than the specified one, they will all be applied before the specified migration is applied." +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +msgid "If the specified migration has already been applied before, any later applied migrations will be reverted." +msgstr "" + +#. type: Title ## +#: ../src/guide/databases/db-migrations.md +#, fuzzy, no-wrap +#| msgid "Defining aliases " +msgid "Reverting Migrations " +msgstr "Определение псевдонимов " + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +msgid "To revert (undo) one or multiple migrations that have been applied before, you can run the following command:" +msgstr "" + +#. type: Fenced code block +#: ../src/guide/databases/db-migrations.md +#, no-wrap +msgid "" +"yii migrate/down # revert the most recently applied migration\n" +"yii migrate/down 3 # revert the most 3 recently applied migrations\n" +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +#, no-wrap +msgid "" +"> Note: Not all migrations are reversible. Trying to revert such migrations will cause an error and stop the\n" +"entire reverting process.\n" +msgstr "" + +#. type: Title ## +#: ../src/guide/databases/db-migrations.md +#, fuzzy, no-wrap +#| msgid "Resolving aliases " +msgid "Redoing Migrations " +msgstr "Разрешение псевдонимов " + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +msgid "Redoing migrations means first reverting the specified migrations and then applying again. This can be done as follows:" +msgstr "" + +#. type: Fenced code block +#: ../src/guide/databases/db-migrations.md +#, no-wrap +msgid "" +"yii migrate/redo # redo the last applied migration\n" +"yii migrate/redo 3 # redo the last 3 applied migrations\n" +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +#, no-wrap +msgid "> Note: If a migration is not reversible, you will not be able to redo it.\n" +msgstr "" + +#. type: Title ## +#: ../src/guide/databases/db-migrations.md +#, fuzzy, no-wrap +#| msgid "Resolving aliases " +msgid "Refreshing Migrations " +msgstr "Разрешение псевдонимов " + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +msgid "Since Yii 2.0.13 you can delete all tables and foreign keys from the database and apply all migrations from the beginning." +msgstr "" + +#. type: Fenced code block +#: ../src/guide/databases/db-migrations.md +#, no-wrap +msgid "yii migrate/fresh # truncate the database and apply all migrations from the beginning\n" +msgstr "" + +#. type: Title ## +#: ../src/guide/databases/db-migrations.md +#, fuzzy, no-wrap +#| msgid "Resolving aliases " +msgid "Listing Migrations " +msgstr "Разрешение псевдонимов " + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +msgid "To list which migrations have been applied and which are not, you may use the following commands:" +msgstr "" + +#. type: Fenced code block +#: ../src/guide/databases/db-migrations.md +#, no-wrap +msgid "" +"yii migrate/history # showing the last 10 applied migrations\n" +"yii migrate/history 5 # showing the last 5 applied migrations\n" +"yii migrate/history all # showing all applied migrations\n" +"\n" +"yii migrate/new # showing the first 10 new migrations\n" +"yii migrate/new 5 # showing the first 5 new migrations\n" +"yii migrate/new all # showing all new migrations\n" +msgstr "" + +#. type: Title ## +#: ../src/guide/databases/db-migrations.md +#, fuzzy, no-wrap +#| msgid "Resolving aliases " +msgid "Modifying Migration History " +msgstr "Разрешение псевдонимов " + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +msgid "Instead of actually applying or reverting migrations, sometimes you may simply want to mark that your database has been upgraded to a particular migration. This often happens when you manually change the database to a particular state and you do not want the migration(s) for that change to be re-applied later. You can achieve this goal with the following command:" +msgstr "" + +#. type: Fenced code block +#: ../src/guide/databases/db-migrations.md +#, no-wrap +msgid "" +"yii migrate/mark 150101_185401 # using timestamp to specify the migration\n" +"yii migrate/mark \"2015-01-01 18:54:01\" # using a string that can be parsed by strtotime()\n" +"yii migrate/mark m150101_185401_create_news_table # using full name\n" +"yii migrate/mark 1392853618 # using UNIX timestamp\n" +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +msgid "The command will modify the `migration` table by adding or deleting certain rows to indicate that the database has been applied migrations to the specified one. No migrations will be applied or reverted by this command." +msgstr "" + +#. type: Title ## +#: ../src/guide/databases/db-migrations.md +#, fuzzy, no-wrap +#| msgid "Resolving aliases " +msgid "Customizing Migrations " +msgstr "Разрешение псевдонимов " + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +msgid "There are several ways to customize the migration command." +msgstr "" + +#. type: Title ### +#: ../src/guide/databases/db-migrations.md +#, fuzzy, no-wrap +#| msgid "Resolving aliases " +msgid "Using Command Line Options " +msgstr "Разрешение псевдонимов " + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +msgid "The migration command comes with a few command-line options that can be used to customize its behaviors:" +msgstr "" + +#. type: Bullet: '* ' +#: ../src/guide/databases/db-migrations.md +msgid "`interactive`: boolean (defaults to `true`), specifies whether to perform migrations in an interactive mode. When this is `true`, the user will be prompted before the command performs certain actions. You may want to set this to `false` if the command is being used in a background process." +msgstr "" + +#. type: Bullet: '* ' +#: ../src/guide/databases/db-migrations.md +msgid "`migrationPath`: string|array (defaults to `@app/migrations`), specifies the directory storing all migration class files. This can be specified as either a directory path or a path [alias](concept-aliases.md). Note that the directory must exist, or the command may trigger an error. Since version 2.0.12 an array can be specified for loading migrations from multiple sources." +msgstr "" + +#. type: Bullet: '* ' +#: ../src/guide/databases/db-migrations.md +msgid "`migrationTable`: string (defaults to `migration`), specifies the name of the database table for storing migration history information. The table will be automatically created by the command if it does not exist. You may also manually create it using the structure `version varchar(255) primary key, apply_time integer`." +msgstr "" + +#. type: Bullet: '* ' +#: ../src/guide/databases/db-migrations.md +msgid "`db`: string (defaults to `db`), specifies the ID of the database [application component](structure-application-components.md). It represents the database that will be migrated using this command." +msgstr "" + +#. type: Bullet: '* ' +#: ../src/guide/databases/db-migrations.md +msgid "`templateFile`: string (defaults to `@yii/views/migration.php`), specifies the path of the template file that is used for generating skeleton migration class files. This can be specified as either a file path or a path [alias](concept-aliases.md). The template file is a PHP script in which you can use a predefined variable named `$className` to get the migration class name." +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +#, no-wrap +msgid "" +"* `generatorTemplateFiles`: array (defaults to `[\n" +" 'create_table' => '@yii/views/createTableMigration.php',\n" +" 'drop_table' => '@yii/views/dropTableMigration.php',\n" +" 'add_column' => '@yii/views/addColumnMigration.php',\n" +" 'drop_column' => '@yii/views/dropColumnMigration.php',\n" +" 'create_junction' => '@yii/views/createTableMigration.php'\n" +" ]`), specifies template files for generating migration code. See \"[Generating Migrations](#generating-migrations)\"\n" +" for more details.\n" +msgstr "" + +#. type: Bullet: '* ' +#: ../src/guide/databases/db-migrations.md +msgid "`fields`: array of column definition strings used for creating migration code. Defaults to `[]`. The format of each definition is `COLUMN_NAME:COLUMN_TYPE:COLUMN_DECORATOR`. For example, `--fields=name:string(12):notNull` produces a string column of size 12 which is not `null`." +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +msgid "The following example shows how you can use these options." +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +msgid "For example, if we want to migrate a `forum` module whose migration files are located within the module's `migrations` directory, we can use the following command:" +msgstr "" + +#. type: Fenced code block +#: ../src/guide/databases/db-migrations.md +#, no-wrap +msgid "" +"# migrate the migrations in a forum module non-interactively\n" +"yii migrate --migrationPath=@app/modules/forum/migrations --interactive=0\n" +msgstr "" + +#. type: Title ### +#: ../src/guide/databases/db-migrations.md +#, fuzzy, no-wrap +#| msgid "Sentry integration" +msgid "Separated Migrations" +msgstr "Интеграция с Sentry" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +msgid "Sometimes using single migration history for all project migrations is not desirable. For example: you may install some 'blog' extension, which contains fully separated functionality and contain its own migrations, which should not affect the ones dedicated to main project functionality." +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +msgid "If you want several migrations to be applied and tracked down completely separated from each other, you can configure multiple migration commands which will use different namespaces and migration history tables:" +msgstr "" + +#. type: Fenced code block (php) +#: ../src/guide/databases/db-migrations.md +#, no-wrap +msgid "" +"return [\n" +" 'controllerMap' => [\n" +" // Common migrations for the whole application\n" +" 'migrate-app' => [\n" +" 'class' => 'yii\\console\\controllers\\MigrateController',\n" +" 'migrationNamespaces' => ['app\\migrations'],\n" +" 'migrationTable' => 'migration_app',\n" +" 'migrationPath' => null,\n" +" ],\n" +" // Migrations for the specific project's module\n" +" 'migrate-module' => [\n" +" 'class' => 'yii\\console\\controllers\\MigrateController',\n" +" 'migrationNamespaces' => ['module\\migrations'],\n" +" 'migrationTable' => 'migration_module',\n" +" 'migrationPath' => null,\n" +" ],\n" +" // Migrations for the specific extension\n" +" 'migrate-rbac' => [\n" +" 'class' => 'yii\\console\\controllers\\MigrateController',\n" +" 'migrationPath' => '@yii/rbac/migrations',\n" +" 'migrationTable' => 'migration_rbac',\n" +" ],\n" +" ],\n" +"];\n" +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +msgid "Note that to synchronize database you now need to run multiple commands instead of one:" +msgstr "" + +#. type: Fenced code block +#: ../src/guide/databases/db-migrations.md +#, no-wrap +msgid "" +"yii migrate-app\n" +"yii migrate-module\n" +"yii migrate-rbac\n" +msgstr "" + +#. type: Title ## +#: ../src/guide/databases/db-migrations.md +#, fuzzy, no-wrap +#| msgid "Defining aliases " +msgid "Migrating Multiple Databases " +msgstr "Определение псевдонимов " + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +msgid "By default, migrations are applied to the same database specified by the `db` [application component](structure-application-components.md). If you want them to be applied to a different database, you may specify the `db` command-line option like shown below," +msgstr "" + +#. type: Fenced code block +#: ../src/guide/databases/db-migrations.md +#, no-wrap +msgid "yii migrate --db=db2\n" +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +msgid "The above command will apply migrations to the `db2` database." +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +msgid "Sometimes it may happen that you want to apply *some* of the migrations to one database, while some others to another database. To achieve this goal, when implementing a migration class you should explicitly specify the DB component ID that the migration would use, like the following:" +msgstr "" + +#. type: Fenced code block (php) +#: ../src/guide/databases/db-migrations.md +#, no-wrap +msgid "" +"db = 'db2';\n" +" parent::init();\n" +" }\n" +"}\n" +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +msgid "The above migration will be applied to `db2`, even if you specify a different database through the `db` command-line option. Note that the migration history will still be recorded in the database specified by the `db` command-line option." +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +msgid "If you have multiple migrations that use the same database, it is recommended that you create a base migration class with the above `init()` code. Then each migration class can extend from this base class." +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +#, no-wrap +msgid "" +"> Tip: Besides setting the [[yii\\db\\Migration::db|db]] property, you can also operate on different databases\n" +"by creating new database connections to them in your migration classes. You then use the [DAO methods](db-dao.md)\n" +"with these connections to manipulate different databases.\n" +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +msgid "Another strategy that you can take to migrate multiple databases is to keep migrations for different databases in different migration paths. Then you can migrate these databases in separate commands like the following:" +msgstr "" + +#. type: Fenced code block +#: ../src/guide/databases/db-migrations.md +#, no-wrap +msgid "" +"yii migrate --migrationPath=@app/migrations/db1 --db=db1\n" +"yii migrate --migrationPath=@app/migrations/db2 --db=db2\n" +"...\n" +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +msgid "The first command will apply migrations in `@app/migrations/db1` to the `db1` database, the second command will apply migrations in `@app/migrations/db2` to `db2`, and so on." +msgstr "" + #. type: Title ### -#: ../../guide/en/databases/db-migrations.md +#: ../src/guide/databases/db-migrations.md #, no-wrap msgid "Upgrading from Yii2" msgstr "" #. type: Plain text -#: ../../guide/en/databases/db-migrations.md +#: ../src/guide/databases/db-migrations.md msgid "Migrations in Yii2 and the [yiisoft/db-migration](https://github.com/yiisoft/db-migration/) package are not compatible, and the `migration` table is also not compatible. A probable solution is to use structure dumps and rename the old `migration` table. Upon the initial execution of migrations, a new `migration` table with new fields will be created. All further changes in the database schema are applied using the new `migration` component and recorded in the new migration table." msgstr "" diff --git a/_translations/po/ru/guide_start_creating-project.md.po b/_translations/po/ru/guide_start_creating-project.md.po index 36466500..46d89558 100644 --- a/_translations/po/ru/guide_start_creating-project.md.po +++ b/_translations/po/ru/guide_start_creating-project.md.po @@ -6,7 +6,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" -"POT-Creation-Date: 2025-12-24 13:00+0000\n" +"POT-Creation-Date: 2025-12-25 22:40+0000\n" "PO-Revision-Date: 2025-09-04 11:19+0500\n" "Last-Translator: Automatically generated\n" "Language-Team: none\n" @@ -33,7 +33,7 @@ msgstr "" msgid "" "> [!NOTE]\n" "> If you want to use another web server,\n" -"> see [\"Configuring web servers\"](../../../cookbook/en/configuring-webservers/general.md).\n" +"> see [\"Configuring web servers\"](../../cookbook/configuring-webservers/general.md).\n" msgstr "" #. type: Plain text @@ -54,13 +54,17 @@ msgstr "" #. type: Plain text #: ../src/guide/start/creating-project.md -msgid "Docker users can run the following command:" -msgstr "" +#, fuzzy +#| msgid "To install the packages, run the following command:" +msgid "Docker users can run the following commands:" +msgstr "Для установки пакетов выполните в консоли следующую команду:" #. type: Fenced code block (sh) #: ../src/guide/start/creating-project.md #, no-wrap -msgid "docker run --rm -it -v \"$(pwd):/app\" composer/composer create-project yiisoft/app your_project\n" +msgid "" +"docker run --rm -it -v \"$(pwd):/app\" composer/composer create-project yiisoft/app your_project\n" +"sudo chown -R $(id -u):$(id -g) your_project\n" msgstr "" #. type: Plain text diff --git a/_translations/po/ru/guide_start_databases.md.po b/_translations/po/ru/guide_start_databases.md.po index f9b3cd62..cdc0af9b 100644 --- a/_translations/po/ru/guide_start_databases.md.po +++ b/_translations/po/ru/guide_start_databases.md.po @@ -6,7 +6,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" -"POT-Creation-Date: 2025-12-24 13:00+0000\n" +"POT-Creation-Date: 2025-12-25 22:40+0000\n" "PO-Revision-Date: 2025-09-04 11:19+0500\n" "Last-Translator: Automatically generated\n" "Language-Team: none\n" @@ -16,6 +16,22 @@ msgstr "" "Content-Transfer-Encoding: 8bit\n" "Plural-Forms: nplurals=3; plural=(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2);\n" +#. type: Fenced code block (sh) +#: ../src/guide/databases/db-migrations.md ../src/guide/start/databases.md +#, fuzzy, no-wrap +msgid "make composer require yiisoft/db-migration\n" +msgstr "composer install yiisoft/security\n" + +#. type: Fenced code block (php) +#: ../src/guide/databases/db-migrations.md ../src/guide/start/databases.md +#, no-wrap +msgid "" +"'yiisoft/db-migration' => [\n" +" 'newMigrationNamespace' => 'App\\\\Migration',\n" +" 'sourceNamespaces' => ['App\\\\Migration'],\n" +"],\n" +msgstr "" + #. type: Title # #: ../src/guide/index.md ../src/guide/start/databases.md #, no-wrap @@ -168,19 +184,14 @@ msgstr "" #. type: Plain text #: ../src/guide/start/databases.md -msgid "Let's use latest versions to be released. Change your `minimum-stability` to `dev` in `composer.json` first." -msgstr "" - -#. type: Plain text -#: ../src/guide/start/databases.md -msgid "Then we need a package to be installed:" +msgid "First we need a package to be installed:" msgstr "" #. type: Fenced code block (sh) #: ../src/guide/start/databases.md #, fuzzy, no-wrap #| msgid "composer install yiisoft/security\n" -msgid "make composer require yiisoft/db-pgsql dev-master\n" +msgid "make composer require yiisoft/db-pgsql\n" msgstr "composer install yiisoft/security\n" #. type: Plain text @@ -261,27 +272,11 @@ msgstr "" msgid "To use migrations we need another package installed:" msgstr "" -#. type: Fenced code block (sh) -#: ../src/guide/start/databases.md -#, fuzzy, no-wrap -msgid "composer require yiisoft/db-migration dev-master\n" -msgstr "composer install yiisoft/security\n" - #. type: Plain text #: ../src/guide/start/databases.md msgid "Create a directory to store migrations `src/Migration` right in the project root. Add the following configuration to `config/common/params.php`:" msgstr "" -#. type: Fenced code block (php) -#: ../src/guide/start/databases.md -#, no-wrap -msgid "" -"'yiisoft/db-migration' => [\n" -" 'newMigrationNamespace' => 'App\\\\Migration',\n" -" 'sourceNamespaces' => ['App\\\\Migration'],\n" -"],\n" -msgstr "" - #. type: Plain text #: ../src/guide/start/databases.md msgid "Now you can use `make yii migrate:create page` to create a new migration. For our example we need a `page` table with some columns:" @@ -300,9 +295,6 @@ msgid "" "use Yiisoft\\Db\\Migration\\MigrationBuilder;\n" "use Yiisoft\\Db\\Migration\\RevertibleMigrationInterface;\n" "\n" -"/**\n" -" * Class M251102141707Page\n" -" */\n" "final class M251102141707Page implements RevertibleMigrationInterface\n" "{\n" " public function up(MigrationBuilder $b): void\n" @@ -354,6 +346,8 @@ msgstr "" msgid "" "responseFactory->createResponse();\n" " $response->getBody()->write('The message is: ' . Html::encode($message));\n" @@ -230,7 +232,7 @@ msgid "To use the view, you need to change `src/Web/Echo/Action.php`:" msgstr "" #. type: Fenced code block (php) -#: ../src/guide/start/hello.md ../src/guide/views/view.md +#: ../src/guide/start/hello.md #, no-wrap msgid "" "viewRenderer->render(__DIR__ . '/template', [\n" " 'message' => $message,\n" diff --git a/_translations/po/ru/guide_views_template-engines.md.po b/_translations/po/ru/guide_views_template-engines.md.po index 3d6ad8bd..7d1699aa 100644 --- a/_translations/po/ru/guide_views_template-engines.md.po +++ b/_translations/po/ru/guide_views_template-engines.md.po @@ -6,7 +6,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" -"POT-Creation-Date: 2025-12-24 13:00+0000\n" +"POT-Creation-Date: 2025-12-25 22:40+0000\n" "PO-Revision-Date: 2025-12-24 08:02+0000\n" "Last-Translator: Automatically generated\n" "Language-Team: none\n" @@ -260,10 +260,12 @@ msgstr "" #: ../src/guide/views/template-engines.md #, no-wrap msgid "" +"use Yiisoft\\Container\\Reference;\n" +"\n" "// In configuration\n" "'yiisoft/view' => [\n" " 'renderers' => [\n" -" 'md' => App\\View\\MarkdownRenderer::class,\n" +" 'md' => Reference::to(App\\View\\MarkdownRenderer::class),\n" " ],\n" "],\n" msgstr "" @@ -287,7 +289,7 @@ msgid "" "\n" "Welcome, {{username}}!\n" "\n" -"This is a markdown template with **bold** and *italic* text.\n" +"This is a Markdown template with **bold** and *italic* text.\n" "\n" "- Feature 1\n" "- Feature 2\n" diff --git a/_translations/po/ru/guide_views_view.md.po b/_translations/po/ru/guide_views_view.md.po index f24271fc..b62ddc17 100644 --- a/_translations/po/ru/guide_views_view.md.po +++ b/_translations/po/ru/guide_views_view.md.po @@ -6,7 +6,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" -"POT-Creation-Date: 2025-12-24 13:00+0000\n" +"POT-Creation-Date: 2025-12-25 22:40+0000\n" "PO-Revision-Date: 2025-12-24 08:02+0000\n" "Last-Translator: Automatically generated\n" "Language-Team: none\n" @@ -44,36 +44,6 @@ msgid "" "

The message is:

\n" msgstr "" -#. type: Fenced code block (php) -#: ../src/guide/start/hello.md ../src/guide/views/view.md -#, no-wrap -msgid "" -"viewRenderer->render(__DIR__ . '/template', [\n" -" 'message' => $message,\n" -" ]);\n" -" }\n" -"}\n" -msgstr "" - #. type: Title ## #: ../src/guide/views/asset.md ../src/guide/views/view.md #: ../src/guide/views/widget.md @@ -142,6 +112,36 @@ msgstr "" msgid "Here `$message` is a view data that is passed when you render a template with the help of `ViewRenderer`. For example, `src/Web/Echo/Action.php`:" msgstr "" +#. type: Fenced code block (php) +#: ../src/guide/views/view.md +#, no-wrap +msgid "" +"viewRenderer->render(__DIR__ . '/template', [\n" +" 'message' => $message,\n" +" ]);\n" +" }\n" +"}\n" +msgstr "" + #. type: Plain text #: ../src/guide/views/view.md msgid "First argument of the `render()` method is a path to the template file. In the `yiisoft/app`, template files are typically stored alongside their actions. The result is ready to be rendered to the browser so we return it immediately." diff --git a/_translations/pot/guide_databases_db-migrations.md.pot b/_translations/pot/guide_databases_db-migrations.md.pot index f2636331..dd361c58 100644 --- a/_translations/pot/guide_databases_db-migrations.md.pot +++ b/_translations/pot/guide_databases_db-migrations.md.pot @@ -7,7 +7,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" -"POT-Creation-Date: 2025-11-03 12:48+0000\n" +"POT-Creation-Date: 2025-12-25 22:40+0000\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -17,112 +17,569 @@ msgstr "" "Content-Transfer-Encoding: 8bit\n" #. type: Title # -#: ../../guide/en/databases/db-migrations.md +#: ../src/guide/databases/db-migrations.md #, no-wrap msgid "Migrations" msgstr "" #. type: Plain text -#: ../../guide/en/databases/db-migrations.md +#: ../src/guide/databases/db-migrations.md +msgid "" +"During the course of developing and maintaining a database-driven " +"application, the structure of the database being used evolves just like the " +"source code does. For example, during the development of an application, a " +"new table may be found necessary; after the application is deployed to " +"production, it may be discovered that an index should be created to improve " +"the query performance; and so on. Because a database structure change often " +"requires some source code changes, Yii supports the so-called *database " +"migration* feature that allows you to keep track of database changes in " +"terms of *database migrations* which are version-controlled together with " +"the source code." +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +msgid "" +"The following steps show how database migration can be used by a team during " +"development:" +msgstr "" + +#. type: Bullet: '1. ' +#: ../src/guide/databases/db-migrations.md +msgid "" +"Tim creates a new migration (e.g. creates a new table, changes a column " +"definition, etc.)." +msgstr "" + +#. type: Bullet: '2. ' +#: ../src/guide/databases/db-migrations.md +msgid "" +"Tim commits the new migration into the source control system (e.g. Git, " +"Mercurial)." +msgstr "" + +#. type: Bullet: '3. ' +#: ../src/guide/databases/db-migrations.md +msgid "" +"Doug updates his repository from the source control system and receives the " +"new migration." +msgstr "" + +#. type: Bullet: '4. ' +#: ../src/guide/databases/db-migrations.md +msgid "" +"Doug applies the migration to his local development database, thereby " +"synchronizing his database to reflect the changes that Tim has made." +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +msgid "" +"And the following steps show how to deploy a new release with database " +"migrations to production:" +msgstr "" + +#. type: Bullet: '1. ' +#: ../src/guide/databases/db-migrations.md +msgid "" +"Scott creates a release tag for the project repository that contains some " +"new database migrations." +msgstr "" + +#. type: Bullet: '2. ' +#: ../src/guide/databases/db-migrations.md +msgid "" +"Scott updates the source code on the production server to the release tag." +msgstr "" + +#. type: Bullet: '3. ' +#: ../src/guide/databases/db-migrations.md +msgid "" +"Scott applies any accumulated database migrations to the production database." +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +msgid "Yii provides a set of migration command line tools that allow you to:" +msgstr "" + +#. type: Bullet: '* ' +#: ../src/guide/databases/db-migrations.md +msgid "create new migrations;" +msgstr "" + +#. type: Bullet: '* ' +#: ../src/guide/databases/db-migrations.md +msgid "apply migrations;" +msgstr "" + +#. type: Bullet: '* ' +#: ../src/guide/databases/db-migrations.md +msgid "revert migrations;" +msgstr "" + +#. type: Bullet: '* ' +#: ../src/guide/databases/db-migrations.md +msgid "re-apply migrations;" +msgstr "" + +#. type: Bullet: '* ' +#: ../src/guide/databases/db-migrations.md +msgid "show migration history and status." +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +msgid "" +"All these tools are accessible through the command `yii migrate`. In this " +"section we will describe in detail how to accomplish various tasks using " +"these tools." +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +#, no-wrap +msgid "" +"> [!TIP]\n" +"> Migrations could affect not only database schema but adjust existing data to fit new schema, create RBAC\n" +"hierarchy or clean up cache.\n" +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +#, no-wrap +msgid "" +"> [!NOTE]\n" +"> When manipulating data using a migration you may find that using your Active Record or entity classes\n" +"> for this might be useful because some of the logic is already implemented there. Keep in mind however, that in contrast\n" +"> to code written in the migrations, whose nature is to stay constant forever, application logic is subject to change.\n" +"> So when using Active Record or entity classes in migration code, changes to the logic in the source code\n" +"> may accidentally break the existing migrations. For this reason migration code should be kept independent of other\n" +"> application logic such.\n" +msgstr "" + +#. type: Title ## +#: ../src/guide/databases/db-migrations.md +#, no-wrap +msgid "Initial configuration" +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md msgid "" "To use migrations, install [yiisoft/db-migration](https://github.com/yiisoft/" "db-migration/) package:" msgstr "" -#. type: Fenced code block (shell) -#: ../../guide/en/databases/db-migrations.md +#. type: Fenced code block (sh) +#: ../src/guide/databases/db-migrations.md ../src/guide/start/databases.md +#, no-wrap +msgid "make composer require yiisoft/db-migration\n" +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +msgid "" +"Create a directory to store migrations `src/Migration` right in the project " +"root." +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +msgid "Add the following configuration to `config/common/params.php`:" +msgstr "" + +#. type: Fenced code block (php) +#: ../src/guide/databases/db-migrations.md ../src/guide/start/databases.md #, no-wrap -msgid "composer require yiisoft/db-migration\n" +msgid "" +"'yiisoft/db-migration' => [\n" +" 'newMigrationNamespace' => 'App\\\\Migration',\n" +" 'sourceNamespaces' => ['App\\\\Migration'],\n" +"],\n" +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +msgid "" +"You need a database connection configured as well. See [Working with " +"databases](../start/databases.md) for an example of configuring it for " +"PostgreSQL." msgstr "" #. type: Title ### -#: ../../guide/en/databases/db-migrations.md +#: ../src/guide/databases/db-migrations.md +#, no-wrap +msgid "Creating a migration" +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +msgid "To create a new empty migration, run the following command:" +msgstr "" + +#. type: Fenced code block (sh) +#: ../src/guide/databases/db-migrations.md #, no-wrap -msgid "Example usage" +msgid "make yii migrate:create \n" msgstr "" #. type: Plain text -#: ../../guide/en/databases/db-migrations.md +#: ../src/guide/databases/db-migrations.md msgid "" -"First, configure a DI container. Create `config/common/db.php` with the " -"following content:" +"The required `name` argument gives a brief description about the new " +"migration. For example, if the migration is about creating a new table named " +"*news*, you may use the name `create_news_table` and run the following " +"command:" +msgstr "" + +#. type: Fenced code block +#: ../src/guide/databases/db-migrations.md +#, no-wrap +msgid "make yii migrate:create create_news_table\n" +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +#, no-wrap +msgid "" +"> [!NOTE]\n" +"> Because the `name` argument will be used as part of the generated migration class name,\n" +"> it should only contain letters, digits, and/or underscore characters.\n" +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +msgid "" +"The above command will create a new PHP class file named `src/Migration/" +"M251225221906CreateNewsTable.php`. The file contains the following code " +"which mainly declares a migration class with the skeleton code:" msgstr "" #. type: Fenced code block (php) -#: ../../guide/en/databases/db-migrations.md +#: ../src/guide/databases/db-migrations.md #, no-wrap msgid "" " [\n" -" 'class' => SqliteConnection::class,\n" -" '__construct()' => [\n" -" 'dsn' => 'sqlite:' . __DIR__ . '/Data/yiitest.sq3'\n" -" ]\n" -" ]\n" -"];\n" +"use Yiisoft\\Db\\Migration\\MigrationBuilder;\n" +"use Yiisoft\\Db\\Migration\\RevertibleMigrationInterface;\n" +"\n" +"final class M251225221906CreateNewsTable implements RevertibleMigrationInterface\n" +"{\n" +" public function up(MigrationBuilder $b): void\n" +" {\n" +" // TODO: Implement the logic to apply the migration.\n" +" }\n" +"\n" +" public function down(MigrationBuilder $b): void\n" +" {\n" +" // TODO: Implement the logic to revert the migration.\n" +" }\n" +"}\n" msgstr "" #. type: Plain text -#: ../../guide/en/databases/db-migrations.md -msgid "Add the following to `config/params.php`:" +#: ../src/guide/databases/db-migrations.md +msgid "" +"In the migration class, you are expected to write code in the `up()` method " +"that makes changes to the database structure. You may also want to write " +"code in the `down()` method to revert the changes made by `up()`. The `up()` " +"method is invoked when you upgrade the database with this migration, while " +"the `down()` method is invoked when you downgrade the database. The " +"following code shows how you may implement the migration class to create a " +"`news` table:" msgstr "" #. type: Fenced code block (php) -#: ../../guide/en/databases/db-migrations.md +#: ../src/guide/databases/db-migrations.md #, no-wrap msgid "" -"...\n" -"'yiisoft/db-migration' => [\n" -" 'newMigrationNamespace' => 'App\\\\Migration',\n" -" 'sourceNamespaces' => ['App\\\\Migration'],\n" -"],\n" -"...\n" +"columnBuilder();\n" +"\n" +" $b->createTable('news', [\n" +" 'id' => $cb::uuidPrimaryKey(),\n" +" 'title' => $cb::string()->notNull(),\n" +" 'content' => $cb::text(),\n" +" ]);\n" +" }\n" +"\n" +" public function down(MigrationBuilder $b): void\n" +" {\n" +" $b->dropTable('news');\n" +" }\n" +"}\n" msgstr "" #. type: Plain text -#: ../../guide/en/databases/db-migrations.md -msgid "Now test if it works:" +#: ../src/guide/databases/db-migrations.md +#, no-wrap +msgid "" +"TODO: explain $b and $qb\n" +"Below is the list of all these database accessing methods:\n" msgstr "" -#. type: Fenced code block (shell) -#: ../../guide/en/databases/db-migrations.md +#. type: Title ### +#: ../src/guide/databases/db-migrations.md #, no-wrap -msgid "./yii list migrate\n" +msgid "Irreversible migrations" +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +msgid "" +"Not all migrations are reversible. For example, if the `up()` method deletes " +"a row of a table, you may not be able to recover this row in the `down()` " +"method. Sometimes, you may be just too lazy to implement the `down()`, " +"because it is not very common to revert database migrations. In this case, " +"you should implement `Yiisoft\\Db\\Migration\\MigrationInterface` that has " +"`up()` only." msgstr "" #. type: Title ### -#: ../../guide/en/databases/db-migrations.md +#: ../src/guide/databases/db-migrations.md #, no-wrap -msgid "Creating a migration" +msgid "Transactional migrations (TODO: update!!!)" +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +msgid "" +"While performing complex DB migrations, it is important to ensure each " +"migration to either succeed or fail as a whole so that the database can " +"maintain integrity and consistency. To achieve this goal, it is recommended " +"that you enclose the DB operations of each migration in a [transaction](db-" +"dao.md#performing-transactions)." +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +msgid "" +"An even easier way of implementing transactional migrations is to put " +"migration code in the `safeUp()` and `safeDown()` methods. These two methods " +"differ from `up()` and `down()` in that they are enclosed implicitly in a " +"transaction. As a result, if any operation in these methods fails, all " +"prior operations will be rolled back automatically." +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +msgid "" +"In the following example, besides creating the `news` table we also insert " +"an initial row into this table." +msgstr "" + +#. type: Fenced code block (php) +#: ../src/guide/databases/db-migrations.md +#, no-wrap +msgid "" +"createTable('news', [\n" +" 'id' => $this->primaryKey(),\n" +" 'title' => $this->string()->notNull(),\n" +" 'content' => $this->text(),\n" +" ]);\n" +"\n" +" $this->insert('news', [\n" +" 'title' => 'test 1',\n" +" 'content' => 'content 1',\n" +" ]);\n" +" }\n" +"\n" +" public function safeDown()\n" +" {\n" +" $this->delete('news', ['id' => 1]);\n" +" $this->dropTable('news');\n" +" }\n" +"}\n" +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +msgid "" +"Note that usually when you perform multiple DB operations in `safeUp()`, you " +"should reverse their execution order in `safeDown()`. In the above example " +"we first create the table and then insert a row in `safeUp()`; while in " +"`safeDown()` we first delete the row and then drop the table." +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +#, no-wrap +msgid "" +"> Note: Not all DBMS support transactions. And some DB queries cannot be put into a transaction. For some examples,\n" +"please refer to [implicit commit](https://dev.mysql.com/doc/refman/5.7/en/implicit-commit.html). If this is the case,\n" +"you should still implement `up()` and `down()`, instead.\n" +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +#, no-wrap +msgid "TODO: TransactionalMigrationInterface\n" +msgstr "" + +#. type: Title ## +#: ../src/guide/databases/db-migrations.md +#, no-wrap +msgid "TODO: update" +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +msgid "" +"The base migration class [[yii\\db\\Migration]] exposes a database " +"connection via the [[yii\\db\\Migration::db|db]] property. You can use it to " +"manipulate the database schema using the methods as described in [Working " +"with Database Schema](db-dao.md#database-schema)." +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +#, no-wrap +msgid "" +"Rather than using physical types, when creating a table or column you should use *abstract types*\n" +"so that your migrations are independent of specific DBMS. The [[yii\\db\\Schema]] class defines\n" +"a set of constants to represent the supported abstract types. These constants are named in the format\n" +"of `TYPE_`. For example, `TYPE_PK` refers to auto-incremental primary key type; `TYPE_STRING`\n" +"refers to a string type. When a migration is applied to a particular database, the abstract types\n" +"will be translated into the corresponding physical types. In the case of MySQL, `TYPE_PK` will be turned\n" +"into `int(11) NOT NULL AUTO_INCREMENT PRIMARY KEY`, while `TYPE_STRING` becomes `varchar(255)`.\n" +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +msgid "" +"You can append additional constraints when using abstract types. In the " +"above example, ` NOT NULL` is appended to `Schema::TYPE_STRING` to specify " +"that the column cannot be `null`." +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +#, no-wrap +msgid "" +"> Info: The mapping between abstract types and physical types is specified by\n" +"the [[yii\\db\\QueryBuilder::$typeMap|$typeMap]] property in each concrete `QueryBuilder` class.\n" +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +msgid "" +"Since version 2.0.6, you can make use of the newly introduced schema builder " +"which provides more convenient way of defining column schema. So the " +"migration above could be written like the following:" +msgstr "" + +#. type: Fenced code block (php) +#: ../src/guide/databases/db-migrations.md +#, no-wrap +msgid "" +"createTable('news', [\n" +" 'id' => $this->primaryKey(),\n" +" 'title' => $this->string()->notNull(),\n" +" 'content' => $this->text(),\n" +" ]);\n" +" }\n" +"\n" +" public function down()\n" +" {\n" +" $this->dropTable('news');\n" +" }\n" +"}\n" +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +msgid "" +"A list of all available methods for defining the column types is available " +"in the API documentation of [[yii\\db\\SchemaBuilderTrait]]." +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +#, no-wrap +msgid "" +"> Info: The generated file permissions and ownership will be determined by the current environment. This might lead to\n" +"inaccessible files. This could, for example, happen when the migration is created within a docker container\n" +"and the files are edited on the host. In this case the `newFileMode` and/or `newFileOwnership` of the MigrateController\n" +"can be changed. E.g. in the application config:\n" +msgstr "" + +#. type: Fenced code block (php) +#: ../src/guide/databases/db-migrations.md +#, no-wrap +msgid "" +" [\n" +" 'migrate' => [\n" +" 'class' => 'yii\\console\\controllers\\MigrateController',\n" +" 'newFileOwnership' => '1000:1000', # Default WSL user id\n" +" 'newFileMode' => 0660,\n" +" ],\n" +" ],\n" +" ];\n" +msgstr "" + +#. type: Title ## +#: ../src/guide/databases/db-migrations.md +#, no-wrap +msgid "Generating Migrations (TODO: likely is OK but...)" msgstr "" #. type: Plain text -#: ../../guide/en/databases/db-migrations.md +#: ../src/guide/databases/db-migrations.md msgid "" -"To work with migrations, you can use the provided [view](https://github.com/" -"yiisoft/db-migration/tree/master/resources/views)." +"The command provides a convenient way to create migrations using the " +"provided [view](https://github.com/yiisoft/db-migration/tree/master/" +"resources/views):" msgstr "" #. type: Fenced code block (shell) -#: ../../guide/en/databases/db-migrations.md +#: ../src/guide/databases/db-migrations.md #, no-wrap -msgid "./yii migrate:create my_first_table --command=table --fields=name,example --table-comment=my_first_table\n" +msgid "make yii migrate:create my_first_table --command=table --fields=name,example --table-comment=my_first_table\n" msgstr "" #. type: Plain text -#: ../../guide/en/databases/db-migrations.md +#: ../src/guide/databases/db-migrations.md msgid "That would generate the following:" msgstr "" #. type: Fenced code block (php) -#: ../../guide/en/databases/db-migrations.md +#: ../src/guide/databases/db-migrations.md #, no-wrap msgid "" " Tip: In case you don't have command line at your server you may try [web shell](https://github.com/samdark/yii2-webshell)\n" +"> extension.\n" +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +msgid "" +"For each migration that has been successfully applied, the command will " +"insert a row into a database table named `migration` to record the " +"successful application of the migration. This will allow the migration tool " +"to identify which migrations have been applied and which have not." +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +#, no-wrap +msgid "" +"> Info: The migration tool will automatically create the `migration` table in the database specified by\n" +"the [[yii\\console\\controllers\\MigrateController::db|db]] option of the command. By default, the database\n" +"is specified by the `db` [application component](structure-application-components.md).\n" +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +msgid "" +"Sometimes, you may only want to apply one or a few new migrations, instead " +"of all available migrations. You can do so by specifying the number of " +"migrations that you want to apply when running the command. For example, " +"the following command will try to apply the next three available migrations:" +msgstr "" + +#. type: Fenced code block +#: ../src/guide/databases/db-migrations.md +#, no-wrap +msgid "yii migrate 3\n" +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +msgid "" +"You can also explicitly specify a particular migration to which the database " +"should be migrated by using the `migrate/to` command in one of the following " +"formats:" +msgstr "" + +#. type: Fenced code block +#: ../src/guide/databases/db-migrations.md +#, no-wrap +msgid "" +"yii migrate/to 150101_185401 # using timestamp to specify the migration\n" +"yii migrate/to \"2015-01-01 18:54:01\" # using a string that can be parsed by strtotime()\n" +"yii migrate/to m150101_185401_create_news_table # using full name\n" +"yii migrate/to 1392853618 # using UNIX timestamp\n" +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +msgid "" +"If there are any unapplied migrations earlier than the specified one, they " +"will all be applied before the specified migration is applied." +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +msgid "" +"If the specified migration has already been applied before, any later " +"applied migrations will be reverted." +msgstr "" + +#. type: Title ## +#: ../src/guide/databases/db-migrations.md +#, no-wrap +msgid "Reverting Migrations " +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +msgid "" +"To revert (undo) one or multiple migrations that have been applied before, " +"you can run the following command:" +msgstr "" + +#. type: Fenced code block +#: ../src/guide/databases/db-migrations.md +#, no-wrap +msgid "" +"yii migrate/down # revert the most recently applied migration\n" +"yii migrate/down 3 # revert the most 3 recently applied migrations\n" +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +#, no-wrap +msgid "" +"> Note: Not all migrations are reversible. Trying to revert such migrations will cause an error and stop the\n" +"entire reverting process.\n" +msgstr "" + +#. type: Title ## +#: ../src/guide/databases/db-migrations.md +#, no-wrap +msgid "Redoing Migrations " +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +msgid "" +"Redoing migrations means first reverting the specified migrations and then " +"applying again. This can be done as follows:" +msgstr "" + +#. type: Fenced code block +#: ../src/guide/databases/db-migrations.md +#, no-wrap +msgid "" +"yii migrate/redo # redo the last applied migration\n" +"yii migrate/redo 3 # redo the last 3 applied migrations\n" +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +#, no-wrap +msgid "> Note: If a migration is not reversible, you will not be able to redo it.\n" +msgstr "" + +#. type: Title ## +#: ../src/guide/databases/db-migrations.md +#, no-wrap +msgid "Refreshing Migrations " +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +msgid "" +"Since Yii 2.0.13 you can delete all tables and foreign keys from the " +"database and apply all migrations from the beginning." +msgstr "" + +#. type: Fenced code block +#: ../src/guide/databases/db-migrations.md +#, no-wrap +msgid "yii migrate/fresh # truncate the database and apply all migrations from the beginning\n" +msgstr "" + +#. type: Title ## +#: ../src/guide/databases/db-migrations.md +#, no-wrap +msgid "Listing Migrations " +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +msgid "" +"To list which migrations have been applied and which are not, you may use " +"the following commands:" +msgstr "" + +#. type: Fenced code block +#: ../src/guide/databases/db-migrations.md +#, no-wrap +msgid "" +"yii migrate/history # showing the last 10 applied migrations\n" +"yii migrate/history 5 # showing the last 5 applied migrations\n" +"yii migrate/history all # showing all applied migrations\n" +"\n" +"yii migrate/new # showing the first 10 new migrations\n" +"yii migrate/new 5 # showing the first 5 new migrations\n" +"yii migrate/new all # showing all new migrations\n" +msgstr "" + +#. type: Title ## +#: ../src/guide/databases/db-migrations.md +#, no-wrap +msgid "Modifying Migration History " +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +msgid "" +"Instead of actually applying or reverting migrations, sometimes you may " +"simply want to mark that your database has been upgraded to a particular " +"migration. This often happens when you manually change the database to a " +"particular state and you do not want the migration(s) for that change to be " +"re-applied later. You can achieve this goal with the following command:" +msgstr "" + +#. type: Fenced code block +#: ../src/guide/databases/db-migrations.md +#, no-wrap +msgid "" +"yii migrate/mark 150101_185401 # using timestamp to specify the migration\n" +"yii migrate/mark \"2015-01-01 18:54:01\" # using a string that can be parsed by strtotime()\n" +"yii migrate/mark m150101_185401_create_news_table # using full name\n" +"yii migrate/mark 1392853618 # using UNIX timestamp\n" +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +msgid "" +"The command will modify the `migration` table by adding or deleting certain " +"rows to indicate that the database has been applied migrations to the " +"specified one. No migrations will be applied or reverted by this command." +msgstr "" + +#. type: Title ## +#: ../src/guide/databases/db-migrations.md +#, no-wrap +msgid "Customizing Migrations " +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +msgid "There are several ways to customize the migration command." +msgstr "" + +#. type: Title ### +#: ../src/guide/databases/db-migrations.md +#, no-wrap +msgid "Using Command Line Options " +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +msgid "" +"The migration command comes with a few command-line options that can be used " +"to customize its behaviors:" +msgstr "" + +#. type: Bullet: '* ' +#: ../src/guide/databases/db-migrations.md +msgid "" +"`interactive`: boolean (defaults to `true`), specifies whether to perform " +"migrations in an interactive mode. When this is `true`, the user will be " +"prompted before the command performs certain actions. You may want to set " +"this to `false` if the command is being used in a background process." +msgstr "" + +#. type: Bullet: '* ' +#: ../src/guide/databases/db-migrations.md +msgid "" +"`migrationPath`: string|array (defaults to `@app/migrations`), specifies the " +"directory storing all migration class files. This can be specified as either " +"a directory path or a path [alias](concept-aliases.md). Note that the " +"directory must exist, or the command may trigger an error. Since version " +"2.0.12 an array can be specified for loading migrations from multiple " +"sources." +msgstr "" + +#. type: Bullet: '* ' +#: ../src/guide/databases/db-migrations.md +msgid "" +"`migrationTable`: string (defaults to `migration`), specifies the name of " +"the database table for storing migration history information. The table will " +"be automatically created by the command if it does not exist. You may also " +"manually create it using the structure `version varchar(255) primary key, " +"apply_time integer`." +msgstr "" + +#. type: Bullet: '* ' +#: ../src/guide/databases/db-migrations.md +msgid "" +"`db`: string (defaults to `db`), specifies the ID of the database " +"[application component](structure-application-components.md). It represents " +"the database that will be migrated using this command." +msgstr "" + +#. type: Bullet: '* ' +#: ../src/guide/databases/db-migrations.md +msgid "" +"`templateFile`: string (defaults to `@yii/views/migration.php`), specifies " +"the path of the template file that is used for generating skeleton migration " +"class files. This can be specified as either a file path or a path [alias]" +"(concept-aliases.md). The template file is a PHP script in which you can use " +"a predefined variable named `$className` to get the migration class name." +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +#, no-wrap +msgid "" +"* `generatorTemplateFiles`: array (defaults to `[\n" +" 'create_table' => '@yii/views/createTableMigration.php',\n" +" 'drop_table' => '@yii/views/dropTableMigration.php',\n" +" 'add_column' => '@yii/views/addColumnMigration.php',\n" +" 'drop_column' => '@yii/views/dropColumnMigration.php',\n" +" 'create_junction' => '@yii/views/createTableMigration.php'\n" +" ]`), specifies template files for generating migration code. See \"[Generating Migrations](#generating-migrations)\"\n" +" for more details.\n" +msgstr "" + +#. type: Bullet: '* ' +#: ../src/guide/databases/db-migrations.md +msgid "" +"`fields`: array of column definition strings used for creating migration " +"code. Defaults to `[]`. The format of each definition is `COLUMN_NAME:" +"COLUMN_TYPE:COLUMN_DECORATOR`. For example, `--fields=name:string(12):" +"notNull` produces a string column of size 12 which is not `null`." +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +msgid "The following example shows how you can use these options." +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +msgid "" +"For example, if we want to migrate a `forum` module whose migration files " +"are located within the module's `migrations` directory, we can use the " +"following command:" +msgstr "" + +#. type: Fenced code block +#: ../src/guide/databases/db-migrations.md +#, no-wrap +msgid "" +"# migrate the migrations in a forum module non-interactively\n" +"yii migrate --migrationPath=@app/modules/forum/migrations --interactive=0\n" +msgstr "" + +#. type: Title ### +#: ../src/guide/databases/db-migrations.md +#, no-wrap +msgid "Separated Migrations" +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +msgid "" +"Sometimes using single migration history for all project migrations is not " +"desirable. For example: you may install some 'blog' extension, which " +"contains fully separated functionality and contain its own migrations, which " +"should not affect the ones dedicated to main project functionality." +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +msgid "" +"If you want several migrations to be applied and tracked down completely " +"separated from each other, you can configure multiple migration commands " +"which will use different namespaces and migration history tables:" +msgstr "" + +#. type: Fenced code block (php) +#: ../src/guide/databases/db-migrations.md +#, no-wrap +msgid "" +"return [\n" +" 'controllerMap' => [\n" +" // Common migrations for the whole application\n" +" 'migrate-app' => [\n" +" 'class' => 'yii\\console\\controllers\\MigrateController',\n" +" 'migrationNamespaces' => ['app\\migrations'],\n" +" 'migrationTable' => 'migration_app',\n" +" 'migrationPath' => null,\n" +" ],\n" +" // Migrations for the specific project's module\n" +" 'migrate-module' => [\n" +" 'class' => 'yii\\console\\controllers\\MigrateController',\n" +" 'migrationNamespaces' => ['module\\migrations'],\n" +" 'migrationTable' => 'migration_module',\n" +" 'migrationPath' => null,\n" +" ],\n" +" // Migrations for the specific extension\n" +" 'migrate-rbac' => [\n" +" 'class' => 'yii\\console\\controllers\\MigrateController',\n" +" 'migrationPath' => '@yii/rbac/migrations',\n" +" 'migrationTable' => 'migration_rbac',\n" +" ],\n" +" ],\n" +"];\n" +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +msgid "" +"Note that to synchronize database you now need to run multiple commands " +"instead of one:" +msgstr "" + +#. type: Fenced code block +#: ../src/guide/databases/db-migrations.md +#, no-wrap +msgid "" +"yii migrate-app\n" +"yii migrate-module\n" +"yii migrate-rbac\n" +msgstr "" + +#. type: Title ## +#: ../src/guide/databases/db-migrations.md +#, no-wrap +msgid "Migrating Multiple Databases " +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +msgid "" +"By default, migrations are applied to the same database specified by the " +"`db` [application component](structure-application-components.md). If you " +"want them to be applied to a different database, you may specify the `db` " +"command-line option like shown below," +msgstr "" + +#. type: Fenced code block +#: ../src/guide/databases/db-migrations.md +#, no-wrap +msgid "yii migrate --db=db2\n" +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +msgid "The above command will apply migrations to the `db2` database." +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +msgid "" +"Sometimes it may happen that you want to apply *some* of the migrations to " +"one database, while some others to another database. To achieve this goal, " +"when implementing a migration class you should explicitly specify the DB " +"component ID that the migration would use, like the following:" +msgstr "" + +#. type: Fenced code block (php) +#: ../src/guide/databases/db-migrations.md +#, no-wrap +msgid "" +"db = 'db2';\n" +" parent::init();\n" +" }\n" +"}\n" +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +msgid "" +"The above migration will be applied to `db2`, even if you specify a " +"different database through the `db` command-line option. Note that the " +"migration history will still be recorded in the database specified by the " +"`db` command-line option." +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +msgid "" +"If you have multiple migrations that use the same database, it is " +"recommended that you create a base migration class with the above `init()` " +"code. Then each migration class can extend from this base class." +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +#, no-wrap +msgid "" +"> Tip: Besides setting the [[yii\\db\\Migration::db|db]] property, you can also operate on different databases\n" +"by creating new database connections to them in your migration classes. You then use the [DAO methods](db-dao.md)\n" +"with these connections to manipulate different databases.\n" +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +msgid "" +"Another strategy that you can take to migrate multiple databases is to keep " +"migrations for different databases in different migration paths. Then you " +"can migrate these databases in separate commands like the following:" +msgstr "" + +#. type: Fenced code block +#: ../src/guide/databases/db-migrations.md +#, no-wrap +msgid "" +"yii migrate --migrationPath=@app/migrations/db1 --db=db1\n" +"yii migrate --migrationPath=@app/migrations/db2 --db=db2\n" +"...\n" +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +msgid "" +"The first command will apply migrations in `@app/migrations/db1` to the " +"`db1` database, the second command will apply migrations in `@app/migrations/" +"db2` to `db2`, and so on." +msgstr "" + #. type: Title ### -#: ../../guide/en/databases/db-migrations.md +#: ../src/guide/databases/db-migrations.md #, no-wrap msgid "Upgrading from Yii2" msgstr "" #. type: Plain text -#: ../../guide/en/databases/db-migrations.md +#: ../src/guide/databases/db-migrations.md msgid "" "Migrations in Yii2 and the [yiisoft/db-migration](https://github.com/yiisoft/" "db-migration/) package are not compatible, and the `migration` table is also " diff --git a/_translations/pot/guide_start_creating-project.md.pot b/_translations/pot/guide_start_creating-project.md.pot index caaab852..71a34b6e 100644 --- a/_translations/pot/guide_start_creating-project.md.pot +++ b/_translations/pot/guide_start_creating-project.md.pot @@ -7,7 +7,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" -"POT-Creation-Date: 2025-12-24 13:00+0000\n" +"POT-Creation-Date: 2025-12-25 22:40+0000\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -36,7 +36,7 @@ msgstr "" msgid "" "> [!NOTE]\n" "> If you want to use another web server,\n" -"> see [\"Configuring web servers\"](../../../cookbook/en/configuring-webservers/general.md).\n" +"> see [\"Configuring web servers\"](../../cookbook/configuring-webservers/general.md).\n" msgstr "" #. type: Plain text @@ -62,13 +62,15 @@ msgstr "" #. type: Plain text #: ../src/guide/start/creating-project.md -msgid "Docker users can run the following command:" +msgid "Docker users can run the following commands:" msgstr "" #. type: Fenced code block (sh) #: ../src/guide/start/creating-project.md #, no-wrap -msgid "docker run --rm -it -v \"$(pwd):/app\" composer/composer create-project yiisoft/app your_project\n" +msgid "" +"docker run --rm -it -v \"$(pwd):/app\" composer/composer create-project yiisoft/app your_project\n" +"sudo chown -R $(id -u):$(id -g) your_project\n" msgstr "" #. type: Plain text diff --git a/_translations/pot/guide_start_databases.md.pot b/_translations/pot/guide_start_databases.md.pot index cc87dc97..66e400b6 100644 --- a/_translations/pot/guide_start_databases.md.pot +++ b/_translations/pot/guide_start_databases.md.pot @@ -7,7 +7,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" -"POT-Creation-Date: 2025-12-24 13:00+0000\n" +"POT-Creation-Date: 2025-12-25 22:40+0000\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -16,6 +16,22 @@ msgstr "" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: 8bit\n" +#. type: Fenced code block (sh) +#: ../src/guide/databases/db-migrations.md ../src/guide/start/databases.md +#, no-wrap +msgid "make composer require yiisoft/db-migration\n" +msgstr "" + +#. type: Fenced code block (php) +#: ../src/guide/databases/db-migrations.md ../src/guide/start/databases.md +#, no-wrap +msgid "" +"'yiisoft/db-migration' => [\n" +" 'newMigrationNamespace' => 'App\\\\Migration',\n" +" 'sourceNamespaces' => ['App\\\\Migration'],\n" +"],\n" +msgstr "" + #. type: Title # #: ../src/guide/index.md ../src/guide/start/databases.md #, no-wrap @@ -184,20 +200,13 @@ msgstr "" #. type: Plain text #: ../src/guide/start/databases.md -msgid "" -"Let's use latest versions to be released. Change your `minimum-stability` to " -"`dev` in `composer.json` first." -msgstr "" - -#. type: Plain text -#: ../src/guide/start/databases.md -msgid "Then we need a package to be installed:" +msgid "First we need a package to be installed:" msgstr "" #. type: Fenced code block (sh) #: ../src/guide/start/databases.md #, no-wrap -msgid "make composer require yiisoft/db-pgsql dev-master\n" +msgid "make composer require yiisoft/db-pgsql\n" msgstr "" #. type: Plain text @@ -286,12 +295,6 @@ msgstr "" msgid "To use migrations we need another package installed:" msgstr "" -#. type: Fenced code block (sh) -#: ../src/guide/start/databases.md -#, no-wrap -msgid "composer require yiisoft/db-migration dev-master\n" -msgstr "" - #. type: Plain text #: ../src/guide/start/databases.md msgid "" @@ -299,16 +302,6 @@ msgid "" "root. Add the following configuration to `config/common/params.php`:" msgstr "" -#. type: Fenced code block (php) -#: ../src/guide/start/databases.md -#, no-wrap -msgid "" -"'yiisoft/db-migration' => [\n" -" 'newMigrationNamespace' => 'App\\\\Migration',\n" -" 'sourceNamespaces' => ['App\\\\Migration'],\n" -"],\n" -msgstr "" - #. type: Plain text #: ../src/guide/start/databases.md msgid "" @@ -329,9 +322,6 @@ msgid "" "use Yiisoft\\Db\\Migration\\MigrationBuilder;\n" "use Yiisoft\\Db\\Migration\\RevertibleMigrationInterface;\n" "\n" -"/**\n" -" * Class M251102141707Page\n" -" */\n" "final class M251102141707Page implements RevertibleMigrationInterface\n" "{\n" " public function up(MigrationBuilder $b): void\n" @@ -390,6 +380,8 @@ msgstr "" msgid "" "\n" "Language-Team: LANGUAGE \n" @@ -105,8 +105,10 @@ msgid "" " private ResponseFactoryInterface $responseFactory,\n" " ) {}\n" "\n" -" #[RouteArgument('message')]\n" -" public function __invoke(string $message = 'Hello!'): ResponseInterface\n" +" public function __invoke(\n" +" #[RouteArgument('message')]\n" +" string $message = 'Hello!'\n" +" ): ResponseInterface\n" " {\n" " $response = $this->responseFactory->createResponse();\n" " $response->getBody()->write('The message is: ' . Html::encode($message));\n" @@ -270,7 +272,7 @@ msgid "To use the view, you need to change `src/Web/Echo/Action.php`:" msgstr "" #. type: Fenced code block (php) -#: ../src/guide/start/hello.md ../src/guide/views/view.md +#: ../src/guide/start/hello.md #, no-wrap msgid "" "viewRenderer->render(__DIR__ . '/template', [\n" " 'message' => $message,\n" diff --git a/_translations/pot/guide_views_template-engines.md.pot b/_translations/pot/guide_views_template-engines.md.pot index 72c6272b..cc408aee 100644 --- a/_translations/pot/guide_views_template-engines.md.pot +++ b/_translations/pot/guide_views_template-engines.md.pot @@ -7,7 +7,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" -"POT-Creation-Date: 2025-12-24 13:00+0000\n" +"POT-Creation-Date: 2025-12-25 22:40+0000\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -268,10 +268,12 @@ msgstr "" #: ../src/guide/views/template-engines.md #, no-wrap msgid "" +"use Yiisoft\\Container\\Reference;\n" +"\n" "// In configuration\n" "'yiisoft/view' => [\n" " 'renderers' => [\n" -" 'md' => App\\View\\MarkdownRenderer::class,\n" +" 'md' => Reference::to(App\\View\\MarkdownRenderer::class),\n" " ],\n" "],\n" msgstr "" @@ -295,7 +297,7 @@ msgid "" "\n" "Welcome, {{username}}!\n" "\n" -"This is a markdown template with **bold** and *italic* text.\n" +"This is a Markdown template with **bold** and *italic* text.\n" "\n" "- Feature 1\n" "- Feature 2\n" diff --git a/_translations/pot/guide_views_view.md.pot b/_translations/pot/guide_views_view.md.pot index cf2ffa1e..041a717b 100644 --- a/_translations/pot/guide_views_view.md.pot +++ b/_translations/pot/guide_views_view.md.pot @@ -7,7 +7,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" -"POT-Creation-Date: 2025-12-24 13:00+0000\n" +"POT-Creation-Date: 2025-12-25 22:40+0000\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -44,36 +44,6 @@ msgid "" "

The message is:

\n" msgstr "" -#. type: Fenced code block (php) -#: ../src/guide/start/hello.md ../src/guide/views/view.md -#, no-wrap -msgid "" -"viewRenderer->render(__DIR__ . '/template', [\n" -" 'message' => $message,\n" -" ]);\n" -" }\n" -"}\n" -msgstr "" - #. type: Title ## #: ../src/guide/views/asset.md ../src/guide/views/view.md #: ../src/guide/views/widget.md @@ -160,6 +130,36 @@ msgid "" "with the help of `ViewRenderer`. For example, `src/Web/Echo/Action.php`:" msgstr "" +#. type: Fenced code block (php) +#: ../src/guide/views/view.md +#, no-wrap +msgid "" +"viewRenderer->render(__DIR__ . '/template', [\n" +" 'message' => $message,\n" +" ]);\n" +" }\n" +"}\n" +msgstr "" + #. type: Plain text #: ../src/guide/views/view.md msgid "" diff --git a/src/es/guide/databases/db-migrations.md b/src/es/guide/databases/db-migrations.md index 057d2896..76ba389d 100644 --- a/src/es/guide/databases/db-migrations.md +++ b/src/es/guide/databases/db-migrations.md @@ -1,61 +1,329 @@ # Migrations +During the course of developing and maintaining a database-driven +application, the structure of the database being used evolves just like the +source code does. For example, during the development of an application, a +new table may be found necessary; after the application is deployed to +production, it may be discovered that an index should be created to improve +the query performance; and so on. Because a database structure change often +requires some source code changes, Yii supports the so-called *database +migration* feature that allows you to keep track of database changes in +terms of *database migrations* which are version-controlled together with +the source code. + +The following steps show how database migration can be used by a team during +development: + +1. Tim creates a new migration (e.g. creates a new table, changes a column + definition, etc.). +2. Tim commits the new migration into the source control system (e.g. Git, + Mercurial). +3. Doug updates his repository from the source control system and receives + the new migration. +4. Doug applies the migration to his local development database, thereby + synchronizing his database to reflect the changes that Tim has made. + +And the following steps show how to deploy a new release with database +migrations to production: + +1. Scott creates a release tag for the project repository that contains some + new database migrations. +2. Scott updates the source code on the production server to the release + tag. +3. Scott applies any accumulated database migrations to the production + database. + +Yii provides a set of migration command line tools that allow you to: + +* create new migrations; +* apply migrations; +* revert migrations; +* re-apply migrations; +* show migration history and status. + +All these tools are accessible through the command `yii migrate`. In this +section we will describe in detail how to accomplish various tasks using +these tools. + +> [!TIP] +> Migrations could affect not only database schema but adjust existing data to fit new schema, create RBAC +hierarchy or clean up cache. + +> [!NOTE] +> When manipulating data using a migration you may find that using your Active Record or entity classes +> for this might be useful because some of the logic is already implemented there. Keep in mind however, that in contrast +> to code written in the migrations, whose nature is to stay constant forever, application logic is subject to change. +> So when using Active Record or entity classes in migration code, changes to the logic in the source code +> may accidentally break the existing migrations. For this reason migration code should be kept independent of other +> application logic such. + +## Initial configuration + To use migrations, install [yiisoft/db-migration](https://github.com/yiisoft/db-migration/) package: ```shell -composer require yiisoft/db-migration +make composer require yiisoft/db-migration ``` -### Example usage +Create a directory to store migrations `src/Migration` right in the project +root. -First, configure a DI container. Create `config/common/db.php` with the -following content: +Add the following configuration to `config/common/params.php`: + +```php +'yiisoft/db-migration' => [ + 'newMigrationNamespace' => 'App\\Migration', + 'sourceNamespaces' => ['App\\Migration'], +], +``` + +You need a database connection configured as well. See [Working with +databases](../start/databases.md) for an example of configuring it for +PostgreSQL. + +### Creating a migration + +To create a new empty migration, run the following command: + +```sh +make yii migrate:create +``` + +The required `name` argument gives a brief description about the new +migration. For example, if the migration is about creating a new table named +*news*, you may use the name `create_news_table` and run the following +command: + +``` +make yii migrate:create create_news_table +``` + + +> [!NOTE] +> Because the `name` argument will be used as part of the generated migration class name, +> it should only contain letters, digits, and/or underscore characters. + +The above command will create a new PHP class file named +`src/Migration/M251225221906CreateNewsTable.php`. The file contains the +following code which mainly declares a migration class with the skeleton +code: ```php [ - 'class' => SqliteConnection::class, - '__construct()' => [ - 'dsn' => 'sqlite:' . __DIR__ . '/Data/yiitest.sq3' - ] - ] -]; +use Yiisoft\Db\Migration\MigrationBuilder; +use Yiisoft\Db\Migration\RevertibleMigrationInterface; + +final class M251225221906CreateNewsTable implements RevertibleMigrationInterface +{ + public function up(MigrationBuilder $b): void + { + // TODO: Implement the logic to apply the migration. + } + + public function down(MigrationBuilder $b): void + { + // TODO: Implement the logic to revert the migration. + } +} ``` -Add the following to `config/params.php`: +In the migration class, you are expected to write code in the `up()` method +that makes changes to the database structure. You may also want to write +code in the `down()` method to revert the changes made by `up()`. The `up()` +method is invoked when you upgrade the database with this migration, while +the `down()` method is invoked when you downgrade the database. The +following code shows how you may implement the migration class to create a +`news` table: ```php -... -'yiisoft/db-migration' => [ - 'newMigrationNamespace' => 'App\\Migration', - 'sourceNamespaces' => ['App\\Migration'], -], -... +columnBuilder(); + + $b->createTable('news', [ + 'id' => $cb::uuidPrimaryKey(), + 'title' => $cb::string()->notNull(), + 'content' => $cb::text(), + ]); + } + + public function down(MigrationBuilder $b): void + { + $b->dropTable('news'); + } +} ``` -Now test if it works: +TODO: explain $b and $qb +Below is the list of all these database accessing methods: -```shell -./yii list migrate +### Irreversible migrations + +Not all migrations are reversible. For example, if the `up()` method deletes +a row of a table, you may not be able to recover this row in the `down()` +method. Sometimes, you may be just too lazy to implement the `down()`, +because it is not very common to revert database migrations. In this case, +you should implement `Yiisoft\Db\Migration\MigrationInterface` that has +`up()` only. + + +### Transactional migrations (TODO: update!!!) + +While performing complex DB migrations, it is important to ensure each +migration to either succeed or fail as a whole so that the database can +maintain integrity and consistency. To achieve this goal, it is recommended +that you enclose the DB operations of each migration in a +[transaction](db-dao.md#performing-transactions). + +An even easier way of implementing transactional migrations is to put +migration code in the `safeUp()` and `safeDown()` methods. These two methods +differ from `up()` and `down()` in that they are enclosed implicitly in a +transaction. As a result, if any operation in these methods fails, all +prior operations will be rolled back automatically. + +In the following example, besides creating the `news` table we also insert +an initial row into this table. + +```php +createTable('news', [ + 'id' => $this->primaryKey(), + 'title' => $this->string()->notNull(), + 'content' => $this->text(), + ]); + + $this->insert('news', [ + 'title' => 'test 1', + 'content' => 'content 1', + ]); + } + + public function safeDown() + { + $this->delete('news', ['id' => 1]); + $this->dropTable('news'); + } +} ``` -### Creating a migration +Note that usually when you perform multiple DB operations in `safeUp()`, you +should reverse their execution order in `safeDown()`. In the above example +we first create the table and then insert a row in `safeUp()`; while in +`safeDown()` we first delete the row and then drop the table. + +> Note: Not all DBMS support transactions. And some DB queries cannot be put into a transaction. For some examples, +please refer to [implicit commit](https://dev.mysql.com/doc/refman/5.7/en/implicit-commit.html). If this is the case, +you should still implement `up()` and `down()`, instead. + +TODO: TransactionalMigrationInterface + + + +## TODO: update + +The base migration class [[yii\db\Migration]] exposes a database connection +via the [[yii\db\Migration::db|db]] property. You can use it to manipulate +the database schema using the methods as described in [Working with Database +Schema](db-dao.md#database-schema). + +Rather than using physical types, when creating a table or column you should use *abstract types* +so that your migrations are independent of specific DBMS. The [[yii\db\Schema]] class defines +a set of constants to represent the supported abstract types. These constants are named in the format +of `TYPE_`. For example, `TYPE_PK` refers to auto-incremental primary key type; `TYPE_STRING` +refers to a string type. When a migration is applied to a particular database, the abstract types +will be translated into the corresponding physical types. In the case of MySQL, `TYPE_PK` will be turned +into `int(11) NOT NULL AUTO_INCREMENT PRIMARY KEY`, while `TYPE_STRING` becomes `varchar(255)`. + +You can append additional constraints when using abstract types. In the +above example, ` NOT NULL` is appended to `Schema::TYPE_STRING` to specify +that the column cannot be `null`. -To work with migrations, you can use the provided -[view](https://github.com/yiisoft/db-migration/tree/master/resources/views). +> Info: The mapping between abstract types and physical types is specified by +the [[yii\db\QueryBuilder::$typeMap|$typeMap]] property in each concrete `QueryBuilder` class. + +Since version 2.0.6, you can make use of the newly introduced schema builder +which provides more convenient way of defining column schema. So the +migration above could be written like the following: + +```php +createTable('news', [ + 'id' => $this->primaryKey(), + 'title' => $this->string()->notNull(), + 'content' => $this->text(), + ]); + } + + public function down() + { + $this->dropTable('news'); + } +} +``` + +A list of all available methods for defining the column types is available +in the API documentation of [[yii\db\SchemaBuilderTrait]]. + +> Info: The generated file permissions and ownership will be determined by the current environment. This might lead to +inaccessible files. This could, for example, happen when the migration is created within a docker container +and the files are edited on the host. In this case the `newFileMode` and/or `newFileOwnership` of the MigrateController +can be changed. E.g. in the application config: + ```php + [ + 'migrate' => [ + 'class' => 'yii\console\controllers\MigrateController', + 'newFileOwnership' => '1000:1000', # Default WSL user id + 'newFileMode' => 0660, + ], + ], + ]; + ``` + +## Generating Migrations (TODO: likely is OK but...) + +The command provides a convenient way to create migrations using the +provided +[view](https://github.com/yiisoft/db-migration/tree/master/resources/views): ```shell -./yii migrate:create my_first_table --command=table --fields=name,example --table-comment=my_first_table +make yii migrate:create my_first_table --command=table --fields=name,example --table-comment=my_first_table ``` + + That would generate the following: ```php @@ -95,6 +363,305 @@ final class M240115143455CreateMyFirstTableTable implements RevertibleMigrationI For more information [see](https://github.com/yiisoft/db-migration/tree/master/docs/guide/en) + +## Applying Migrations + +To upgrade a database to its latest structure, you should apply all +available new migrations using the following command: + +``` +yii migrate +``` + +This command will list all migrations that have not been applied so far. If +you confirm that you want to apply these migrations, it will run the `up()` +or `safeUp()` method in every new migration class, one after another, in the +order of their timestamp values. If any of the migrations fails, the command +will quit without applying the rest of the migrations. + +> Tip: In case you don't have command line at your server you may try [web shell](https://github.com/samdark/yii2-webshell) +> extension. + +For each migration that has been successfully applied, the command will +insert a row into a database table named `migration` to record the +successful application of the migration. This will allow the migration tool +to identify which migrations have been applied and which have not. + +> Info: The migration tool will automatically create the `migration` table in the database specified by +the [[yii\console\controllers\MigrateController::db|db]] option of the command. By default, the database +is specified by the `db` [application component](structure-application-components.md). + +Sometimes, you may only want to apply one or a few new migrations, instead +of all available migrations. You can do so by specifying the number of +migrations that you want to apply when running the command. For example, +the following command will try to apply the next three available migrations: + +``` +yii migrate 3 +``` + +You can also explicitly specify a particular migration to which the database +should be migrated by using the `migrate/to` command in one of the following +formats: + +``` +yii migrate/to 150101_185401 # using timestamp to specify the migration +yii migrate/to "2015-01-01 18:54:01" # using a string that can be parsed by strtotime() +yii migrate/to m150101_185401_create_news_table # using full name +yii migrate/to 1392853618 # using UNIX timestamp +``` + +If there are any unapplied migrations earlier than the specified one, they +will all be applied before the specified migration is applied. + +If the specified migration has already been applied before, any later +applied migrations will be reverted. + + +## Reverting Migrations + +To revert (undo) one or multiple migrations that have been applied before, +you can run the following command: + +``` +yii migrate/down # revert the most recently applied migration +yii migrate/down 3 # revert the most 3 recently applied migrations +``` + +> Note: Not all migrations are reversible. Trying to revert such migrations will cause an error and stop the +entire reverting process. + + +## Redoing Migrations + +Redoing migrations means first reverting the specified migrations and then +applying again. This can be done as follows: + +``` +yii migrate/redo # redo the last applied migration +yii migrate/redo 3 # redo the last 3 applied migrations +``` + +> Note: If a migration is not reversible, you will not be able to redo it. + +## Refreshing Migrations + +Since Yii 2.0.13 you can delete all tables and foreign keys from the +database and apply all migrations from the beginning. + +``` +yii migrate/fresh # truncate the database and apply all migrations from the beginning +``` + +## Listing Migrations + +To list which migrations have been applied and which are not, you may use +the following commands: + +``` +yii migrate/history # showing the last 10 applied migrations +yii migrate/history 5 # showing the last 5 applied migrations +yii migrate/history all # showing all applied migrations + +yii migrate/new # showing the first 10 new migrations +yii migrate/new 5 # showing the first 5 new migrations +yii migrate/new all # showing all new migrations +``` + + +## Modifying Migration History + +Instead of actually applying or reverting migrations, sometimes you may +simply want to mark that your database has been upgraded to a particular +migration. This often happens when you manually change the database to a +particular state and you do not want the migration(s) for that change to be +re-applied later. You can achieve this goal with the following command: + +``` +yii migrate/mark 150101_185401 # using timestamp to specify the migration +yii migrate/mark "2015-01-01 18:54:01" # using a string that can be parsed by strtotime() +yii migrate/mark m150101_185401_create_news_table # using full name +yii migrate/mark 1392853618 # using UNIX timestamp +``` + +The command will modify the `migration` table by adding or deleting certain +rows to indicate that the database has been applied migrations to the +specified one. No migrations will be applied or reverted by this command. + + +## Customizing Migrations + +There are several ways to customize the migration command. + + +### Using Command Line Options + +The migration command comes with a few command-line options that can be used +to customize its behaviors: + +* `interactive`: boolean (defaults to `true`), specifies whether to perform + migrations in an interactive mode. When this is `true`, the user will be + prompted before the command performs certain actions. You may want to set + this to `false` if the command is being used in a background process. + +* `migrationPath`: string|array (defaults to `@app/migrations`), specifies + the directory storing all migration class files. This can be specified as + either a directory path or a path [alias](concept-aliases.md). Note that + the directory must exist, or the command may trigger an error. Since + version 2.0.12 an array can be specified for loading migrations from + multiple sources. + +* `migrationTable`: string (defaults to `migration`), specifies the name of + the database table for storing migration history information. The table + will be automatically created by the command if it does not exist. You + may also manually create it using the structure `version varchar(255) + primary key, apply_time integer`. + +* `db`: string (defaults to `db`), specifies the ID of the database + [application component](structure-application-components.md). It + represents the database that will be migrated using this command. + +* `templateFile`: string (defaults to `@yii/views/migration.php`), specifies + the path of the template file that is used for generating skeleton + migration class files. This can be specified as either a file path or a + path [alias](concept-aliases.md). The template file is a PHP script in + which you can use a predefined variable named `$className` to get the + migration class name. + +* `generatorTemplateFiles`: array (defaults to `[ + 'create_table' => '@yii/views/createTableMigration.php', + 'drop_table' => '@yii/views/dropTableMigration.php', + 'add_column' => '@yii/views/addColumnMigration.php', + 'drop_column' => '@yii/views/dropColumnMigration.php', + 'create_junction' => '@yii/views/createTableMigration.php' + ]`), specifies template files for generating migration code. See "[Generating Migrations](#generating-migrations)" + for more details. + +* `fields`: array of column definition strings used for creating migration + code. Defaults to `[]`. The format of each definition is + `COLUMN_NAME:COLUMN_TYPE:COLUMN_DECORATOR`. For example, + `--fields=name:string(12):notNull` produces a string column of size 12 + which is not `null`. + +The following example shows how you can use these options. + +For example, if we want to migrate a `forum` module whose migration files +are located within the module's `migrations` directory, we can use the +following command: + +``` +# migrate the migrations in a forum module non-interactively +yii migrate --migrationPath=@app/modules/forum/migrations --interactive=0 +``` + +### Separated Migrations + + +Sometimes using single migration history for all project migrations is not +desirable. For example: you may install some 'blog' extension, which +contains fully separated functionality and contain its own migrations, which +should not affect the ones dedicated to main project functionality. + +If you want several migrations to be applied and tracked down completely +separated from each other, you can configure multiple migration commands +which will use different namespaces and migration history tables: + +```php +return [ + 'controllerMap' => [ + // Common migrations for the whole application + 'migrate-app' => [ + 'class' => 'yii\console\controllers\MigrateController', + 'migrationNamespaces' => ['app\migrations'], + 'migrationTable' => 'migration_app', + 'migrationPath' => null, + ], + // Migrations for the specific project's module + 'migrate-module' => [ + 'class' => 'yii\console\controllers\MigrateController', + 'migrationNamespaces' => ['module\migrations'], + 'migrationTable' => 'migration_module', + 'migrationPath' => null, + ], + // Migrations for the specific extension + 'migrate-rbac' => [ + 'class' => 'yii\console\controllers\MigrateController', + 'migrationPath' => '@yii/rbac/migrations', + 'migrationTable' => 'migration_rbac', + ], + ], +]; +``` + +Note that to synchronize database you now need to run multiple commands +instead of one: + +``` +yii migrate-app +yii migrate-module +yii migrate-rbac +``` + +## Migrating Multiple Databases + +By default, migrations are applied to the same database specified by the +`db` [application component](structure-application-components.md). If you +want them to be applied to a different database, you may specify the `db` +command-line option like shown below, + +``` +yii migrate --db=db2 +``` + +The above command will apply migrations to the `db2` database. + +Sometimes it may happen that you want to apply *some* of the migrations to +one database, while some others to another database. To achieve this goal, +when implementing a migration class you should explicitly specify the DB +component ID that the migration would use, like the following: + +```php +db = 'db2'; + parent::init(); + } +} +``` + +The above migration will be applied to `db2`, even if you specify a +different database through the `db` command-line option. Note that the +migration history will still be recorded in the database specified by the +`db` command-line option. + +If you have multiple migrations that use the same database, it is +recommended that you create a base migration class with the above `init()` +code. Then each migration class can extend from this base class. + +> Tip: Besides setting the [[yii\db\Migration::db|db]] property, you can also operate on different databases +by creating new database connections to them in your migration classes. You then use the [DAO methods](db-dao.md) +with these connections to manipulate different databases. + +Another strategy that you can take to migrate multiple databases is to keep +migrations for different databases in different migration paths. Then you +can migrate these databases in separate commands like the following: + +``` +yii migrate --migrationPath=@app/migrations/db1 --db=db1 +yii migrate --migrationPath=@app/migrations/db2 --db=db2 +... +``` + +The first command will apply migrations in `@app/migrations/db1` to the +`db1` database, the second command will apply migrations in +`@app/migrations/db2` to `db2`, and so on. + ### Upgrading from Yii2 Migrations in Yii2 and the diff --git a/src/es/guide/start/creating-project.md b/src/es/guide/start/creating-project.md index efde5e36..52ba1bab 100644 --- a/src/es/guide/start/creating-project.md +++ b/src/es/guide/start/creating-project.md @@ -6,7 +6,7 @@ dev server with everything installed locally. > [!NOTE] > If you want to use another web server, -> see ["Configuring web servers"](../../../cookbook/en/configuring-webservers/general.md). +> see ["Configuring web servers"](../../cookbook/configuring-webservers/general.md). We recommend starting with a project template that's a minimal working Yii project implementing some basic features. It can serve as a good starting @@ -19,10 +19,11 @@ You can create a new project from a template using the composer create-project yiisoft/app your_project ``` -Docker users can run the following command: - +Docker users can run the following commands: + ```sh docker run --rm -it -v "$(pwd):/app" composer/composer create-project yiisoft/app your_project +sudo chown -R $(id -u):$(id -g) your_project ``` This installs the latest stable version of the Yii project template in a diff --git a/src/es/guide/start/databases.md b/src/es/guide/start/databases.md index b4be1d4b..0c9a8010 100644 --- a/src/es/guide/start/databases.md +++ b/src/es/guide/start/databases.md @@ -86,13 +86,10 @@ list. Then rebuild PHP image with `make build && make down && make up`. Now that we have the database, it's time to define the connection. -Let's use latest versions to be released. Change your `minimum-stability` to -`dev` in `composer.json` first. - -Then we need a package to be installed: +First we need a package to be installed: ```sh -make composer require yiisoft/db-pgsql dev-master +make composer require yiisoft/db-pgsql ``` Now create `config/common/di/db-pgsql.php`: @@ -152,7 +149,7 @@ the current state and which migrations remain to be applied. To use migrations we need another package installed: ```sh -composer require yiisoft/db-migration dev-master +make composer require yiisoft/db-migration ``` Create a directory to store migrations `src/Migration` right in the project @@ -178,9 +175,6 @@ namespace App\Migration; use Yiisoft\Db\Migration\MigrationBuilder; use Yiisoft\Db\Migration\RevertibleMigrationInterface; -/** - * Class M251102141707Page - */ final class M251102141707Page implements RevertibleMigrationInterface { public function up(MigrationBuilder $b): void @@ -221,6 +215,8 @@ Now that you have a table it is time to define an entity in the code. Create ```php responseFactory->createResponse(); $response->getBody()->write('The message is: ' . Html::encode($message)); @@ -155,8 +157,10 @@ final readonly class Action private ViewRenderer $viewRenderer, ) {} - #[RouteArgument('message')] - public function __invoke(string $message = 'Hello!'): ResponseInterface + public function __invoke( + #[RouteArgument('message')] + string $message = 'Hello!' + ): ResponseInterface { return $this->viewRenderer->render(__DIR__ . '/template', [ 'message' => $message, diff --git a/src/es/guide/views/template-engines.md b/src/es/guide/views/template-engines.md index 08ab054c..708f6141 100644 --- a/src/es/guide/views/template-engines.md +++ b/src/es/guide/views/template-engines.md @@ -150,10 +150,12 @@ final class MarkdownRenderer implements TemplateRendererInterface Register your custom renderer: ```php +use Yiisoft\Container\Reference; + // In configuration 'yiisoft/view' => [ 'renderers' => [ - 'md' => App\View\MarkdownRenderer::class, + 'md' => Reference::to(App\View\MarkdownRenderer::class), ], ], ``` @@ -166,7 +168,7 @@ Now you can use `.md` template files: Welcome, {{username}}! -This is a markdown template with **bold** and *italic* text. +This is a Markdown template with **bold** and *italic* text. - Feature 1 - Feature 2 diff --git a/src/id/guide/databases/db-migrations.md b/src/id/guide/databases/db-migrations.md index 057d2896..76ba389d 100644 --- a/src/id/guide/databases/db-migrations.md +++ b/src/id/guide/databases/db-migrations.md @@ -1,61 +1,329 @@ # Migrations +During the course of developing and maintaining a database-driven +application, the structure of the database being used evolves just like the +source code does. For example, during the development of an application, a +new table may be found necessary; after the application is deployed to +production, it may be discovered that an index should be created to improve +the query performance; and so on. Because a database structure change often +requires some source code changes, Yii supports the so-called *database +migration* feature that allows you to keep track of database changes in +terms of *database migrations* which are version-controlled together with +the source code. + +The following steps show how database migration can be used by a team during +development: + +1. Tim creates a new migration (e.g. creates a new table, changes a column + definition, etc.). +2. Tim commits the new migration into the source control system (e.g. Git, + Mercurial). +3. Doug updates his repository from the source control system and receives + the new migration. +4. Doug applies the migration to his local development database, thereby + synchronizing his database to reflect the changes that Tim has made. + +And the following steps show how to deploy a new release with database +migrations to production: + +1. Scott creates a release tag for the project repository that contains some + new database migrations. +2. Scott updates the source code on the production server to the release + tag. +3. Scott applies any accumulated database migrations to the production + database. + +Yii provides a set of migration command line tools that allow you to: + +* create new migrations; +* apply migrations; +* revert migrations; +* re-apply migrations; +* show migration history and status. + +All these tools are accessible through the command `yii migrate`. In this +section we will describe in detail how to accomplish various tasks using +these tools. + +> [!TIP] +> Migrations could affect not only database schema but adjust existing data to fit new schema, create RBAC +hierarchy or clean up cache. + +> [!NOTE] +> When manipulating data using a migration you may find that using your Active Record or entity classes +> for this might be useful because some of the logic is already implemented there. Keep in mind however, that in contrast +> to code written in the migrations, whose nature is to stay constant forever, application logic is subject to change. +> So when using Active Record or entity classes in migration code, changes to the logic in the source code +> may accidentally break the existing migrations. For this reason migration code should be kept independent of other +> application logic such. + +## Initial configuration + To use migrations, install [yiisoft/db-migration](https://github.com/yiisoft/db-migration/) package: ```shell -composer require yiisoft/db-migration +make composer require yiisoft/db-migration ``` -### Example usage +Create a directory to store migrations `src/Migration` right in the project +root. -First, configure a DI container. Create `config/common/db.php` with the -following content: +Add the following configuration to `config/common/params.php`: + +```php +'yiisoft/db-migration' => [ + 'newMigrationNamespace' => 'App\\Migration', + 'sourceNamespaces' => ['App\\Migration'], +], +``` + +You need a database connection configured as well. See [Working with +databases](../start/databases.md) for an example of configuring it for +PostgreSQL. + +### Creating a migration + +To create a new empty migration, run the following command: + +```sh +make yii migrate:create +``` + +The required `name` argument gives a brief description about the new +migration. For example, if the migration is about creating a new table named +*news*, you may use the name `create_news_table` and run the following +command: + +``` +make yii migrate:create create_news_table +``` + + +> [!NOTE] +> Because the `name` argument will be used as part of the generated migration class name, +> it should only contain letters, digits, and/or underscore characters. + +The above command will create a new PHP class file named +`src/Migration/M251225221906CreateNewsTable.php`. The file contains the +following code which mainly declares a migration class with the skeleton +code: ```php [ - 'class' => SqliteConnection::class, - '__construct()' => [ - 'dsn' => 'sqlite:' . __DIR__ . '/Data/yiitest.sq3' - ] - ] -]; +use Yiisoft\Db\Migration\MigrationBuilder; +use Yiisoft\Db\Migration\RevertibleMigrationInterface; + +final class M251225221906CreateNewsTable implements RevertibleMigrationInterface +{ + public function up(MigrationBuilder $b): void + { + // TODO: Implement the logic to apply the migration. + } + + public function down(MigrationBuilder $b): void + { + // TODO: Implement the logic to revert the migration. + } +} ``` -Add the following to `config/params.php`: +In the migration class, you are expected to write code in the `up()` method +that makes changes to the database structure. You may also want to write +code in the `down()` method to revert the changes made by `up()`. The `up()` +method is invoked when you upgrade the database with this migration, while +the `down()` method is invoked when you downgrade the database. The +following code shows how you may implement the migration class to create a +`news` table: ```php -... -'yiisoft/db-migration' => [ - 'newMigrationNamespace' => 'App\\Migration', - 'sourceNamespaces' => ['App\\Migration'], -], -... +columnBuilder(); + + $b->createTable('news', [ + 'id' => $cb::uuidPrimaryKey(), + 'title' => $cb::string()->notNull(), + 'content' => $cb::text(), + ]); + } + + public function down(MigrationBuilder $b): void + { + $b->dropTable('news'); + } +} ``` -Now test if it works: +TODO: explain $b and $qb +Below is the list of all these database accessing methods: -```shell -./yii list migrate +### Irreversible migrations + +Not all migrations are reversible. For example, if the `up()` method deletes +a row of a table, you may not be able to recover this row in the `down()` +method. Sometimes, you may be just too lazy to implement the `down()`, +because it is not very common to revert database migrations. In this case, +you should implement `Yiisoft\Db\Migration\MigrationInterface` that has +`up()` only. + + +### Transactional migrations (TODO: update!!!) + +While performing complex DB migrations, it is important to ensure each +migration to either succeed or fail as a whole so that the database can +maintain integrity and consistency. To achieve this goal, it is recommended +that you enclose the DB operations of each migration in a +[transaction](db-dao.md#performing-transactions). + +An even easier way of implementing transactional migrations is to put +migration code in the `safeUp()` and `safeDown()` methods. These two methods +differ from `up()` and `down()` in that they are enclosed implicitly in a +transaction. As a result, if any operation in these methods fails, all +prior operations will be rolled back automatically. + +In the following example, besides creating the `news` table we also insert +an initial row into this table. + +```php +createTable('news', [ + 'id' => $this->primaryKey(), + 'title' => $this->string()->notNull(), + 'content' => $this->text(), + ]); + + $this->insert('news', [ + 'title' => 'test 1', + 'content' => 'content 1', + ]); + } + + public function safeDown() + { + $this->delete('news', ['id' => 1]); + $this->dropTable('news'); + } +} ``` -### Creating a migration +Note that usually when you perform multiple DB operations in `safeUp()`, you +should reverse their execution order in `safeDown()`. In the above example +we first create the table and then insert a row in `safeUp()`; while in +`safeDown()` we first delete the row and then drop the table. + +> Note: Not all DBMS support transactions. And some DB queries cannot be put into a transaction. For some examples, +please refer to [implicit commit](https://dev.mysql.com/doc/refman/5.7/en/implicit-commit.html). If this is the case, +you should still implement `up()` and `down()`, instead. + +TODO: TransactionalMigrationInterface + + + +## TODO: update + +The base migration class [[yii\db\Migration]] exposes a database connection +via the [[yii\db\Migration::db|db]] property. You can use it to manipulate +the database schema using the methods as described in [Working with Database +Schema](db-dao.md#database-schema). + +Rather than using physical types, when creating a table or column you should use *abstract types* +so that your migrations are independent of specific DBMS. The [[yii\db\Schema]] class defines +a set of constants to represent the supported abstract types. These constants are named in the format +of `TYPE_`. For example, `TYPE_PK` refers to auto-incremental primary key type; `TYPE_STRING` +refers to a string type. When a migration is applied to a particular database, the abstract types +will be translated into the corresponding physical types. In the case of MySQL, `TYPE_PK` will be turned +into `int(11) NOT NULL AUTO_INCREMENT PRIMARY KEY`, while `TYPE_STRING` becomes `varchar(255)`. + +You can append additional constraints when using abstract types. In the +above example, ` NOT NULL` is appended to `Schema::TYPE_STRING` to specify +that the column cannot be `null`. -To work with migrations, you can use the provided -[view](https://github.com/yiisoft/db-migration/tree/master/resources/views). +> Info: The mapping between abstract types and physical types is specified by +the [[yii\db\QueryBuilder::$typeMap|$typeMap]] property in each concrete `QueryBuilder` class. + +Since version 2.0.6, you can make use of the newly introduced schema builder +which provides more convenient way of defining column schema. So the +migration above could be written like the following: + +```php +createTable('news', [ + 'id' => $this->primaryKey(), + 'title' => $this->string()->notNull(), + 'content' => $this->text(), + ]); + } + + public function down() + { + $this->dropTable('news'); + } +} +``` + +A list of all available methods for defining the column types is available +in the API documentation of [[yii\db\SchemaBuilderTrait]]. + +> Info: The generated file permissions and ownership will be determined by the current environment. This might lead to +inaccessible files. This could, for example, happen when the migration is created within a docker container +and the files are edited on the host. In this case the `newFileMode` and/or `newFileOwnership` of the MigrateController +can be changed. E.g. in the application config: + ```php + [ + 'migrate' => [ + 'class' => 'yii\console\controllers\MigrateController', + 'newFileOwnership' => '1000:1000', # Default WSL user id + 'newFileMode' => 0660, + ], + ], + ]; + ``` + +## Generating Migrations (TODO: likely is OK but...) + +The command provides a convenient way to create migrations using the +provided +[view](https://github.com/yiisoft/db-migration/tree/master/resources/views): ```shell -./yii migrate:create my_first_table --command=table --fields=name,example --table-comment=my_first_table +make yii migrate:create my_first_table --command=table --fields=name,example --table-comment=my_first_table ``` + + That would generate the following: ```php @@ -95,6 +363,305 @@ final class M240115143455CreateMyFirstTableTable implements RevertibleMigrationI For more information [see](https://github.com/yiisoft/db-migration/tree/master/docs/guide/en) + +## Applying Migrations + +To upgrade a database to its latest structure, you should apply all +available new migrations using the following command: + +``` +yii migrate +``` + +This command will list all migrations that have not been applied so far. If +you confirm that you want to apply these migrations, it will run the `up()` +or `safeUp()` method in every new migration class, one after another, in the +order of their timestamp values. If any of the migrations fails, the command +will quit without applying the rest of the migrations. + +> Tip: In case you don't have command line at your server you may try [web shell](https://github.com/samdark/yii2-webshell) +> extension. + +For each migration that has been successfully applied, the command will +insert a row into a database table named `migration` to record the +successful application of the migration. This will allow the migration tool +to identify which migrations have been applied and which have not. + +> Info: The migration tool will automatically create the `migration` table in the database specified by +the [[yii\console\controllers\MigrateController::db|db]] option of the command. By default, the database +is specified by the `db` [application component](structure-application-components.md). + +Sometimes, you may only want to apply one or a few new migrations, instead +of all available migrations. You can do so by specifying the number of +migrations that you want to apply when running the command. For example, +the following command will try to apply the next three available migrations: + +``` +yii migrate 3 +``` + +You can also explicitly specify a particular migration to which the database +should be migrated by using the `migrate/to` command in one of the following +formats: + +``` +yii migrate/to 150101_185401 # using timestamp to specify the migration +yii migrate/to "2015-01-01 18:54:01" # using a string that can be parsed by strtotime() +yii migrate/to m150101_185401_create_news_table # using full name +yii migrate/to 1392853618 # using UNIX timestamp +``` + +If there are any unapplied migrations earlier than the specified one, they +will all be applied before the specified migration is applied. + +If the specified migration has already been applied before, any later +applied migrations will be reverted. + + +## Reverting Migrations + +To revert (undo) one or multiple migrations that have been applied before, +you can run the following command: + +``` +yii migrate/down # revert the most recently applied migration +yii migrate/down 3 # revert the most 3 recently applied migrations +``` + +> Note: Not all migrations are reversible. Trying to revert such migrations will cause an error and stop the +entire reverting process. + + +## Redoing Migrations + +Redoing migrations means first reverting the specified migrations and then +applying again. This can be done as follows: + +``` +yii migrate/redo # redo the last applied migration +yii migrate/redo 3 # redo the last 3 applied migrations +``` + +> Note: If a migration is not reversible, you will not be able to redo it. + +## Refreshing Migrations + +Since Yii 2.0.13 you can delete all tables and foreign keys from the +database and apply all migrations from the beginning. + +``` +yii migrate/fresh # truncate the database and apply all migrations from the beginning +``` + +## Listing Migrations + +To list which migrations have been applied and which are not, you may use +the following commands: + +``` +yii migrate/history # showing the last 10 applied migrations +yii migrate/history 5 # showing the last 5 applied migrations +yii migrate/history all # showing all applied migrations + +yii migrate/new # showing the first 10 new migrations +yii migrate/new 5 # showing the first 5 new migrations +yii migrate/new all # showing all new migrations +``` + + +## Modifying Migration History + +Instead of actually applying or reverting migrations, sometimes you may +simply want to mark that your database has been upgraded to a particular +migration. This often happens when you manually change the database to a +particular state and you do not want the migration(s) for that change to be +re-applied later. You can achieve this goal with the following command: + +``` +yii migrate/mark 150101_185401 # using timestamp to specify the migration +yii migrate/mark "2015-01-01 18:54:01" # using a string that can be parsed by strtotime() +yii migrate/mark m150101_185401_create_news_table # using full name +yii migrate/mark 1392853618 # using UNIX timestamp +``` + +The command will modify the `migration` table by adding or deleting certain +rows to indicate that the database has been applied migrations to the +specified one. No migrations will be applied or reverted by this command. + + +## Customizing Migrations + +There are several ways to customize the migration command. + + +### Using Command Line Options + +The migration command comes with a few command-line options that can be used +to customize its behaviors: + +* `interactive`: boolean (defaults to `true`), specifies whether to perform + migrations in an interactive mode. When this is `true`, the user will be + prompted before the command performs certain actions. You may want to set + this to `false` if the command is being used in a background process. + +* `migrationPath`: string|array (defaults to `@app/migrations`), specifies + the directory storing all migration class files. This can be specified as + either a directory path or a path [alias](concept-aliases.md). Note that + the directory must exist, or the command may trigger an error. Since + version 2.0.12 an array can be specified for loading migrations from + multiple sources. + +* `migrationTable`: string (defaults to `migration`), specifies the name of + the database table for storing migration history information. The table + will be automatically created by the command if it does not exist. You + may also manually create it using the structure `version varchar(255) + primary key, apply_time integer`. + +* `db`: string (defaults to `db`), specifies the ID of the database + [application component](structure-application-components.md). It + represents the database that will be migrated using this command. + +* `templateFile`: string (defaults to `@yii/views/migration.php`), specifies + the path of the template file that is used for generating skeleton + migration class files. This can be specified as either a file path or a + path [alias](concept-aliases.md). The template file is a PHP script in + which you can use a predefined variable named `$className` to get the + migration class name. + +* `generatorTemplateFiles`: array (defaults to `[ + 'create_table' => '@yii/views/createTableMigration.php', + 'drop_table' => '@yii/views/dropTableMigration.php', + 'add_column' => '@yii/views/addColumnMigration.php', + 'drop_column' => '@yii/views/dropColumnMigration.php', + 'create_junction' => '@yii/views/createTableMigration.php' + ]`), specifies template files for generating migration code. See "[Generating Migrations](#generating-migrations)" + for more details. + +* `fields`: array of column definition strings used for creating migration + code. Defaults to `[]`. The format of each definition is + `COLUMN_NAME:COLUMN_TYPE:COLUMN_DECORATOR`. For example, + `--fields=name:string(12):notNull` produces a string column of size 12 + which is not `null`. + +The following example shows how you can use these options. + +For example, if we want to migrate a `forum` module whose migration files +are located within the module's `migrations` directory, we can use the +following command: + +``` +# migrate the migrations in a forum module non-interactively +yii migrate --migrationPath=@app/modules/forum/migrations --interactive=0 +``` + +### Separated Migrations + + +Sometimes using single migration history for all project migrations is not +desirable. For example: you may install some 'blog' extension, which +contains fully separated functionality and contain its own migrations, which +should not affect the ones dedicated to main project functionality. + +If you want several migrations to be applied and tracked down completely +separated from each other, you can configure multiple migration commands +which will use different namespaces and migration history tables: + +```php +return [ + 'controllerMap' => [ + // Common migrations for the whole application + 'migrate-app' => [ + 'class' => 'yii\console\controllers\MigrateController', + 'migrationNamespaces' => ['app\migrations'], + 'migrationTable' => 'migration_app', + 'migrationPath' => null, + ], + // Migrations for the specific project's module + 'migrate-module' => [ + 'class' => 'yii\console\controllers\MigrateController', + 'migrationNamespaces' => ['module\migrations'], + 'migrationTable' => 'migration_module', + 'migrationPath' => null, + ], + // Migrations for the specific extension + 'migrate-rbac' => [ + 'class' => 'yii\console\controllers\MigrateController', + 'migrationPath' => '@yii/rbac/migrations', + 'migrationTable' => 'migration_rbac', + ], + ], +]; +``` + +Note that to synchronize database you now need to run multiple commands +instead of one: + +``` +yii migrate-app +yii migrate-module +yii migrate-rbac +``` + +## Migrating Multiple Databases + +By default, migrations are applied to the same database specified by the +`db` [application component](structure-application-components.md). If you +want them to be applied to a different database, you may specify the `db` +command-line option like shown below, + +``` +yii migrate --db=db2 +``` + +The above command will apply migrations to the `db2` database. + +Sometimes it may happen that you want to apply *some* of the migrations to +one database, while some others to another database. To achieve this goal, +when implementing a migration class you should explicitly specify the DB +component ID that the migration would use, like the following: + +```php +db = 'db2'; + parent::init(); + } +} +``` + +The above migration will be applied to `db2`, even if you specify a +different database through the `db` command-line option. Note that the +migration history will still be recorded in the database specified by the +`db` command-line option. + +If you have multiple migrations that use the same database, it is +recommended that you create a base migration class with the above `init()` +code. Then each migration class can extend from this base class. + +> Tip: Besides setting the [[yii\db\Migration::db|db]] property, you can also operate on different databases +by creating new database connections to them in your migration classes. You then use the [DAO methods](db-dao.md) +with these connections to manipulate different databases. + +Another strategy that you can take to migrate multiple databases is to keep +migrations for different databases in different migration paths. Then you +can migrate these databases in separate commands like the following: + +``` +yii migrate --migrationPath=@app/migrations/db1 --db=db1 +yii migrate --migrationPath=@app/migrations/db2 --db=db2 +... +``` + +The first command will apply migrations in `@app/migrations/db1` to the +`db1` database, the second command will apply migrations in +`@app/migrations/db2` to `db2`, and so on. + ### Upgrading from Yii2 Migrations in Yii2 and the diff --git a/src/id/guide/start/creating-project.md b/src/id/guide/start/creating-project.md index efde5e36..52ba1bab 100644 --- a/src/id/guide/start/creating-project.md +++ b/src/id/guide/start/creating-project.md @@ -6,7 +6,7 @@ dev server with everything installed locally. > [!NOTE] > If you want to use another web server, -> see ["Configuring web servers"](../../../cookbook/en/configuring-webservers/general.md). +> see ["Configuring web servers"](../../cookbook/configuring-webservers/general.md). We recommend starting with a project template that's a minimal working Yii project implementing some basic features. It can serve as a good starting @@ -19,10 +19,11 @@ You can create a new project from a template using the composer create-project yiisoft/app your_project ``` -Docker users can run the following command: - +Docker users can run the following commands: + ```sh docker run --rm -it -v "$(pwd):/app" composer/composer create-project yiisoft/app your_project +sudo chown -R $(id -u):$(id -g) your_project ``` This installs the latest stable version of the Yii project template in a diff --git a/src/id/guide/start/databases.md b/src/id/guide/start/databases.md index b4be1d4b..0c9a8010 100644 --- a/src/id/guide/start/databases.md +++ b/src/id/guide/start/databases.md @@ -86,13 +86,10 @@ list. Then rebuild PHP image with `make build && make down && make up`. Now that we have the database, it's time to define the connection. -Let's use latest versions to be released. Change your `minimum-stability` to -`dev` in `composer.json` first. - -Then we need a package to be installed: +First we need a package to be installed: ```sh -make composer require yiisoft/db-pgsql dev-master +make composer require yiisoft/db-pgsql ``` Now create `config/common/di/db-pgsql.php`: @@ -152,7 +149,7 @@ the current state and which migrations remain to be applied. To use migrations we need another package installed: ```sh -composer require yiisoft/db-migration dev-master +make composer require yiisoft/db-migration ``` Create a directory to store migrations `src/Migration` right in the project @@ -178,9 +175,6 @@ namespace App\Migration; use Yiisoft\Db\Migration\MigrationBuilder; use Yiisoft\Db\Migration\RevertibleMigrationInterface; -/** - * Class M251102141707Page - */ final class M251102141707Page implements RevertibleMigrationInterface { public function up(MigrationBuilder $b): void @@ -221,6 +215,8 @@ Now that you have a table it is time to define an entity in the code. Create ```php responseFactory->createResponse(); $response->getBody()->write('The message is: ' . Html::encode($message)); @@ -155,8 +157,10 @@ final readonly class Action private ViewRenderer $viewRenderer, ) {} - #[RouteArgument('message')] - public function __invoke(string $message = 'Hello!'): ResponseInterface + public function __invoke( + #[RouteArgument('message')] + string $message = 'Hello!' + ): ResponseInterface { return $this->viewRenderer->render(__DIR__ . '/template', [ 'message' => $message, diff --git a/src/id/guide/views/template-engines.md b/src/id/guide/views/template-engines.md index 08ab054c..708f6141 100644 --- a/src/id/guide/views/template-engines.md +++ b/src/id/guide/views/template-engines.md @@ -150,10 +150,12 @@ final class MarkdownRenderer implements TemplateRendererInterface Register your custom renderer: ```php +use Yiisoft\Container\Reference; + // In configuration 'yiisoft/view' => [ 'renderers' => [ - 'md' => App\View\MarkdownRenderer::class, + 'md' => Reference::to(App\View\MarkdownRenderer::class), ], ], ``` @@ -166,7 +168,7 @@ Now you can use `.md` template files: Welcome, {{username}}! -This is a markdown template with **bold** and *italic* text. +This is a Markdown template with **bold** and *italic* text. - Feature 1 - Feature 2 diff --git a/src/ru/guide/databases/db-migrations.md b/src/ru/guide/databases/db-migrations.md index 057d2896..76ba389d 100644 --- a/src/ru/guide/databases/db-migrations.md +++ b/src/ru/guide/databases/db-migrations.md @@ -1,61 +1,329 @@ # Migrations +During the course of developing and maintaining a database-driven +application, the structure of the database being used evolves just like the +source code does. For example, during the development of an application, a +new table may be found necessary; after the application is deployed to +production, it may be discovered that an index should be created to improve +the query performance; and so on. Because a database structure change often +requires some source code changes, Yii supports the so-called *database +migration* feature that allows you to keep track of database changes in +terms of *database migrations* which are version-controlled together with +the source code. + +The following steps show how database migration can be used by a team during +development: + +1. Tim creates a new migration (e.g. creates a new table, changes a column + definition, etc.). +2. Tim commits the new migration into the source control system (e.g. Git, + Mercurial). +3. Doug updates his repository from the source control system and receives + the new migration. +4. Doug applies the migration to his local development database, thereby + synchronizing his database to reflect the changes that Tim has made. + +And the following steps show how to deploy a new release with database +migrations to production: + +1. Scott creates a release tag for the project repository that contains some + new database migrations. +2. Scott updates the source code on the production server to the release + tag. +3. Scott applies any accumulated database migrations to the production + database. + +Yii provides a set of migration command line tools that allow you to: + +* create new migrations; +* apply migrations; +* revert migrations; +* re-apply migrations; +* show migration history and status. + +All these tools are accessible through the command `yii migrate`. In this +section we will describe in detail how to accomplish various tasks using +these tools. + +> [!TIP] +> Migrations could affect not only database schema but adjust existing data to fit new schema, create RBAC +hierarchy or clean up cache. + +> [!NOTE] +> When manipulating data using a migration you may find that using your Active Record or entity classes +> for this might be useful because some of the logic is already implemented there. Keep in mind however, that in contrast +> to code written in the migrations, whose nature is to stay constant forever, application logic is subject to change. +> So when using Active Record or entity classes in migration code, changes to the logic in the source code +> may accidentally break the existing migrations. For this reason migration code should be kept independent of other +> application logic such. + +## Initial configuration + To use migrations, install [yiisoft/db-migration](https://github.com/yiisoft/db-migration/) package: ```shell -composer require yiisoft/db-migration +make composer require yiisoft/db-migration ``` -### Example usage +Create a directory to store migrations `src/Migration` right in the project +root. -First, configure a DI container. Create `config/common/db.php` with the -following content: +Add the following configuration to `config/common/params.php`: + +```php +'yiisoft/db-migration' => [ + 'newMigrationNamespace' => 'App\\Migration', + 'sourceNamespaces' => ['App\\Migration'], +], +``` + +You need a database connection configured as well. See [Working with +databases](../start/databases.md) for an example of configuring it for +PostgreSQL. + +### Creating a migration + +To create a new empty migration, run the following command: + +```sh +make yii migrate:create +``` + +The required `name` argument gives a brief description about the new +migration. For example, if the migration is about creating a new table named +*news*, you may use the name `create_news_table` and run the following +command: + +``` +make yii migrate:create create_news_table +``` + + +> [!NOTE] +> Because the `name` argument will be used as part of the generated migration class name, +> it should only contain letters, digits, and/or underscore characters. + +The above command will create a new PHP class file named +`src/Migration/M251225221906CreateNewsTable.php`. The file contains the +following code which mainly declares a migration class with the skeleton +code: ```php [ - 'class' => SqliteConnection::class, - '__construct()' => [ - 'dsn' => 'sqlite:' . __DIR__ . '/Data/yiitest.sq3' - ] - ] -]; +use Yiisoft\Db\Migration\MigrationBuilder; +use Yiisoft\Db\Migration\RevertibleMigrationInterface; + +final class M251225221906CreateNewsTable implements RevertibleMigrationInterface +{ + public function up(MigrationBuilder $b): void + { + // TODO: Implement the logic to apply the migration. + } + + public function down(MigrationBuilder $b): void + { + // TODO: Implement the logic to revert the migration. + } +} ``` -Add the following to `config/params.php`: +In the migration class, you are expected to write code in the `up()` method +that makes changes to the database structure. You may also want to write +code in the `down()` method to revert the changes made by `up()`. The `up()` +method is invoked when you upgrade the database with this migration, while +the `down()` method is invoked when you downgrade the database. The +following code shows how you may implement the migration class to create a +`news` table: ```php -... -'yiisoft/db-migration' => [ - 'newMigrationNamespace' => 'App\\Migration', - 'sourceNamespaces' => ['App\\Migration'], -], -... +columnBuilder(); + + $b->createTable('news', [ + 'id' => $cb::uuidPrimaryKey(), + 'title' => $cb::string()->notNull(), + 'content' => $cb::text(), + ]); + } + + public function down(MigrationBuilder $b): void + { + $b->dropTable('news'); + } +} ``` -Now test if it works: +TODO: explain $b and $qb +Below is the list of all these database accessing methods: -```shell -./yii list migrate +### Irreversible migrations + +Not all migrations are reversible. For example, if the `up()` method deletes +a row of a table, you may not be able to recover this row in the `down()` +method. Sometimes, you may be just too lazy to implement the `down()`, +because it is not very common to revert database migrations. In this case, +you should implement `Yiisoft\Db\Migration\MigrationInterface` that has +`up()` only. + + +### Transactional migrations (TODO: update!!!) + +While performing complex DB migrations, it is important to ensure each +migration to either succeed or fail as a whole so that the database can +maintain integrity and consistency. To achieve this goal, it is recommended +that you enclose the DB operations of each migration in a +[transaction](db-dao.md#performing-transactions). + +An even easier way of implementing transactional migrations is to put +migration code in the `safeUp()` and `safeDown()` methods. These two methods +differ from `up()` and `down()` in that they are enclosed implicitly in a +transaction. As a result, if any operation in these methods fails, all +prior operations will be rolled back automatically. + +In the following example, besides creating the `news` table we also insert +an initial row into this table. + +```php +createTable('news', [ + 'id' => $this->primaryKey(), + 'title' => $this->string()->notNull(), + 'content' => $this->text(), + ]); + + $this->insert('news', [ + 'title' => 'test 1', + 'content' => 'content 1', + ]); + } + + public function safeDown() + { + $this->delete('news', ['id' => 1]); + $this->dropTable('news'); + } +} ``` -### Creating a migration +Note that usually when you perform multiple DB operations in `safeUp()`, you +should reverse their execution order in `safeDown()`. In the above example +we first create the table and then insert a row in `safeUp()`; while in +`safeDown()` we first delete the row and then drop the table. + +> Note: Not all DBMS support transactions. And some DB queries cannot be put into a transaction. For some examples, +please refer to [implicit commit](https://dev.mysql.com/doc/refman/5.7/en/implicit-commit.html). If this is the case, +you should still implement `up()` and `down()`, instead. + +TODO: TransactionalMigrationInterface + + + +## TODO: update + +The base migration class [[yii\db\Migration]] exposes a database connection +via the [[yii\db\Migration::db|db]] property. You can use it to manipulate +the database schema using the methods as described in [Working with Database +Schema](db-dao.md#database-schema). + +Rather than using physical types, when creating a table or column you should use *abstract types* +so that your migrations are independent of specific DBMS. The [[yii\db\Schema]] class defines +a set of constants to represent the supported abstract types. These constants are named in the format +of `TYPE_`. For example, `TYPE_PK` refers to auto-incremental primary key type; `TYPE_STRING` +refers to a string type. When a migration is applied to a particular database, the abstract types +will be translated into the corresponding physical types. In the case of MySQL, `TYPE_PK` will be turned +into `int(11) NOT NULL AUTO_INCREMENT PRIMARY KEY`, while `TYPE_STRING` becomes `varchar(255)`. + +You can append additional constraints when using abstract types. In the +above example, ` NOT NULL` is appended to `Schema::TYPE_STRING` to specify +that the column cannot be `null`. -To work with migrations, you can use the provided -[view](https://github.com/yiisoft/db-migration/tree/master/resources/views). +> Info: The mapping between abstract types and physical types is specified by +the [[yii\db\QueryBuilder::$typeMap|$typeMap]] property in each concrete `QueryBuilder` class. + +Since version 2.0.6, you can make use of the newly introduced schema builder +which provides more convenient way of defining column schema. So the +migration above could be written like the following: + +```php +createTable('news', [ + 'id' => $this->primaryKey(), + 'title' => $this->string()->notNull(), + 'content' => $this->text(), + ]); + } + + public function down() + { + $this->dropTable('news'); + } +} +``` + +A list of all available methods for defining the column types is available +in the API documentation of [[yii\db\SchemaBuilderTrait]]. + +> Info: The generated file permissions and ownership will be determined by the current environment. This might lead to +inaccessible files. This could, for example, happen when the migration is created within a docker container +and the files are edited on the host. In this case the `newFileMode` and/or `newFileOwnership` of the MigrateController +can be changed. E.g. in the application config: + ```php + [ + 'migrate' => [ + 'class' => 'yii\console\controllers\MigrateController', + 'newFileOwnership' => '1000:1000', # Default WSL user id + 'newFileMode' => 0660, + ], + ], + ]; + ``` + +## Generating Migrations (TODO: likely is OK but...) + +The command provides a convenient way to create migrations using the +provided +[view](https://github.com/yiisoft/db-migration/tree/master/resources/views): ```shell -./yii migrate:create my_first_table --command=table --fields=name,example --table-comment=my_first_table +make yii migrate:create my_first_table --command=table --fields=name,example --table-comment=my_first_table ``` + + That would generate the following: ```php @@ -95,6 +363,305 @@ final class M240115143455CreateMyFirstTableTable implements RevertibleMigrationI For more information [see](https://github.com/yiisoft/db-migration/tree/master/docs/guide/en) + +## Applying Migrations + +To upgrade a database to its latest structure, you should apply all +available new migrations using the following command: + +``` +yii migrate +``` + +This command will list all migrations that have not been applied so far. If +you confirm that you want to apply these migrations, it will run the `up()` +or `safeUp()` method in every new migration class, one after another, in the +order of their timestamp values. If any of the migrations fails, the command +will quit without applying the rest of the migrations. + +> Tip: In case you don't have command line at your server you may try [web shell](https://github.com/samdark/yii2-webshell) +> extension. + +For each migration that has been successfully applied, the command will +insert a row into a database table named `migration` to record the +successful application of the migration. This will allow the migration tool +to identify which migrations have been applied and which have not. + +> Info: The migration tool will automatically create the `migration` table in the database specified by +the [[yii\console\controllers\MigrateController::db|db]] option of the command. By default, the database +is specified by the `db` [application component](structure-application-components.md). + +Sometimes, you may only want to apply one or a few new migrations, instead +of all available migrations. You can do so by specifying the number of +migrations that you want to apply when running the command. For example, +the following command will try to apply the next three available migrations: + +``` +yii migrate 3 +``` + +You can also explicitly specify a particular migration to which the database +should be migrated by using the `migrate/to` command in one of the following +formats: + +``` +yii migrate/to 150101_185401 # using timestamp to specify the migration +yii migrate/to "2015-01-01 18:54:01" # using a string that can be parsed by strtotime() +yii migrate/to m150101_185401_create_news_table # using full name +yii migrate/to 1392853618 # using UNIX timestamp +``` + +If there are any unapplied migrations earlier than the specified one, they +will all be applied before the specified migration is applied. + +If the specified migration has already been applied before, any later +applied migrations will be reverted. + + +## Reverting Migrations + +To revert (undo) one or multiple migrations that have been applied before, +you can run the following command: + +``` +yii migrate/down # revert the most recently applied migration +yii migrate/down 3 # revert the most 3 recently applied migrations +``` + +> Note: Not all migrations are reversible. Trying to revert such migrations will cause an error and stop the +entire reverting process. + + +## Redoing Migrations + +Redoing migrations means first reverting the specified migrations and then +applying again. This can be done as follows: + +``` +yii migrate/redo # redo the last applied migration +yii migrate/redo 3 # redo the last 3 applied migrations +``` + +> Note: If a migration is not reversible, you will not be able to redo it. + +## Refreshing Migrations + +Since Yii 2.0.13 you can delete all tables and foreign keys from the +database and apply all migrations from the beginning. + +``` +yii migrate/fresh # truncate the database and apply all migrations from the beginning +``` + +## Listing Migrations + +To list which migrations have been applied and which are not, you may use +the following commands: + +``` +yii migrate/history # showing the last 10 applied migrations +yii migrate/history 5 # showing the last 5 applied migrations +yii migrate/history all # showing all applied migrations + +yii migrate/new # showing the first 10 new migrations +yii migrate/new 5 # showing the first 5 new migrations +yii migrate/new all # showing all new migrations +``` + + +## Modifying Migration History + +Instead of actually applying or reverting migrations, sometimes you may +simply want to mark that your database has been upgraded to a particular +migration. This often happens when you manually change the database to a +particular state and you do not want the migration(s) for that change to be +re-applied later. You can achieve this goal with the following command: + +``` +yii migrate/mark 150101_185401 # using timestamp to specify the migration +yii migrate/mark "2015-01-01 18:54:01" # using a string that can be parsed by strtotime() +yii migrate/mark m150101_185401_create_news_table # using full name +yii migrate/mark 1392853618 # using UNIX timestamp +``` + +The command will modify the `migration` table by adding or deleting certain +rows to indicate that the database has been applied migrations to the +specified one. No migrations will be applied or reverted by this command. + + +## Customizing Migrations + +There are several ways to customize the migration command. + + +### Using Command Line Options + +The migration command comes with a few command-line options that can be used +to customize its behaviors: + +* `interactive`: boolean (defaults to `true`), specifies whether to perform + migrations in an interactive mode. When this is `true`, the user will be + prompted before the command performs certain actions. You may want to set + this to `false` if the command is being used in a background process. + +* `migrationPath`: string|array (defaults to `@app/migrations`), specifies + the directory storing all migration class files. This can be specified as + either a directory path or a path [alias](concept-aliases.md). Note that + the directory must exist, or the command may trigger an error. Since + version 2.0.12 an array can be specified for loading migrations from + multiple sources. + +* `migrationTable`: string (defaults to `migration`), specifies the name of + the database table for storing migration history information. The table + will be automatically created by the command if it does not exist. You + may also manually create it using the structure `version varchar(255) + primary key, apply_time integer`. + +* `db`: string (defaults to `db`), specifies the ID of the database + [application component](structure-application-components.md). It + represents the database that will be migrated using this command. + +* `templateFile`: string (defaults to `@yii/views/migration.php`), specifies + the path of the template file that is used for generating skeleton + migration class files. This can be specified as either a file path or a + path [alias](concept-aliases.md). The template file is a PHP script in + which you can use a predefined variable named `$className` to get the + migration class name. + +* `generatorTemplateFiles`: array (defaults to `[ + 'create_table' => '@yii/views/createTableMigration.php', + 'drop_table' => '@yii/views/dropTableMigration.php', + 'add_column' => '@yii/views/addColumnMigration.php', + 'drop_column' => '@yii/views/dropColumnMigration.php', + 'create_junction' => '@yii/views/createTableMigration.php' + ]`), specifies template files for generating migration code. See "[Generating Migrations](#generating-migrations)" + for more details. + +* `fields`: array of column definition strings used for creating migration + code. Defaults to `[]`. The format of each definition is + `COLUMN_NAME:COLUMN_TYPE:COLUMN_DECORATOR`. For example, + `--fields=name:string(12):notNull` produces a string column of size 12 + which is not `null`. + +The following example shows how you can use these options. + +For example, if we want to migrate a `forum` module whose migration files +are located within the module's `migrations` directory, we can use the +following command: + +``` +# migrate the migrations in a forum module non-interactively +yii migrate --migrationPath=@app/modules/forum/migrations --interactive=0 +``` + +### Separated Migrations + + +Sometimes using single migration history for all project migrations is not +desirable. For example: you may install some 'blog' extension, which +contains fully separated functionality and contain its own migrations, which +should not affect the ones dedicated to main project functionality. + +If you want several migrations to be applied and tracked down completely +separated from each other, you can configure multiple migration commands +which will use different namespaces and migration history tables: + +```php +return [ + 'controllerMap' => [ + // Common migrations for the whole application + 'migrate-app' => [ + 'class' => 'yii\console\controllers\MigrateController', + 'migrationNamespaces' => ['app\migrations'], + 'migrationTable' => 'migration_app', + 'migrationPath' => null, + ], + // Migrations for the specific project's module + 'migrate-module' => [ + 'class' => 'yii\console\controllers\MigrateController', + 'migrationNamespaces' => ['module\migrations'], + 'migrationTable' => 'migration_module', + 'migrationPath' => null, + ], + // Migrations for the specific extension + 'migrate-rbac' => [ + 'class' => 'yii\console\controllers\MigrateController', + 'migrationPath' => '@yii/rbac/migrations', + 'migrationTable' => 'migration_rbac', + ], + ], +]; +``` + +Note that to synchronize database you now need to run multiple commands +instead of one: + +``` +yii migrate-app +yii migrate-module +yii migrate-rbac +``` + +## Migrating Multiple Databases + +By default, migrations are applied to the same database specified by the +`db` [application component](structure-application-components.md). If you +want them to be applied to a different database, you may specify the `db` +command-line option like shown below, + +``` +yii migrate --db=db2 +``` + +The above command will apply migrations to the `db2` database. + +Sometimes it may happen that you want to apply *some* of the migrations to +one database, while some others to another database. To achieve this goal, +when implementing a migration class you should explicitly specify the DB +component ID that the migration would use, like the following: + +```php +db = 'db2'; + parent::init(); + } +} +``` + +The above migration will be applied to `db2`, even if you specify a +different database through the `db` command-line option. Note that the +migration history will still be recorded in the database specified by the +`db` command-line option. + +If you have multiple migrations that use the same database, it is +recommended that you create a base migration class with the above `init()` +code. Then each migration class can extend from this base class. + +> Tip: Besides setting the [[yii\db\Migration::db|db]] property, you can also operate on different databases +by creating new database connections to them in your migration classes. You then use the [DAO methods](db-dao.md) +with these connections to manipulate different databases. + +Another strategy that you can take to migrate multiple databases is to keep +migrations for different databases in different migration paths. Then you +can migrate these databases in separate commands like the following: + +``` +yii migrate --migrationPath=@app/migrations/db1 --db=db1 +yii migrate --migrationPath=@app/migrations/db2 --db=db2 +... +``` + +The first command will apply migrations in `@app/migrations/db1` to the +`db1` database, the second command will apply migrations in +`@app/migrations/db2` to `db2`, and so on. + ### Upgrading from Yii2 Migrations in Yii2 and the diff --git a/src/ru/guide/start/creating-project.md b/src/ru/guide/start/creating-project.md index efde5e36..52ba1bab 100644 --- a/src/ru/guide/start/creating-project.md +++ b/src/ru/guide/start/creating-project.md @@ -6,7 +6,7 @@ dev server with everything installed locally. > [!NOTE] > If you want to use another web server, -> see ["Configuring web servers"](../../../cookbook/en/configuring-webservers/general.md). +> see ["Configuring web servers"](../../cookbook/configuring-webservers/general.md). We recommend starting with a project template that's a minimal working Yii project implementing some basic features. It can serve as a good starting @@ -19,10 +19,11 @@ You can create a new project from a template using the composer create-project yiisoft/app your_project ``` -Docker users can run the following command: - +Docker users can run the following commands: + ```sh docker run --rm -it -v "$(pwd):/app" composer/composer create-project yiisoft/app your_project +sudo chown -R $(id -u):$(id -g) your_project ``` This installs the latest stable version of the Yii project template in a diff --git a/src/ru/guide/start/databases.md b/src/ru/guide/start/databases.md index b4be1d4b..0c9a8010 100644 --- a/src/ru/guide/start/databases.md +++ b/src/ru/guide/start/databases.md @@ -86,13 +86,10 @@ list. Then rebuild PHP image with `make build && make down && make up`. Now that we have the database, it's time to define the connection. -Let's use latest versions to be released. Change your `minimum-stability` to -`dev` in `composer.json` first. - -Then we need a package to be installed: +First we need a package to be installed: ```sh -make composer require yiisoft/db-pgsql dev-master +make composer require yiisoft/db-pgsql ``` Now create `config/common/di/db-pgsql.php`: @@ -152,7 +149,7 @@ the current state and which migrations remain to be applied. To use migrations we need another package installed: ```sh -composer require yiisoft/db-migration dev-master +make composer require yiisoft/db-migration ``` Create a directory to store migrations `src/Migration` right in the project @@ -178,9 +175,6 @@ namespace App\Migration; use Yiisoft\Db\Migration\MigrationBuilder; use Yiisoft\Db\Migration\RevertibleMigrationInterface; -/** - * Class M251102141707Page - */ final class M251102141707Page implements RevertibleMigrationInterface { public function up(MigrationBuilder $b): void @@ -221,6 +215,8 @@ Now that you have a table it is time to define an entity in the code. Create ```php responseFactory->createResponse(); $response->getBody()->write('The message is: ' . Html::encode($message)); @@ -155,8 +157,10 @@ final readonly class Action private ViewRenderer $viewRenderer, ) {} - #[RouteArgument('message')] - public function __invoke(string $message = 'Hello!'): ResponseInterface + public function __invoke( + #[RouteArgument('message')] + string $message = 'Hello!' + ): ResponseInterface { return $this->viewRenderer->render(__DIR__ . '/template', [ 'message' => $message, diff --git a/src/ru/guide/views/template-engines.md b/src/ru/guide/views/template-engines.md index 08ab054c..708f6141 100644 --- a/src/ru/guide/views/template-engines.md +++ b/src/ru/guide/views/template-engines.md @@ -150,10 +150,12 @@ final class MarkdownRenderer implements TemplateRendererInterface Register your custom renderer: ```php +use Yiisoft\Container\Reference; + // In configuration 'yiisoft/view' => [ 'renderers' => [ - 'md' => App\View\MarkdownRenderer::class, + 'md' => Reference::to(App\View\MarkdownRenderer::class), ], ], ``` @@ -166,7 +168,7 @@ Now you can use `.md` template files: Welcome, {{username}}! -This is a markdown template with **bold** and *italic* text. +This is a Markdown template with **bold** and *italic* text. - Feature 1 - Feature 2 From 850f0c39d3c4650517a62676663aaf54a9782caf Mon Sep 17 00:00:00 2001 From: vjik <525501+vjik@users.noreply.github.com> Date: Sat, 27 Dec 2025 06:16:55 +0000 Subject: [PATCH 3/8] Update translation --- .../po/es/guide_start_databases.md.po | 34 +++++++++--------- .../po/id/guide_start_databases.md.po | 35 +++++++++---------- .../po/ru/guide_start_databases.md.po | 34 +++++++++--------- .../pot/guide_start_databases.md.pot | 34 +++++++++--------- 4 files changed, 68 insertions(+), 69 deletions(-) diff --git a/_translations/po/es/guide_start_databases.md.po b/_translations/po/es/guide_start_databases.md.po index 7ac96a09..560aedee 100644 --- a/_translations/po/es/guide_start_databases.md.po +++ b/_translations/po/es/guide_start_databases.md.po @@ -6,7 +6,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" -"POT-Creation-Date: 2025-12-27 06:04+0000\n" +"POT-Creation-Date: 2025-12-27 06:16+0000\n" "PO-Revision-Date: 2025-09-04 11:19+0500\n" "Last-Translator: Automatically generated\n" "Language-Team: none\n" @@ -16,6 +16,22 @@ msgstr "" "Content-Transfer-Encoding: 8bit\n" "Plural-Forms: nplurals=2; plural=(n != 1);\n" +#. type: Fenced code block (sh) +#: ../src/guide/databases/db-migrations.md ../src/guide/start/databases.md +#, no-wrap +msgid "make composer require yiisoft/db-migration\n" +msgstr "" + +#. type: Fenced code block (php) +#: ../src/guide/databases/db-migrations.md ../src/guide/start/databases.md +#, no-wrap +msgid "" +"'yiisoft/db-migration' => [\n" +" 'newMigrationNamespace' => 'App\\\\Migration',\n" +" 'sourceNamespaces' => ['App\\\\Migration'],\n" +"],\n" +msgstr "" + #. type: Title # #: ../src/guide/index.md ../src/guide/start/databases.md #, no-wrap @@ -252,27 +268,11 @@ msgstr "" msgid "To use migrations we need another package installed:" msgstr "" -#. type: Fenced code block (sh) -#: ../src/guide/start/databases.md -#, no-wrap -msgid "make composer require yiisoft/db-migration\n" -msgstr "" - #. type: Plain text #: ../src/guide/start/databases.md msgid "Create a directory to store migrations `src/Migration` right in the project root. Add the following configuration to `config/common/params.php`:" msgstr "" -#. type: Fenced code block (php) -#: ../src/guide/start/databases.md -#, no-wrap -msgid "" -"'yiisoft/db-migration' => [\n" -" 'newMigrationNamespace' => 'App\\\\Migration',\n" -" 'sourceNamespaces' => ['App\\\\Migration'],\n" -"],\n" -msgstr "" - #. type: Plain text #: ../src/guide/start/databases.md msgid "Now you can use `make yii migrate:create page` to create a new migration. For our example we need a `page` table with some columns:" diff --git a/_translations/po/id/guide_start_databases.md.po b/_translations/po/id/guide_start_databases.md.po index 079b1620..e08047e9 100644 --- a/_translations/po/id/guide_start_databases.md.po +++ b/_translations/po/id/guide_start_databases.md.po @@ -6,7 +6,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" -"POT-Creation-Date: 2025-12-27 06:04+0000\n" +"POT-Creation-Date: 2025-12-27 06:16+0000\n" "PO-Revision-Date: 2025-09-04 11:19+0500\n" "Last-Translator: Automatically generated\n" "Language-Team: none\n" @@ -15,6 +15,22 @@ msgstr "" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: 8bit\n" +#. type: Fenced code block (sh) +#: ../src/guide/databases/db-migrations.md ../src/guide/start/databases.md +#, fuzzy, no-wrap +msgid "make composer require yiisoft/db-migration\n" +msgstr "composer require yiisoft/cache\n" + +#. type: Fenced code block (php) +#: ../src/guide/databases/db-migrations.md ../src/guide/start/databases.md +#, no-wrap +msgid "" +"'yiisoft/db-migration' => [\n" +" 'newMigrationNamespace' => 'App\\\\Migration',\n" +" 'sourceNamespaces' => ['App\\\\Migration'],\n" +"],\n" +msgstr "" + #. type: Title # #: ../src/guide/index.md ../src/guide/start/databases.md #, no-wrap @@ -252,28 +268,11 @@ msgstr "" msgid "To use migrations we need another package installed:" msgstr "" -#. type: Fenced code block (sh) -#: ../src/guide/start/databases.md -#, fuzzy, no-wrap -#| msgid "composer require yiisoft/cache\n" -msgid "make composer require yiisoft/db-migration\n" -msgstr "composer require yiisoft/cache\n" - #. type: Plain text #: ../src/guide/start/databases.md msgid "Create a directory to store migrations `src/Migration` right in the project root. Add the following configuration to `config/common/params.php`:" msgstr "" -#. type: Fenced code block (php) -#: ../src/guide/start/databases.md -#, no-wrap -msgid "" -"'yiisoft/db-migration' => [\n" -" 'newMigrationNamespace' => 'App\\\\Migration',\n" -" 'sourceNamespaces' => ['App\\\\Migration'],\n" -"],\n" -msgstr "" - #. type: Plain text #: ../src/guide/start/databases.md msgid "Now you can use `make yii migrate:create page` to create a new migration. For our example we need a `page` table with some columns:" diff --git a/_translations/po/ru/guide_start_databases.md.po b/_translations/po/ru/guide_start_databases.md.po index b2d8a534..0ec59a3c 100644 --- a/_translations/po/ru/guide_start_databases.md.po +++ b/_translations/po/ru/guide_start_databases.md.po @@ -6,7 +6,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" -"POT-Creation-Date: 2025-12-27 06:04+0000\n" +"POT-Creation-Date: 2025-12-27 06:16+0000\n" "PO-Revision-Date: 2025-09-04 11:19+0500\n" "Last-Translator: Automatically generated\n" "Language-Team: none\n" @@ -16,6 +16,22 @@ msgstr "" "Content-Transfer-Encoding: 8bit\n" "Plural-Forms: nplurals=3; plural=(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2);\n" +#. type: Fenced code block (sh) +#: ../src/guide/databases/db-migrations.md ../src/guide/start/databases.md +#, fuzzy, no-wrap +msgid "make composer require yiisoft/db-migration\n" +msgstr "composer install yiisoft/security\n" + +#. type: Fenced code block (php) +#: ../src/guide/databases/db-migrations.md ../src/guide/start/databases.md +#, no-wrap +msgid "" +"'yiisoft/db-migration' => [\n" +" 'newMigrationNamespace' => 'App\\\\Migration',\n" +" 'sourceNamespaces' => ['App\\\\Migration'],\n" +"],\n" +msgstr "" + #. type: Title # #: ../src/guide/index.md ../src/guide/start/databases.md #, no-wrap @@ -256,27 +272,11 @@ msgstr "" msgid "To use migrations we need another package installed:" msgstr "" -#. type: Fenced code block (sh) -#: ../src/guide/start/databases.md -#, fuzzy, no-wrap -msgid "make composer require yiisoft/db-migration\n" -msgstr "composer install yiisoft/security\n" - #. type: Plain text #: ../src/guide/start/databases.md msgid "Create a directory to store migrations `src/Migration` right in the project root. Add the following configuration to `config/common/params.php`:" msgstr "" -#. type: Fenced code block (php) -#: ../src/guide/start/databases.md -#, no-wrap -msgid "" -"'yiisoft/db-migration' => [\n" -" 'newMigrationNamespace' => 'App\\\\Migration',\n" -" 'sourceNamespaces' => ['App\\\\Migration'],\n" -"],\n" -msgstr "" - #. type: Plain text #: ../src/guide/start/databases.md msgid "Now you can use `make yii migrate:create page` to create a new migration. For our example we need a `page` table with some columns:" diff --git a/_translations/pot/guide_start_databases.md.pot b/_translations/pot/guide_start_databases.md.pot index fa4684f9..3ddde79d 100644 --- a/_translations/pot/guide_start_databases.md.pot +++ b/_translations/pot/guide_start_databases.md.pot @@ -7,7 +7,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" -"POT-Creation-Date: 2025-12-27 06:04+0000\n" +"POT-Creation-Date: 2025-12-27 06:16+0000\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -16,6 +16,22 @@ msgstr "" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: 8bit\n" +#. type: Fenced code block (sh) +#: ../src/guide/databases/db-migrations.md ../src/guide/start/databases.md +#, no-wrap +msgid "make composer require yiisoft/db-migration\n" +msgstr "" + +#. type: Fenced code block (php) +#: ../src/guide/databases/db-migrations.md ../src/guide/start/databases.md +#, no-wrap +msgid "" +"'yiisoft/db-migration' => [\n" +" 'newMigrationNamespace' => 'App\\\\Migration',\n" +" 'sourceNamespaces' => ['App\\\\Migration'],\n" +"],\n" +msgstr "" + #. type: Title # #: ../src/guide/index.md ../src/guide/start/databases.md #, no-wrap @@ -279,12 +295,6 @@ msgstr "" msgid "To use migrations we need another package installed:" msgstr "" -#. type: Fenced code block (sh) -#: ../src/guide/start/databases.md -#, no-wrap -msgid "make composer require yiisoft/db-migration\n" -msgstr "" - #. type: Plain text #: ../src/guide/start/databases.md msgid "" @@ -292,16 +302,6 @@ msgid "" "root. Add the following configuration to `config/common/params.php`:" msgstr "" -#. type: Fenced code block (php) -#: ../src/guide/start/databases.md -#, no-wrap -msgid "" -"'yiisoft/db-migration' => [\n" -" 'newMigrationNamespace' => 'App\\\\Migration',\n" -" 'sourceNamespaces' => ['App\\\\Migration'],\n" -"],\n" -msgstr "" - #. type: Plain text #: ../src/guide/start/databases.md msgid "" From b427df4c96ca648dc09fcee74ba32bc60e1f05b9 Mon Sep 17 00:00:00 2001 From: samdark <47294+samdark@users.noreply.github.com> Date: Sat, 27 Dec 2025 07:56:43 +0000 Subject: [PATCH 4/8] Update translation --- .../po/es/guide_databases_db-migrations.md.po | 916 +++++++++++++- .../po/id/guide_databases_db-migrations.md.po | 915 +++++++++++++- .../po/ru/guide_databases_db-migrations.md.po | 932 +++++++++++++- .../pot/guide_databases_db-migrations.md.pot | 1105 ++++++++++++++++- 4 files changed, 3646 insertions(+), 222 deletions(-) diff --git a/_translations/po/es/guide_databases_db-migrations.md.po b/_translations/po/es/guide_databases_db-migrations.md.po index c41ea3c3..7f9281c7 100644 --- a/_translations/po/es/guide_databases_db-migrations.md.po +++ b/_translations/po/es/guide_databases_db-migrations.md.po @@ -6,7 +6,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" -"POT-Creation-Date: 2025-12-27 07:40+0000\n" +"POT-Creation-Date: 2025-12-27 07:55+0000\n" "PO-Revision-Date: 2025-09-04 11:19+0500\n" "Last-Translator: Automatically generated\n" "Language-Team: none\n" @@ -22,26 +22,198 @@ msgstr "" msgid "Migrations" msgstr "" +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +msgid "During the course of developing and maintaining a database-driven application, the structure of the database being used evolves just like the source code does. For example, during the development of an application, a new table may be found necessary; after the application is deployed to production, it may be discovered that an index should be created to improve the query performance; and so on. Because a database structure change often requires some source code changes, Yii supports the so-called *database migration* feature that allows you to keep track of database changes in terms of *database migrations* which are version-controlled together with the source code." +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +msgid "The following steps show how database migration can be used by a team during development:" +msgstr "" + +#. type: Bullet: '1. ' +#: ../src/guide/databases/db-migrations.md +msgid "Tim creates a new migration (e.g. creates a new table, changes a column definition, etc.)." +msgstr "" + +#. type: Bullet: '2. ' +#: ../src/guide/databases/db-migrations.md +msgid "Tim commits the new migration into the source control system (e.g. Git, Mercurial)." +msgstr "" + +#. type: Bullet: '3. ' +#: ../src/guide/databases/db-migrations.md +msgid "Doug updates his repository from the source control system and receives the new migration." +msgstr "" + +#. type: Bullet: '4. ' +#: ../src/guide/databases/db-migrations.md +msgid "Doug applies the migration to his local development database, thereby synchronizing his database to reflect the changes that Tim has made." +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +msgid "And the following steps show how to deploy a new release with database migrations to production:" +msgstr "" + +#. type: Bullet: '1. ' +#: ../src/guide/databases/db-migrations.md +msgid "Scott creates a release tag for the project repository that contains some new database migrations." +msgstr "" + +#. type: Bullet: '2. ' +#: ../src/guide/databases/db-migrations.md +msgid "Scott updates the source code on the production server to the release tag." +msgstr "" + +#. type: Bullet: '3. ' +#: ../src/guide/databases/db-migrations.md +msgid "Scott applies any accumulated database migrations to the production database." +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +msgid "Yii provides a set of migration command line tools that allow you to:" +msgstr "" + +#. type: Bullet: '* ' +#: ../src/guide/databases/db-migrations.md +msgid "create new migrations;" +msgstr "" + +#. type: Bullet: '* ' +#: ../src/guide/databases/db-migrations.md +msgid "apply migrations;" +msgstr "" + +#. type: Bullet: '* ' +#: ../src/guide/databases/db-migrations.md +msgid "revert migrations;" +msgstr "" + +#. type: Bullet: '* ' +#: ../src/guide/databases/db-migrations.md +msgid "re-apply migrations;" +msgstr "" + +#. type: Bullet: '* ' +#: ../src/guide/databases/db-migrations.md +msgid "show migration history and status." +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +msgid "All these tools are accessible through the command `yii migrate`. In this section we will describe in detail how to accomplish various tasks using these tools." +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +#, no-wrap +msgid "" +"> [!TIP]\n" +"> Migrations could affect not only database schema but adjust existing data to fit new schema, create RBAC\n" +"hierarchy or clean up cache.\n" +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +#, no-wrap +msgid "" +"> [!NOTE]\n" +"> When manipulating data using a migration you may find that using your Active Record or entity classes\n" +"> for this might be useful because some of the logic is already implemented there. Keep in mind however, that in contrast\n" +"> to code written in the migrations, whose nature is to stay constant forever, application logic is subject to change.\n" +"> So when using Active Record or entity classes in migration code, changes to the logic in the source code\n" +"> may accidentally break the existing migrations. For this reason migration code should be kept independent of other\n" +"> application logic such.\n" +msgstr "" + +#. type: Title ## +#: ../src/guide/databases/db-migrations.md +#, fuzzy, no-wrap +#| msgid "Introduction +" +msgid "Initial configuration" +msgstr "Introducción" + #. type: Plain text #: ../src/guide/databases/db-migrations.md msgid "To use migrations, install [yiisoft/db-migration](https://github.com/yiisoft/db-migration/) package:" msgstr "" -#. type: Fenced code block (shell) +#. type: Fenced code block (sh) +#: ../src/guide/databases/db-migrations.md ../src/guide/start/databases.md +#, no-wrap +msgid "make composer require yiisoft/db-migration\n" +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +msgid "Create a directory to store migrations `src/Migration` right in the project root." +msgstr "" + +#. type: Plain text #: ../src/guide/databases/db-migrations.md +msgid "Add the following configuration to `config/common/params.php`:" +msgstr "" + +#. type: Fenced code block (php) +#: ../src/guide/databases/db-migrations.md ../src/guide/start/databases.md #, no-wrap -msgid "composer require yiisoft/db-migration\n" +msgid "" +"'yiisoft/db-migration' => [\n" +" 'newMigrationNamespace' => 'App\\\\Migration',\n" +" 'sourceNamespaces' => ['App\\\\Migration'],\n" +"],\n" +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +msgid "You need a database connection configured as well. See [Working with databases](../start/databases.md) for an example of configuring it for PostgreSQL." msgstr "" #. type: Title ### #: ../src/guide/databases/db-migrations.md #, no-wrap -msgid "Example usage" +msgid "Creating a migration" +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +#, fuzzy +#| msgid "Events are raised like the following:" +msgid "To create a new empty migration, run the following command:" +msgstr "Los eventos se lanzan de la siguiente forma:" + +#. type: Fenced code block (sh) +#: ../src/guide/databases/db-migrations.md +#, no-wrap +msgid "make yii migrate:create \n" +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +msgid "The required `name` argument gives a brief description about the new migration. For example, if the migration is about creating a new table named *news*, you may use the name `create_news_table` and run the following command:" +msgstr "" + +#. type: Fenced code block +#: ../src/guide/databases/db-migrations.md +#, no-wrap +msgid "make yii migrate:create create_news_table\n" +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +#, no-wrap +msgid "" +"> [!NOTE]\n" +"> Because the `name` argument will be used as part of the generated migration class name,\n" +"> it should only contain letters, digits, and/or underscore characters.\n" msgstr "" #. type: Plain text #: ../src/guide/databases/db-migrations.md -msgid "First, configure a DI container. Create `config/common/db.php` with the following content:" +msgid "The above command will create a new PHP class file named `src/Migration/M251225221906CreateNewsTable.php`. The file contains the following code which mainly declares a migration class with the skeleton code:" msgstr "" #. type: Fenced code block (php) @@ -52,67 +224,101 @@ msgid "" "\n" "declare(strict_types=1);\n" "\n" -"use Yiisoft\\Db\\Connection\\ConnectionInterface;\n" -"use Yiisoft\\Db\\Sqlite\\Connection as SqliteConnection;\n" +"namespace App\\Migration;\n" "\n" -"return [\n" -" ConnectionInterface::class => [\n" -" 'class' => SqliteConnection::class,\n" -" '__construct()' => [\n" -" 'dsn' => 'sqlite:' . __DIR__ . '/Data/yiitest.sq3'\n" -" ]\n" -" ]\n" -"];\n" +"use Yiisoft\\Db\\Migration\\MigrationBuilder;\n" +"use Yiisoft\\Db\\Migration\\RevertibleMigrationInterface;\n" +"\n" +"final class M251225221906CreateNewsTable implements RevertibleMigrationInterface\n" +"{\n" +" public function up(MigrationBuilder $b): void\n" +" {\n" +" // TODO: Implement the logic to apply the migration.\n" +" }\n" +"\n" +" public function down(MigrationBuilder $b): void\n" +" {\n" +" // TODO: Implement the logic to revert the migration.\n" +" }\n" +"}\n" msgstr "" #. type: Plain text #: ../src/guide/databases/db-migrations.md -msgid "Add the following to `config/params.php`:" +msgid "In the migration class, you are expected to write code in the `up()` method that makes changes to the database structure. You may also want to write code in the `down()` method to revert the changes made by `up()`. The `up()` method is invoked when you upgrade the database with this migration, while the `down()` method is invoked when you downgrade the database. The following code shows how you may implement the migration class to create a `news` table:" msgstr "" #. type: Fenced code block (php) #: ../src/guide/databases/db-migrations.md #, no-wrap msgid "" -"...\n" -"'yiisoft/db-migration' => [\n" -" 'newMigrationNamespace' => 'App\\\\Migration',\n" -" 'sourceNamespaces' => ['App\\\\Migration'],\n" -"],\n" -"...\n" +"columnBuilder();\n" +"\n" +" $b->createTable('news', [\n" +" 'id' => $cb::uuidPrimaryKey(),\n" +" 'title' => $cb::string()->notNull(),\n" +" 'content' => $cb::text(),\n" +" ]);\n" +" }\n" +"\n" +" public function down(MigrationBuilder $b): void\n" +" {\n" +" $b->dropTable('news');\n" +" }\n" +"}\n" msgstr "" #. type: Plain text #: ../src/guide/databases/db-migrations.md -msgid "Now test if it works:" +#, no-wrap +msgid "" +"TODO: explain $b and $qb\n" +"Below is the list of all these database accessing methods:\n" msgstr "" -#. type: Fenced code block (shell) +#. type: Title ### #: ../src/guide/databases/db-migrations.md #, no-wrap -msgid "./yii list migrate\n" +msgid "Irreversible migrations" +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +msgid "Not all migrations are reversible. For example, if the `up()` method deletes a row of a table, you may not be able to recover this row in the `down()` method. Sometimes, you may be just too lazy to implement the `down()`, because it is not very common to revert database migrations. In this case, you should implement `Yiisoft\\Db\\Migration\\MigrationInterface` that has `up()` only." msgstr "" #. type: Title ### #: ../src/guide/databases/db-migrations.md #, no-wrap -msgid "Creating a migration" +msgid "Transactional migrations (TODO: update!!!)" msgstr "" #. type: Plain text #: ../src/guide/databases/db-migrations.md -msgid "To work with migrations, you can use the provided [view](https://github.com/yiisoft/db-migration/tree/master/resources/views)." +msgid "While performing complex DB migrations, it is important to ensure each migration to either succeed or fail as a whole so that the database can maintain integrity and consistency. To achieve this goal, it is recommended that you enclose the DB operations of each migration in a [transaction](db-dao.md#performing-transactions)." msgstr "" -#. type: Fenced code block (shell) +#. type: Plain text #: ../src/guide/databases/db-migrations.md -#, no-wrap -msgid "./yii migrate:create my_first_table --command=table --fields=name,example --table-comment=my_first_table\n" +msgid "An even easier way of implementing transactional migrations is to put migration code in the `safeUp()` and `safeDown()` methods. These two methods differ from `up()` and `down()` in that they are enclosed implicitly in a transaction. As a result, if any operation in these methods fails, all prior operations will be rolled back automatically." msgstr "" #. type: Plain text #: ../src/guide/databases/db-migrations.md -msgid "That would generate the following:" +msgid "In the following example, besides creating the `news` table we also insert an initial row into this table." msgstr "" #. type: Fenced code block (php) @@ -121,49 +327,655 @@ msgstr "" msgid "" "createTable('news', [\n" +" 'id' => $this->primaryKey(),\n" +" 'title' => $this->string()->notNull(),\n" +" 'content' => $this->text(),\n" +" ]);\n" "\n" -"use Yiisoft\\Db\\Migration\\MigrationBuilder;\n" -"use Yiisoft\\Db\\Migration\\RevertibleMigrationInterface;\n" -"use Yiisoft\\Db\\Migration\\TransactionalMigrationInterface;\n" +" $this->insert('news', [\n" +" 'title' => 'test 1',\n" +" 'content' => 'content 1',\n" +" ]);\n" +" }\n" "\n" -"/**\n" -" * Handles the creation of a table `my_first_table`.\n" -" */\n" -"final class M240115143455CreateMyFirstTableTable implements RevertibleMigrationInterface, TransactionalMigrationInterface\n" +" public function safeDown()\n" +" {\n" +" $this->delete('news', ['id' => 1]);\n" +" $this->dropTable('news');\n" +" }\n" +"}\n" +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +msgid "Note that usually when you perform multiple DB operations in `safeUp()`, you should reverse their execution order in `safeDown()`. In the above example we first create the table and then insert a row in `safeUp()`; while in `safeDown()` we first delete the row and then drop the table." +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +#, no-wrap +msgid "" +"> Note: Not all DBMS support transactions. And some DB queries cannot be put into a transaction. For some examples,\n" +"please refer to [implicit commit](https://dev.mysql.com/doc/refman/5.7/en/implicit-commit.html). If this is the case,\n" +"you should still implement `up()` and `down()`, instead.\n" +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +#, no-wrap +msgid "TODO: TransactionalMigrationInterface\n" +msgstr "" + +#. type: Title ## +#: ../src/guide/databases/db-migrations.md +#, no-wrap +msgid "TODO: update" +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +msgid "The base migration class [[yii\\db\\Migration]] exposes a database connection via the [[yii\\db\\Migration::db|db]] property. You can use it to manipulate the database schema using the methods as described in [Working with Database Schema](db-dao.md#database-schema)." +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +#, no-wrap +msgid "" +"Rather than using physical types, when creating a table or column you should use *abstract types*\n" +"so that your migrations are independent of specific DBMS. The [[yii\\db\\Schema]] class defines\n" +"a set of constants to represent the supported abstract types. These constants are named in the format\n" +"of `TYPE_`. For example, `TYPE_PK` refers to auto-incremental primary key type; `TYPE_STRING`\n" +"refers to a string type. When a migration is applied to a particular database, the abstract types\n" +"will be translated into the corresponding physical types. In the case of MySQL, `TYPE_PK` will be turned\n" +"into `int(11) NOT NULL AUTO_INCREMENT PRIMARY KEY`, while `TYPE_STRING` becomes `varchar(255)`.\n" +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +msgid "You can append additional constraints when using abstract types. In the above example, ` NOT NULL` is appended to `Schema::TYPE_STRING` to specify that the column cannot be `null`." +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +#, no-wrap +msgid "" +"> Info: The mapping between abstract types and physical types is specified by\n" +"the [[yii\\db\\QueryBuilder::$typeMap|$typeMap]] property in each concrete `QueryBuilder` class.\n" +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +msgid "Since version 2.0.6, you can make use of the newly introduced schema builder which provides more convenient way of defining column schema. So the migration above could be written like the following:" +msgstr "" + +#. type: Fenced code block (php) +#: ../src/guide/databases/db-migrations.md +#, no-wrap +msgid "" +"createTable('my_first_table', [\n" -" 'id' => $b->primaryKey(),\n" -" 'name',\n" -" 'example',\n" +" $this->createTable('news', [\n" +" 'id' => $this->primaryKey(),\n" +" 'title' => $this->string()->notNull(),\n" +" 'content' => $this->text(),\n" " ]);\n" -" \n" -" $b->addCommentOnTable('my_first_table', 'dest');\n" " }\n" "\n" -" public function down(MigrationBuilder $b): void\n" +" public function down()\n" " {\n" -" $b->dropTable('my_first_table');\n" +" $this->dropTable('news');\n" " }\n" "}\n" msgstr "" #. type: Plain text #: ../src/guide/databases/db-migrations.md -msgid "For more information [see](https://github.com/yiisoft/db-migration/tree/master/docs/guide/en)" +msgid "A list of all available methods for defining the column types is available in the API documentation of [[yii\\db\\SchemaBuilderTrait]]." +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +#, no-wrap +msgid "" +"> Info: The generated file permissions and ownership will be determined by the current environment. This might lead to\n" +"inaccessible files. This could, for example, happen when the migration is created within a docker container\n" +"and the files are edited on the host. In this case the `newFileMode` and/or `newFileOwnership` of the MigrateController\n" +"can be changed. E.g. in the application config:\n" +msgstr "" + +#. type: Fenced code block (php) +#: ../src/guide/databases/db-migrations.md +#, no-wrap +msgid "" +" [\n" +" 'migrate' => [\n" +" 'class' => 'yii\\console\\controllers\\MigrateController',\n" +" 'newFileOwnership' => '1000:1000', # Default WSL user id\n" +" 'newFileMode' => 0660,\n" +" ],\n" +" ],\n" +" ];\n" +msgstr "" + +#. type: Title ## +#: ../src/guide/databases/db-migrations.md +#, no-wrap +msgid "Generating Migrations (TODO: likely is OK but...)" +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +msgid "The command provides a convenient way to create migrations using the provided [view](https://github.com/yiisoft/db-migration/tree/master/resources/views):" +msgstr "" + +#. type: Fenced code block (shell) +#: ../src/guide/databases/db-migrations.md +#, no-wrap +msgid "make yii migrate:create my_first_table --command=table --fields=name,example --table-comment=my_first_table\n" +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +msgid "That would generate the following:" +msgstr "" + +#. type: Fenced code block (php) +#: ../src/guide/databases/db-migrations.md +#, no-wrap +msgid "" +"createTable('my_first_table', [\n" +" 'id' => $b->primaryKey(),\n" +" 'name',\n" +" 'example',\n" +" ]);\n" +" \n" +" $b->addCommentOnTable('my_first_table', 'dest');\n" +" }\n" +"\n" +" public function down(MigrationBuilder $b): void\n" +" {\n" +" $b->dropTable('my_first_table');\n" +" }\n" +"}\n" +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +msgid "For more information [see](https://github.com/yiisoft/db-migration/tree/master/docs/guide/en)" +msgstr "" + +#. type: Title ## +#: ../src/guide/databases/db-migrations.md +#, no-wrap +msgid "Applying Migrations" +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +msgid "To upgrade a database to its latest structure, you should apply all available new migrations using the following command:" +msgstr "" + +#. type: Fenced code block +#: ../src/guide/databases/db-migrations.md +#, no-wrap +msgid "yii migrate\n" +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +msgid "This command will list all migrations that have not been applied so far. If you confirm that you want to apply these migrations, it will run the `up()` or `safeUp()` method in every new migration class, one after another, in the order of their timestamp values. If any of the migrations fails, the command will quit without applying the rest of the migrations." +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +#, no-wrap +msgid "" +"> Tip: In case you don't have command line at your server you may try [web shell](https://github.com/samdark/yii2-webshell)\n" +"> extension.\n" +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +msgid "For each migration that has been successfully applied, the command will insert a row into a database table named `migration` to record the successful application of the migration. This will allow the migration tool to identify which migrations have been applied and which have not." +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +#, no-wrap +msgid "" +"> Info: The migration tool will automatically create the `migration` table in the database specified by\n" +"the [[yii\\console\\controllers\\MigrateController::db|db]] option of the command. By default, the database\n" +"is specified by the `db` [application component](structure-application-components.md).\n" +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +msgid "Sometimes, you may only want to apply one or a few new migrations, instead of all available migrations. You can do so by specifying the number of migrations that you want to apply when running the command. For example, the following command will try to apply the next three available migrations:" +msgstr "" + +#. type: Fenced code block +#: ../src/guide/databases/db-migrations.md +#, no-wrap +msgid "yii migrate 3\n" +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +msgid "You can also explicitly specify a particular migration to which the database should be migrated by using the `migrate/to` command in one of the following formats:" +msgstr "" + +#. type: Fenced code block +#: ../src/guide/databases/db-migrations.md +#, no-wrap +msgid "" +"yii migrate/to 150101_185401 # using timestamp to specify the migration\n" +"yii migrate/to \"2015-01-01 18:54:01\" # using a string that can be parsed by strtotime()\n" +"yii migrate/to m150101_185401_create_news_table # using full name\n" +"yii migrate/to 1392853618 # using UNIX timestamp\n" +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +msgid "If there are any unapplied migrations earlier than the specified one, they will all be applied before the specified migration is applied." +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +msgid "If the specified migration has already been applied before, any later applied migrations will be reverted." +msgstr "" + +#. type: Title ## +#: ../src/guide/databases/db-migrations.md +#, fuzzy, no-wrap +#| msgid "Resolving aliases " +msgid "Reverting Migrations " +msgstr "Resolución de Alias " + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +msgid "To revert (undo) one or multiple migrations that have been applied before, you can run the following command:" +msgstr "" + +#. type: Fenced code block +#: ../src/guide/databases/db-migrations.md +#, no-wrap +msgid "" +"yii migrate/down # revert the most recently applied migration\n" +"yii migrate/down 3 # revert the most 3 recently applied migrations\n" +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +#, no-wrap +msgid "" +"> Note: Not all migrations are reversible. Trying to revert such migrations will cause an error and stop the\n" +"entire reverting process.\n" +msgstr "" + +#. type: Title ## +#: ../src/guide/databases/db-migrations.md +#, fuzzy, no-wrap +#| msgid "Resolving aliases " +msgid "Redoing Migrations " +msgstr "Resolución de Alias " + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +msgid "Redoing migrations means first reverting the specified migrations and then applying again. This can be done as follows:" +msgstr "" + +#. type: Fenced code block +#: ../src/guide/databases/db-migrations.md +#, no-wrap +msgid "" +"yii migrate/redo # redo the last applied migration\n" +"yii migrate/redo 3 # redo the last 3 applied migrations\n" +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +#, no-wrap +msgid "> Note: If a migration is not reversible, you will not be able to redo it.\n" +msgstr "" + +#. type: Title ## +#: ../src/guide/databases/db-migrations.md +#, fuzzy, no-wrap +#| msgid "Resolving aliases " +msgid "Refreshing Migrations " +msgstr "Resolución de Alias " + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +msgid "Since Yii 2.0.13 you can delete all tables and foreign keys from the database and apply all migrations from the beginning." +msgstr "" + +#. type: Fenced code block +#: ../src/guide/databases/db-migrations.md +#, no-wrap +msgid "yii migrate/fresh # truncate the database and apply all migrations from the beginning\n" +msgstr "" + +#. type: Title ## +#: ../src/guide/databases/db-migrations.md +#, fuzzy, no-wrap +#| msgid "Raising events " +msgid "Listing Migrations " +msgstr "Lanzamiento de Eventos " + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +msgid "To list which migrations have been applied and which are not, you may use the following commands:" +msgstr "" + +#. type: Fenced code block +#: ../src/guide/databases/db-migrations.md +#, no-wrap +msgid "" +"yii migrate/history # showing the last 10 applied migrations\n" +"yii migrate/history 5 # showing the last 5 applied migrations\n" +"yii migrate/history all # showing all applied migrations\n" +"\n" +"yii migrate/new # showing the first 10 new migrations\n" +"yii migrate/new 5 # showing the first 5 new migrations\n" +"yii migrate/new all # showing all new migrations\n" +msgstr "" + +#. type: Title ## +#: ../src/guide/databases/db-migrations.md +#, no-wrap +msgid "Modifying Migration History " +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +msgid "Instead of actually applying or reverting migrations, sometimes you may simply want to mark that your database has been upgraded to a particular migration. This often happens when you manually change the database to a particular state and you do not want the migration(s) for that change to be re-applied later. You can achieve this goal with the following command:" +msgstr "" + +#. type: Fenced code block +#: ../src/guide/databases/db-migrations.md +#, no-wrap +msgid "" +"yii migrate/mark 150101_185401 # using timestamp to specify the migration\n" +"yii migrate/mark \"2015-01-01 18:54:01\" # using a string that can be parsed by strtotime()\n" +"yii migrate/mark m150101_185401_create_news_table # using full name\n" +"yii migrate/mark 1392853618 # using UNIX timestamp\n" +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +msgid "The command will modify the `migration` table by adding or deleting certain rows to indicate that the database has been applied migrations to the specified one. No migrations will be applied or reverted by this command." +msgstr "" + +#. type: Title ## +#: ../src/guide/databases/db-migrations.md +#, fuzzy, no-wrap +#| msgid "Raising events " +msgid "Customizing Migrations " +msgstr "Lanzamiento de Eventos " + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +msgid "There are several ways to customize the migration command." +msgstr "" + +#. type: Title ### +#: ../src/guide/databases/db-migrations.md +#, fuzzy, no-wrap +#| msgid "Resolving aliases " +msgid "Using Command Line Options " +msgstr "Resolución de Alias " + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +msgid "The migration command comes with a few command-line options that can be used to customize its behaviors:" +msgstr "" + +#. type: Bullet: '* ' +#: ../src/guide/databases/db-migrations.md +msgid "`interactive`: boolean (defaults to `true`), specifies whether to perform migrations in an interactive mode. When this is `true`, the user will be prompted before the command performs certain actions. You may want to set this to `false` if the command is being used in a background process." +msgstr "" + +#. type: Bullet: '* ' +#: ../src/guide/databases/db-migrations.md +msgid "`migrationPath`: string|array (defaults to `@app/migrations`), specifies the directory storing all migration class files. This can be specified as either a directory path or a path [alias](concept-aliases.md). Note that the directory must exist, or the command may trigger an error. Since version 2.0.12 an array can be specified for loading migrations from multiple sources." +msgstr "" + +#. type: Bullet: '* ' +#: ../src/guide/databases/db-migrations.md +msgid "`migrationTable`: string (defaults to `migration`), specifies the name of the database table for storing migration history information. The table will be automatically created by the command if it does not exist. You may also manually create it using the structure `version varchar(255) primary key, apply_time integer`." +msgstr "" + +#. type: Bullet: '* ' +#: ../src/guide/databases/db-migrations.md +msgid "`db`: string (defaults to `db`), specifies the ID of the database [application component](structure-application-components.md). It represents the database that will be migrated using this command." +msgstr "" + +#. type: Bullet: '* ' +#: ../src/guide/databases/db-migrations.md +msgid "`templateFile`: string (defaults to `@yii/views/migration.php`), specifies the path of the template file that is used for generating skeleton migration class files. This can be specified as either a file path or a path [alias](concept-aliases.md). The template file is a PHP script in which you can use a predefined variable named `$className` to get the migration class name." +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +#, no-wrap +msgid "" +"* `generatorTemplateFiles`: array (defaults to `[\n" +" 'create_table' => '@yii/views/createTableMigration.php',\n" +" 'drop_table' => '@yii/views/dropTableMigration.php',\n" +" 'add_column' => '@yii/views/addColumnMigration.php',\n" +" 'drop_column' => '@yii/views/dropColumnMigration.php',\n" +" 'create_junction' => '@yii/views/createTableMigration.php'\n" +" ]`), specifies template files for generating migration code. See \"[Generating Migrations](#generating-migrations)\"\n" +" for more details.\n" +msgstr "" + +#. type: Bullet: '* ' +#: ../src/guide/databases/db-migrations.md +msgid "`fields`: array of column definition strings used for creating migration code. Defaults to `[]`. The format of each definition is `COLUMN_NAME:COLUMN_TYPE:COLUMN_DECORATOR`. For example, `--fields=name:string(12):notNull` produces a string column of size 12 which is not `null`." +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +msgid "The following example shows how you can use these options." +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +msgid "For example, if we want to migrate a `forum` module whose migration files are located within the module's `migrations` directory, we can use the following command:" +msgstr "" + +#. type: Fenced code block +#: ../src/guide/databases/db-migrations.md +#, no-wrap +msgid "" +"# migrate the migrations in a forum module non-interactively\n" +"yii migrate --migrationPath=@app/modules/forum/migrations --interactive=0\n" +msgstr "" + +#. type: Title ### +#: ../src/guide/databases/db-migrations.md +#, no-wrap +msgid "Separated Migrations" +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +msgid "Sometimes using single migration history for all project migrations is not desirable. For example: you may install some 'blog' extension, which contains fully separated functionality and contain its own migrations, which should not affect the ones dedicated to main project functionality." +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +msgid "If you want several migrations to be applied and tracked down completely separated from each other, you can configure multiple migration commands which will use different namespaces and migration history tables:" +msgstr "" + +#. type: Fenced code block (php) +#: ../src/guide/databases/db-migrations.md +#, no-wrap +msgid "" +"return [\n" +" 'controllerMap' => [\n" +" // Common migrations for the whole application\n" +" 'migrate-app' => [\n" +" 'class' => 'yii\\console\\controllers\\MigrateController',\n" +" 'migrationNamespaces' => ['app\\migrations'],\n" +" 'migrationTable' => 'migration_app',\n" +" 'migrationPath' => null,\n" +" ],\n" +" // Migrations for the specific project's module\n" +" 'migrate-module' => [\n" +" 'class' => 'yii\\console\\controllers\\MigrateController',\n" +" 'migrationNamespaces' => ['module\\migrations'],\n" +" 'migrationTable' => 'migration_module',\n" +" 'migrationPath' => null,\n" +" ],\n" +" // Migrations for the specific extension\n" +" 'migrate-rbac' => [\n" +" 'class' => 'yii\\console\\controllers\\MigrateController',\n" +" 'migrationPath' => '@yii/rbac/migrations',\n" +" 'migrationTable' => 'migration_rbac',\n" +" ],\n" +" ],\n" +"];\n" +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +msgid "Note that to synchronize database you now need to run multiple commands instead of one:" +msgstr "" + +#. type: Fenced code block +#: ../src/guide/databases/db-migrations.md +#, no-wrap +msgid "" +"yii migrate-app\n" +"yii migrate-module\n" +"yii migrate-rbac\n" +msgstr "" + +#. type: Title ## +#: ../src/guide/databases/db-migrations.md +#, fuzzy, no-wrap +#| msgid "Defining aliases " +msgid "Migrating Multiple Databases " +msgstr "Definir Alias " + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +msgid "By default, migrations are applied to the same database specified by the `db` [application component](structure-application-components.md). If you want them to be applied to a different database, you may specify the `db` command-line option like shown below," +msgstr "" + +#. type: Fenced code block +#: ../src/guide/databases/db-migrations.md +#, no-wrap +msgid "yii migrate --db=db2\n" +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +msgid "The above command will apply migrations to the `db2` database." +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +msgid "Sometimes it may happen that you want to apply *some* of the migrations to one database, while some others to another database. To achieve this goal, when implementing a migration class you should explicitly specify the DB component ID that the migration would use, like the following:" +msgstr "" + +#. type: Fenced code block (php) +#: ../src/guide/databases/db-migrations.md +#, no-wrap +msgid "" +"db = 'db2';\n" +" parent::init();\n" +" }\n" +"}\n" +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +msgid "The above migration will be applied to `db2`, even if you specify a different database through the `db` command-line option. Note that the migration history will still be recorded in the database specified by the `db` command-line option." +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +msgid "If you have multiple migrations that use the same database, it is recommended that you create a base migration class with the above `init()` code. Then each migration class can extend from this base class." +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +#, no-wrap +msgid "" +"> Tip: Besides setting the [[yii\\db\\Migration::db|db]] property, you can also operate on different databases\n" +"by creating new database connections to them in your migration classes. You then use the [DAO methods](db-dao.md)\n" +"with these connections to manipulate different databases.\n" +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +msgid "Another strategy that you can take to migrate multiple databases is to keep migrations for different databases in different migration paths. Then you can migrate these databases in separate commands like the following:" +msgstr "" + +#. type: Fenced code block +#: ../src/guide/databases/db-migrations.md +#, no-wrap +msgid "" +"yii migrate --migrationPath=@app/migrations/db1 --db=db1\n" +"yii migrate --migrationPath=@app/migrations/db2 --db=db2\n" +"...\n" +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +msgid "The first command will apply migrations in `@app/migrations/db1` to the `db1` database, the second command will apply migrations in `@app/migrations/db2` to `db2`, and so on." msgstr "" #. type: Title ### #: ../src/guide/databases/db-migrations.md #, no-wrap -msgid "Upgrading from Yii 2.0" +msgid "Upgrading from Yii2" msgstr "" #. type: Plain text #: ../src/guide/databases/db-migrations.md -msgid "Migrations in Yii 2.0 and the [yiisoft/db-migration](https://github.com/yiisoft/db-migration/) package are not compatible, and the `migration` table is also not compatible. A probable solution is to use structure dumps and rename the old `migration` table. Upon the initial execution of migrations, a new `migration` table with new fields will be created. All further changes in the database schema are applied using the new `migration` component and recorded in the new migration table." +msgid "Migrations in Yii2 and the [yiisoft/db-migration](https://github.com/yiisoft/db-migration/) package are not compatible, and the `migration` table is also not compatible. A probable solution is to use structure dumps and rename the old `migration` table. Upon the initial execution of migrations, a new `migration` table with new fields will be created. All further changes in the database schema are applied using the new `migration` component and recorded in the new migration table." msgstr "" diff --git a/_translations/po/id/guide_databases_db-migrations.md.po b/_translations/po/id/guide_databases_db-migrations.md.po index cc0892f9..825d8bc7 100644 --- a/_translations/po/id/guide_databases_db-migrations.md.po +++ b/_translations/po/id/guide_databases_db-migrations.md.po @@ -6,7 +6,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" -"POT-Creation-Date: 2025-12-27 07:40+0000\n" +"POT-Creation-Date: 2025-12-27 07:55+0000\n" "PO-Revision-Date: 2025-09-04 11:19+0500\n" "Last-Translator: Automatically generated\n" "Language-Team: none\n" @@ -21,26 +21,196 @@ msgstr "" msgid "Migrations" msgstr "" +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +msgid "During the course of developing and maintaining a database-driven application, the structure of the database being used evolves just like the source code does. For example, during the development of an application, a new table may be found necessary; after the application is deployed to production, it may be discovered that an index should be created to improve the query performance; and so on. Because a database structure change often requires some source code changes, Yii supports the so-called *database migration* feature that allows you to keep track of database changes in terms of *database migrations* which are version-controlled together with the source code." +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +msgid "The following steps show how database migration can be used by a team during development:" +msgstr "" + +#. type: Bullet: '1. ' +#: ../src/guide/databases/db-migrations.md +msgid "Tim creates a new migration (e.g. creates a new table, changes a column definition, etc.)." +msgstr "" + +#. type: Bullet: '2. ' +#: ../src/guide/databases/db-migrations.md +msgid "Tim commits the new migration into the source control system (e.g. Git, Mercurial)." +msgstr "" + +#. type: Bullet: '3. ' +#: ../src/guide/databases/db-migrations.md +msgid "Doug updates his repository from the source control system and receives the new migration." +msgstr "" + +#. type: Bullet: '4. ' +#: ../src/guide/databases/db-migrations.md +msgid "Doug applies the migration to his local development database, thereby synchronizing his database to reflect the changes that Tim has made." +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +msgid "And the following steps show how to deploy a new release with database migrations to production:" +msgstr "" + +#. type: Bullet: '1. ' +#: ../src/guide/databases/db-migrations.md +msgid "Scott creates a release tag for the project repository that contains some new database migrations." +msgstr "" + +#. type: Bullet: '2. ' +#: ../src/guide/databases/db-migrations.md +msgid "Scott updates the source code on the production server to the release tag." +msgstr "" + +#. type: Bullet: '3. ' +#: ../src/guide/databases/db-migrations.md +msgid "Scott applies any accumulated database migrations to the production database." +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +msgid "Yii provides a set of migration command line tools that allow you to:" +msgstr "" + +#. type: Bullet: '* ' +#: ../src/guide/databases/db-migrations.md +msgid "create new migrations;" +msgstr "" + +#. type: Bullet: '* ' +#: ../src/guide/databases/db-migrations.md +msgid "apply migrations;" +msgstr "" + +#. type: Bullet: '* ' +#: ../src/guide/databases/db-migrations.md +msgid "revert migrations;" +msgstr "" + +#. type: Bullet: '* ' +#: ../src/guide/databases/db-migrations.md +msgid "re-apply migrations;" +msgstr "" + +#. type: Bullet: '* ' +#: ../src/guide/databases/db-migrations.md +msgid "show migration history and status." +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +msgid "All these tools are accessible through the command `yii migrate`. In this section we will describe in detail how to accomplish various tasks using these tools." +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +#, no-wrap +msgid "" +"> [!TIP]\n" +"> Migrations could affect not only database schema but adjust existing data to fit new schema, create RBAC\n" +"hierarchy or clean up cache.\n" +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +#, no-wrap +msgid "" +"> [!NOTE]\n" +"> When manipulating data using a migration you may find that using your Active Record or entity classes\n" +"> for this might be useful because some of the logic is already implemented there. Keep in mind however, that in contrast\n" +"> to code written in the migrations, whose nature is to stay constant forever, application logic is subject to change.\n" +"> So when using Active Record or entity classes in migration code, changes to the logic in the source code\n" +"> may accidentally break the existing migrations. For this reason migration code should be kept independent of other\n" +"> application logic such.\n" +msgstr "" + +#. type: Title ## +#: ../src/guide/databases/db-migrations.md +#, fuzzy, no-wrap +#| msgid "Container configuration" +msgid "Initial configuration" +msgstr "Konfigurasi container" + #. type: Plain text #: ../src/guide/databases/db-migrations.md msgid "To use migrations, install [yiisoft/db-migration](https://github.com/yiisoft/db-migration/) package:" msgstr "" -#. type: Fenced code block (shell) +#. type: Fenced code block (sh) +#: ../src/guide/databases/db-migrations.md ../src/guide/start/databases.md +#, fuzzy, no-wrap +msgid "make composer require yiisoft/db-migration\n" +msgstr "composer require yiisoft/cache\n" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +msgid "Create a directory to store migrations `src/Migration` right in the project root." +msgstr "" + +#. type: Plain text #: ../src/guide/databases/db-migrations.md +msgid "Add the following configuration to `config/common/params.php`:" +msgstr "" + +#. type: Fenced code block (php) +#: ../src/guide/databases/db-migrations.md ../src/guide/start/databases.md #, no-wrap -msgid "composer require yiisoft/db-migration\n" +msgid "" +"'yiisoft/db-migration' => [\n" +" 'newMigrationNamespace' => 'App\\\\Migration',\n" +" 'sourceNamespaces' => ['App\\\\Migration'],\n" +"],\n" +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +msgid "You need a database connection configured as well. See [Working with databases](../start/databases.md) for an example of configuring it for PostgreSQL." msgstr "" #. type: Title ### #: ../src/guide/databases/db-migrations.md #, no-wrap -msgid "Example usage" +msgid "Creating a migration" +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +msgid "To create a new empty migration, run the following command:" +msgstr "" + +#. type: Fenced code block (sh) +#: ../src/guide/databases/db-migrations.md +#, no-wrap +msgid "make yii migrate:create \n" +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +msgid "The required `name` argument gives a brief description about the new migration. For example, if the migration is about creating a new table named *news*, you may use the name `create_news_table` and run the following command:" +msgstr "" + +#. type: Fenced code block +#: ../src/guide/databases/db-migrations.md +#, no-wrap +msgid "make yii migrate:create create_news_table\n" +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +#, no-wrap +msgid "" +"> [!NOTE]\n" +"> Because the `name` argument will be used as part of the generated migration class name,\n" +"> it should only contain letters, digits, and/or underscore characters.\n" msgstr "" #. type: Plain text #: ../src/guide/databases/db-migrations.md -msgid "First, configure a DI container. Create `config/common/db.php` with the following content:" +msgid "The above command will create a new PHP class file named `src/Migration/M251225221906CreateNewsTable.php`. The file contains the following code which mainly declares a migration class with the skeleton code:" msgstr "" #. type: Fenced code block (php) @@ -51,67 +221,101 @@ msgid "" "\n" "declare(strict_types=1);\n" "\n" -"use Yiisoft\\Db\\Connection\\ConnectionInterface;\n" -"use Yiisoft\\Db\\Sqlite\\Connection as SqliteConnection;\n" +"namespace App\\Migration;\n" "\n" -"return [\n" -" ConnectionInterface::class => [\n" -" 'class' => SqliteConnection::class,\n" -" '__construct()' => [\n" -" 'dsn' => 'sqlite:' . __DIR__ . '/Data/yiitest.sq3'\n" -" ]\n" -" ]\n" -"];\n" +"use Yiisoft\\Db\\Migration\\MigrationBuilder;\n" +"use Yiisoft\\Db\\Migration\\RevertibleMigrationInterface;\n" +"\n" +"final class M251225221906CreateNewsTable implements RevertibleMigrationInterface\n" +"{\n" +" public function up(MigrationBuilder $b): void\n" +" {\n" +" // TODO: Implement the logic to apply the migration.\n" +" }\n" +"\n" +" public function down(MigrationBuilder $b): void\n" +" {\n" +" // TODO: Implement the logic to revert the migration.\n" +" }\n" +"}\n" msgstr "" #. type: Plain text #: ../src/guide/databases/db-migrations.md -msgid "Add the following to `config/params.php`:" +msgid "In the migration class, you are expected to write code in the `up()` method that makes changes to the database structure. You may also want to write code in the `down()` method to revert the changes made by `up()`. The `up()` method is invoked when you upgrade the database with this migration, while the `down()` method is invoked when you downgrade the database. The following code shows how you may implement the migration class to create a `news` table:" msgstr "" #. type: Fenced code block (php) #: ../src/guide/databases/db-migrations.md #, no-wrap msgid "" -"...\n" -"'yiisoft/db-migration' => [\n" -" 'newMigrationNamespace' => 'App\\\\Migration',\n" -" 'sourceNamespaces' => ['App\\\\Migration'],\n" -"],\n" -"...\n" +"columnBuilder();\n" +"\n" +" $b->createTable('news', [\n" +" 'id' => $cb::uuidPrimaryKey(),\n" +" 'title' => $cb::string()->notNull(),\n" +" 'content' => $cb::text(),\n" +" ]);\n" +" }\n" +"\n" +" public function down(MigrationBuilder $b): void\n" +" {\n" +" $b->dropTable('news');\n" +" }\n" +"}\n" msgstr "" #. type: Plain text #: ../src/guide/databases/db-migrations.md -msgid "Now test if it works:" +#, no-wrap +msgid "" +"TODO: explain $b and $qb\n" +"Below is the list of all these database accessing methods:\n" msgstr "" -#. type: Fenced code block (shell) +#. type: Title ### #: ../src/guide/databases/db-migrations.md #, no-wrap -msgid "./yii list migrate\n" +msgid "Irreversible migrations" +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +msgid "Not all migrations are reversible. For example, if the `up()` method deletes a row of a table, you may not be able to recover this row in the `down()` method. Sometimes, you may be just too lazy to implement the `down()`, because it is not very common to revert database migrations. In this case, you should implement `Yiisoft\\Db\\Migration\\MigrationInterface` that has `up()` only." msgstr "" #. type: Title ### #: ../src/guide/databases/db-migrations.md #, no-wrap -msgid "Creating a migration" +msgid "Transactional migrations (TODO: update!!!)" msgstr "" #. type: Plain text #: ../src/guide/databases/db-migrations.md -msgid "To work with migrations, you can use the provided [view](https://github.com/yiisoft/db-migration/tree/master/resources/views)." +msgid "While performing complex DB migrations, it is important to ensure each migration to either succeed or fail as a whole so that the database can maintain integrity and consistency. To achieve this goal, it is recommended that you enclose the DB operations of each migration in a [transaction](db-dao.md#performing-transactions)." msgstr "" -#. type: Fenced code block (shell) +#. type: Plain text #: ../src/guide/databases/db-migrations.md -#, no-wrap -msgid "./yii migrate:create my_first_table --command=table --fields=name,example --table-comment=my_first_table\n" +msgid "An even easier way of implementing transactional migrations is to put migration code in the `safeUp()` and `safeDown()` methods. These two methods differ from `up()` and `down()` in that they are enclosed implicitly in a transaction. As a result, if any operation in these methods fails, all prior operations will be rolled back automatically." msgstr "" #. type: Plain text #: ../src/guide/databases/db-migrations.md -msgid "That would generate the following:" +msgid "In the following example, besides creating the `news` table we also insert an initial row into this table." msgstr "" #. type: Fenced code block (php) @@ -120,49 +324,656 @@ msgstr "" msgid "" "createTable('news', [\n" +" 'id' => $this->primaryKey(),\n" +" 'title' => $this->string()->notNull(),\n" +" 'content' => $this->text(),\n" +" ]);\n" "\n" -"use Yiisoft\\Db\\Migration\\MigrationBuilder;\n" -"use Yiisoft\\Db\\Migration\\RevertibleMigrationInterface;\n" -"use Yiisoft\\Db\\Migration\\TransactionalMigrationInterface;\n" +" $this->insert('news', [\n" +" 'title' => 'test 1',\n" +" 'content' => 'content 1',\n" +" ]);\n" +" }\n" "\n" -"/**\n" -" * Handles the creation of a table `my_first_table`.\n" -" */\n" -"final class M240115143455CreateMyFirstTableTable implements RevertibleMigrationInterface, TransactionalMigrationInterface\n" +" public function safeDown()\n" +" {\n" +" $this->delete('news', ['id' => 1]);\n" +" $this->dropTable('news');\n" +" }\n" +"}\n" +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +msgid "Note that usually when you perform multiple DB operations in `safeUp()`, you should reverse their execution order in `safeDown()`. In the above example we first create the table and then insert a row in `safeUp()`; while in `safeDown()` we first delete the row and then drop the table." +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +#, no-wrap +msgid "" +"> Note: Not all DBMS support transactions. And some DB queries cannot be put into a transaction. For some examples,\n" +"please refer to [implicit commit](https://dev.mysql.com/doc/refman/5.7/en/implicit-commit.html). If this is the case,\n" +"you should still implement `up()` and `down()`, instead.\n" +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +#, no-wrap +msgid "TODO: TransactionalMigrationInterface\n" +msgstr "" + +#. type: Title ## +#: ../src/guide/databases/db-migrations.md +#, no-wrap +msgid "TODO: update" +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +msgid "The base migration class [[yii\\db\\Migration]] exposes a database connection via the [[yii\\db\\Migration::db|db]] property. You can use it to manipulate the database schema using the methods as described in [Working with Database Schema](db-dao.md#database-schema)." +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +#, no-wrap +msgid "" +"Rather than using physical types, when creating a table or column you should use *abstract types*\n" +"so that your migrations are independent of specific DBMS. The [[yii\\db\\Schema]] class defines\n" +"a set of constants to represent the supported abstract types. These constants are named in the format\n" +"of `TYPE_`. For example, `TYPE_PK` refers to auto-incremental primary key type; `TYPE_STRING`\n" +"refers to a string type. When a migration is applied to a particular database, the abstract types\n" +"will be translated into the corresponding physical types. In the case of MySQL, `TYPE_PK` will be turned\n" +"into `int(11) NOT NULL AUTO_INCREMENT PRIMARY KEY`, while `TYPE_STRING` becomes `varchar(255)`.\n" +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +msgid "You can append additional constraints when using abstract types. In the above example, ` NOT NULL` is appended to `Schema::TYPE_STRING` to specify that the column cannot be `null`." +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +#, no-wrap +msgid "" +"> Info: The mapping between abstract types and physical types is specified by\n" +"the [[yii\\db\\QueryBuilder::$typeMap|$typeMap]] property in each concrete `QueryBuilder` class.\n" +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +msgid "Since version 2.0.6, you can make use of the newly introduced schema builder which provides more convenient way of defining column schema. So the migration above could be written like the following:" +msgstr "" + +#. type: Fenced code block (php) +#: ../src/guide/databases/db-migrations.md +#, no-wrap +msgid "" +"createTable('my_first_table', [\n" -" 'id' => $b->primaryKey(),\n" -" 'name',\n" -" 'example',\n" +" $this->createTable('news', [\n" +" 'id' => $this->primaryKey(),\n" +" 'title' => $this->string()->notNull(),\n" +" 'content' => $this->text(),\n" " ]);\n" -" \n" -" $b->addCommentOnTable('my_first_table', 'dest');\n" " }\n" "\n" -" public function down(MigrationBuilder $b): void\n" +" public function down()\n" " {\n" -" $b->dropTable('my_first_table');\n" +" $this->dropTable('news');\n" " }\n" "}\n" msgstr "" #. type: Plain text #: ../src/guide/databases/db-migrations.md -msgid "For more information [see](https://github.com/yiisoft/db-migration/tree/master/docs/guide/en)" +msgid "A list of all available methods for defining the column types is available in the API documentation of [[yii\\db\\SchemaBuilderTrait]]." +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +#, no-wrap +msgid "" +"> Info: The generated file permissions and ownership will be determined by the current environment. This might lead to\n" +"inaccessible files. This could, for example, happen when the migration is created within a docker container\n" +"and the files are edited on the host. In this case the `newFileMode` and/or `newFileOwnership` of the MigrateController\n" +"can be changed. E.g. in the application config:\n" +msgstr "" + +#. type: Fenced code block (php) +#: ../src/guide/databases/db-migrations.md +#, no-wrap +msgid "" +" [\n" +" 'migrate' => [\n" +" 'class' => 'yii\\console\\controllers\\MigrateController',\n" +" 'newFileOwnership' => '1000:1000', # Default WSL user id\n" +" 'newFileMode' => 0660,\n" +" ],\n" +" ],\n" +" ];\n" +msgstr "" + +#. type: Title ## +#: ../src/guide/databases/db-migrations.md +#, no-wrap +msgid "Generating Migrations (TODO: likely is OK but...)" +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +msgid "The command provides a convenient way to create migrations using the provided [view](https://github.com/yiisoft/db-migration/tree/master/resources/views):" +msgstr "" + +#. type: Fenced code block (shell) +#: ../src/guide/databases/db-migrations.md +#, no-wrap +msgid "make yii migrate:create my_first_table --command=table --fields=name,example --table-comment=my_first_table\n" +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +msgid "That would generate the following:" +msgstr "" + +#. type: Fenced code block (php) +#: ../src/guide/databases/db-migrations.md +#, no-wrap +msgid "" +"createTable('my_first_table', [\n" +" 'id' => $b->primaryKey(),\n" +" 'name',\n" +" 'example',\n" +" ]);\n" +" \n" +" $b->addCommentOnTable('my_first_table', 'dest');\n" +" }\n" +"\n" +" public function down(MigrationBuilder $b): void\n" +" {\n" +" $b->dropTable('my_first_table');\n" +" }\n" +"}\n" +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +msgid "For more information [see](https://github.com/yiisoft/db-migration/tree/master/docs/guide/en)" +msgstr "" + +#. type: Title ## +#: ../src/guide/databases/db-migrations.md +#, fuzzy, no-wrap +#| msgid "Configuration" +msgid "Applying Migrations" +msgstr "Konfigurasi" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +msgid "To upgrade a database to its latest structure, you should apply all available new migrations using the following command:" +msgstr "" + +#. type: Fenced code block +#: ../src/guide/databases/db-migrations.md +#, no-wrap +msgid "yii migrate\n" +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +msgid "This command will list all migrations that have not been applied so far. If you confirm that you want to apply these migrations, it will run the `up()` or `safeUp()` method in every new migration class, one after another, in the order of their timestamp values. If any of the migrations fails, the command will quit without applying the rest of the migrations." +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +#, no-wrap +msgid "" +"> Tip: In case you don't have command line at your server you may try [web shell](https://github.com/samdark/yii2-webshell)\n" +"> extension.\n" +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +msgid "For each migration that has been successfully applied, the command will insert a row into a database table named `migration` to record the successful application of the migration. This will allow the migration tool to identify which migrations have been applied and which have not." +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +#, no-wrap +msgid "" +"> Info: The migration tool will automatically create the `migration` table in the database specified by\n" +"the [[yii\\console\\controllers\\MigrateController::db|db]] option of the command. By default, the database\n" +"is specified by the `db` [application component](structure-application-components.md).\n" +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +msgid "Sometimes, you may only want to apply one or a few new migrations, instead of all available migrations. You can do so by specifying the number of migrations that you want to apply when running the command. For example, the following command will try to apply the next three available migrations:" +msgstr "" + +#. type: Fenced code block +#: ../src/guide/databases/db-migrations.md +#, no-wrap +msgid "yii migrate 3\n" +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +msgid "You can also explicitly specify a particular migration to which the database should be migrated by using the `migrate/to` command in one of the following formats:" +msgstr "" + +#. type: Fenced code block +#: ../src/guide/databases/db-migrations.md +#, no-wrap +msgid "" +"yii migrate/to 150101_185401 # using timestamp to specify the migration\n" +"yii migrate/to \"2015-01-01 18:54:01\" # using a string that can be parsed by strtotime()\n" +"yii migrate/to m150101_185401_create_news_table # using full name\n" +"yii migrate/to 1392853618 # using UNIX timestamp\n" +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +msgid "If there are any unapplied migrations earlier than the specified one, they will all be applied before the specified migration is applied." +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +msgid "If the specified migration has already been applied before, any later applied migrations will be reverted." +msgstr "" + +#. type: Title ## +#: ../src/guide/databases/db-migrations.md +#, fuzzy, no-wrap +#| msgid "Resolving aliases " +msgid "Reverting Migrations " +msgstr "Me-resolve alias " + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +msgid "To revert (undo) one or multiple migrations that have been applied before, you can run the following command:" +msgstr "" + +#. type: Fenced code block +#: ../src/guide/databases/db-migrations.md +#, no-wrap +msgid "" +"yii migrate/down # revert the most recently applied migration\n" +"yii migrate/down 3 # revert the most 3 recently applied migrations\n" +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +#, no-wrap +msgid "" +"> Note: Not all migrations are reversible. Trying to revert such migrations will cause an error and stop the\n" +"entire reverting process.\n" +msgstr "" + +#. type: Title ## +#: ../src/guide/databases/db-migrations.md +#, fuzzy, no-wrap +#| msgid "Resolving aliases " +msgid "Redoing Migrations " +msgstr "Me-resolve alias " + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +msgid "Redoing migrations means first reverting the specified migrations and then applying again. This can be done as follows:" +msgstr "" + +#. type: Fenced code block +#: ../src/guide/databases/db-migrations.md +#, no-wrap +msgid "" +"yii migrate/redo # redo the last applied migration\n" +"yii migrate/redo 3 # redo the last 3 applied migrations\n" +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +#, no-wrap +msgid "> Note: If a migration is not reversible, you will not be able to redo it.\n" +msgstr "" + +#. type: Title ## +#: ../src/guide/databases/db-migrations.md +#, fuzzy, no-wrap +#| msgid "Resolving aliases " +msgid "Refreshing Migrations " +msgstr "Me-resolve alias " + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +msgid "Since Yii 2.0.13 you can delete all tables and foreign keys from the database and apply all migrations from the beginning." +msgstr "" + +#. type: Fenced code block +#: ../src/guide/databases/db-migrations.md +#, no-wrap +msgid "yii migrate/fresh # truncate the database and apply all migrations from the beginning\n" +msgstr "" + +#. type: Title ## +#: ../src/guide/databases/db-migrations.md +#, fuzzy, no-wrap +#| msgid "Using aliases in configuration " +msgid "Listing Migrations " +msgstr "Menggunakan aliases di konfigurasi " + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +msgid "To list which migrations have been applied and which are not, you may use the following commands:" +msgstr "" + +#. type: Fenced code block +#: ../src/guide/databases/db-migrations.md +#, no-wrap +msgid "" +"yii migrate/history # showing the last 10 applied migrations\n" +"yii migrate/history 5 # showing the last 5 applied migrations\n" +"yii migrate/history all # showing all applied migrations\n" +"\n" +"yii migrate/new # showing the first 10 new migrations\n" +"yii migrate/new 5 # showing the first 5 new migrations\n" +"yii migrate/new all # showing all new migrations\n" +msgstr "" + +#. type: Title ## +#: ../src/guide/databases/db-migrations.md +#, no-wrap +msgid "Modifying Migration History " +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +msgid "Instead of actually applying or reverting migrations, sometimes you may simply want to mark that your database has been upgraded to a particular migration. This often happens when you manually change the database to a particular state and you do not want the migration(s) for that change to be re-applied later. You can achieve this goal with the following command:" +msgstr "" + +#. type: Fenced code block +#: ../src/guide/databases/db-migrations.md +#, no-wrap +msgid "" +"yii migrate/mark 150101_185401 # using timestamp to specify the migration\n" +"yii migrate/mark \"2015-01-01 18:54:01\" # using a string that can be parsed by strtotime()\n" +"yii migrate/mark m150101_185401_create_news_table # using full name\n" +"yii migrate/mark 1392853618 # using UNIX timestamp\n" +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +msgid "The command will modify the `migration` table by adding or deleting certain rows to indicate that the database has been applied migrations to the specified one. No migrations will be applied or reverted by this command." +msgstr "" + +#. type: Title ## +#: ../src/guide/databases/db-migrations.md +#, fuzzy, no-wrap +#| msgid "Using aliases in configuration " +msgid "Customizing Migrations " +msgstr "Menggunakan aliases di konfigurasi " + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +msgid "There are several ways to customize the migration command." +msgstr "" + +#. type: Title ### +#: ../src/guide/databases/db-migrations.md +#, fuzzy, no-wrap +#| msgid "Using aliases in configuration " +msgid "Using Command Line Options " +msgstr "Menggunakan aliases di konfigurasi " + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +msgid "The migration command comes with a few command-line options that can be used to customize its behaviors:" +msgstr "" + +#. type: Bullet: '* ' +#: ../src/guide/databases/db-migrations.md +msgid "`interactive`: boolean (defaults to `true`), specifies whether to perform migrations in an interactive mode. When this is `true`, the user will be prompted before the command performs certain actions. You may want to set this to `false` if the command is being used in a background process." +msgstr "" + +#. type: Bullet: '* ' +#: ../src/guide/databases/db-migrations.md +msgid "`migrationPath`: string|array (defaults to `@app/migrations`), specifies the directory storing all migration class files. This can be specified as either a directory path or a path [alias](concept-aliases.md). Note that the directory must exist, or the command may trigger an error. Since version 2.0.12 an array can be specified for loading migrations from multiple sources." +msgstr "" + +#. type: Bullet: '* ' +#: ../src/guide/databases/db-migrations.md +msgid "`migrationTable`: string (defaults to `migration`), specifies the name of the database table for storing migration history information. The table will be automatically created by the command if it does not exist. You may also manually create it using the structure `version varchar(255) primary key, apply_time integer`." +msgstr "" + +#. type: Bullet: '* ' +#: ../src/guide/databases/db-migrations.md +msgid "`db`: string (defaults to `db`), specifies the ID of the database [application component](structure-application-components.md). It represents the database that will be migrated using this command." +msgstr "" + +#. type: Bullet: '* ' +#: ../src/guide/databases/db-migrations.md +msgid "`templateFile`: string (defaults to `@yii/views/migration.php`), specifies the path of the template file that is used for generating skeleton migration class files. This can be specified as either a file path or a path [alias](concept-aliases.md). The template file is a PHP script in which you can use a predefined variable named `$className` to get the migration class name." +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +#, no-wrap +msgid "" +"* `generatorTemplateFiles`: array (defaults to `[\n" +" 'create_table' => '@yii/views/createTableMigration.php',\n" +" 'drop_table' => '@yii/views/dropTableMigration.php',\n" +" 'add_column' => '@yii/views/addColumnMigration.php',\n" +" 'drop_column' => '@yii/views/dropColumnMigration.php',\n" +" 'create_junction' => '@yii/views/createTableMigration.php'\n" +" ]`), specifies template files for generating migration code. See \"[Generating Migrations](#generating-migrations)\"\n" +" for more details.\n" +msgstr "" + +#. type: Bullet: '* ' +#: ../src/guide/databases/db-migrations.md +msgid "`fields`: array of column definition strings used for creating migration code. Defaults to `[]`. The format of each definition is `COLUMN_NAME:COLUMN_TYPE:COLUMN_DECORATOR`. For example, `--fields=name:string(12):notNull` produces a string column of size 12 which is not `null`." +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +msgid "The following example shows how you can use these options." +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +msgid "For example, if we want to migrate a `forum` module whose migration files are located within the module's `migrations` directory, we can use the following command:" +msgstr "" + +#. type: Fenced code block +#: ../src/guide/databases/db-migrations.md +#, no-wrap +msgid "" +"# migrate the migrations in a forum module non-interactively\n" +"yii migrate --migrationPath=@app/modules/forum/migrations --interactive=0\n" +msgstr "" + +#. type: Title ### +#: ../src/guide/databases/db-migrations.md +#, no-wrap +msgid "Separated Migrations" +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +msgid "Sometimes using single migration history for all project migrations is not desirable. For example: you may install some 'blog' extension, which contains fully separated functionality and contain its own migrations, which should not affect the ones dedicated to main project functionality." +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +msgid "If you want several migrations to be applied and tracked down completely separated from each other, you can configure multiple migration commands which will use different namespaces and migration history tables:" +msgstr "" + +#. type: Fenced code block (php) +#: ../src/guide/databases/db-migrations.md +#, no-wrap +msgid "" +"return [\n" +" 'controllerMap' => [\n" +" // Common migrations for the whole application\n" +" 'migrate-app' => [\n" +" 'class' => 'yii\\console\\controllers\\MigrateController',\n" +" 'migrationNamespaces' => ['app\\migrations'],\n" +" 'migrationTable' => 'migration_app',\n" +" 'migrationPath' => null,\n" +" ],\n" +" // Migrations for the specific project's module\n" +" 'migrate-module' => [\n" +" 'class' => 'yii\\console\\controllers\\MigrateController',\n" +" 'migrationNamespaces' => ['module\\migrations'],\n" +" 'migrationTable' => 'migration_module',\n" +" 'migrationPath' => null,\n" +" ],\n" +" // Migrations for the specific extension\n" +" 'migrate-rbac' => [\n" +" 'class' => 'yii\\console\\controllers\\MigrateController',\n" +" 'migrationPath' => '@yii/rbac/migrations',\n" +" 'migrationTable' => 'migration_rbac',\n" +" ],\n" +" ],\n" +"];\n" +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +msgid "Note that to synchronize database you now need to run multiple commands instead of one:" +msgstr "" + +#. type: Fenced code block +#: ../src/guide/databases/db-migrations.md +#, no-wrap +msgid "" +"yii migrate-app\n" +"yii migrate-module\n" +"yii migrate-rbac\n" +msgstr "" + +#. type: Title ## +#: ../src/guide/databases/db-migrations.md +#, fuzzy, no-wrap +#| msgid "Defining aliases " +msgid "Migrating Multiple Databases " +msgstr "Defining aliases " + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +msgid "By default, migrations are applied to the same database specified by the `db` [application component](structure-application-components.md). If you want them to be applied to a different database, you may specify the `db` command-line option like shown below," +msgstr "" + +#. type: Fenced code block +#: ../src/guide/databases/db-migrations.md +#, no-wrap +msgid "yii migrate --db=db2\n" +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +msgid "The above command will apply migrations to the `db2` database." +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +msgid "Sometimes it may happen that you want to apply *some* of the migrations to one database, while some others to another database. To achieve this goal, when implementing a migration class you should explicitly specify the DB component ID that the migration would use, like the following:" +msgstr "" + +#. type: Fenced code block (php) +#: ../src/guide/databases/db-migrations.md +#, no-wrap +msgid "" +"db = 'db2';\n" +" parent::init();\n" +" }\n" +"}\n" +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +msgid "The above migration will be applied to `db2`, even if you specify a different database through the `db` command-line option. Note that the migration history will still be recorded in the database specified by the `db` command-line option." +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +msgid "If you have multiple migrations that use the same database, it is recommended that you create a base migration class with the above `init()` code. Then each migration class can extend from this base class." +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +#, no-wrap +msgid "" +"> Tip: Besides setting the [[yii\\db\\Migration::db|db]] property, you can also operate on different databases\n" +"by creating new database connections to them in your migration classes. You then use the [DAO methods](db-dao.md)\n" +"with these connections to manipulate different databases.\n" +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +msgid "Another strategy that you can take to migrate multiple databases is to keep migrations for different databases in different migration paths. Then you can migrate these databases in separate commands like the following:" +msgstr "" + +#. type: Fenced code block +#: ../src/guide/databases/db-migrations.md +#, no-wrap +msgid "" +"yii migrate --migrationPath=@app/migrations/db1 --db=db1\n" +"yii migrate --migrationPath=@app/migrations/db2 --db=db2\n" +"...\n" +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +msgid "The first command will apply migrations in `@app/migrations/db1` to the `db1` database, the second command will apply migrations in `@app/migrations/db2` to `db2`, and so on." msgstr "" #. type: Title ### #: ../src/guide/databases/db-migrations.md #, no-wrap -msgid "Upgrading from Yii 2.0" +msgid "Upgrading from Yii2" msgstr "" #. type: Plain text #: ../src/guide/databases/db-migrations.md -msgid "Migrations in Yii 2.0 and the [yiisoft/db-migration](https://github.com/yiisoft/db-migration/) package are not compatible, and the `migration` table is also not compatible. A probable solution is to use structure dumps and rename the old `migration` table. Upon the initial execution of migrations, a new `migration` table with new fields will be created. All further changes in the database schema are applied using the new `migration` component and recorded in the new migration table." +msgid "Migrations in Yii2 and the [yiisoft/db-migration](https://github.com/yiisoft/db-migration/) package are not compatible, and the `migration` table is also not compatible. A probable solution is to use structure dumps and rename the old `migration` table. Upon the initial execution of migrations, a new `migration` table with new fields will be created. All further changes in the database schema are applied using the new `migration` component and recorded in the new migration table." msgstr "" diff --git a/_translations/po/ru/guide_databases_db-migrations.md.po b/_translations/po/ru/guide_databases_db-migrations.md.po index e2298805..760c0f61 100644 --- a/_translations/po/ru/guide_databases_db-migrations.md.po +++ b/_translations/po/ru/guide_databases_db-migrations.md.po @@ -6,7 +6,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" -"POT-Creation-Date: 2025-12-27 07:40+0000\n" +"POT-Creation-Date: 2025-12-27 07:55+0000\n" "PO-Revision-Date: 2025-09-04 11:19+0500\n" "Last-Translator: Automatically generated\n" "Language-Team: none\n" @@ -24,100 +24,202 @@ msgstr "" #. type: Plain text #: ../src/guide/databases/db-migrations.md -msgid "To use migrations, install [yiisoft/db-migration](https://github.com/yiisoft/db-migration/) package:" +msgid "During the course of developing and maintaining a database-driven application, the structure of the database being used evolves just like the source code does. For example, during the development of an application, a new table may be found necessary; after the application is deployed to production, it may be discovered that an index should be created to improve the query performance; and so on. Because a database structure change often requires some source code changes, Yii supports the so-called *database migration* feature that allows you to keep track of database changes in terms of *database migrations* which are version-controlled together with the source code." msgstr "" -#. type: Fenced code block (shell) +#. type: Plain text #: ../src/guide/databases/db-migrations.md -#, fuzzy, no-wrap -msgid "composer require yiisoft/db-migration\n" -msgstr "composer install yiisoft/security\n" +msgid "The following steps show how database migration can be used by a team during development:" +msgstr "" -#. type: Title ### +#. type: Bullet: '1. ' #: ../src/guide/databases/db-migrations.md -#, no-wrap -msgid "Example usage" +msgid "Tim creates a new migration (e.g. creates a new table, changes a column definition, etc.)." +msgstr "" + +#. type: Bullet: '2. ' +#: ../src/guide/databases/db-migrations.md +msgid "Tim commits the new migration into the source control system (e.g. Git, Mercurial)." +msgstr "" + +#. type: Bullet: '3. ' +#: ../src/guide/databases/db-migrations.md +msgid "Doug updates his repository from the source control system and receives the new migration." +msgstr "" + +#. type: Bullet: '4. ' +#: ../src/guide/databases/db-migrations.md +msgid "Doug applies the migration to his local development database, thereby synchronizing his database to reflect the changes that Tim has made." msgstr "" #. type: Plain text #: ../src/guide/databases/db-migrations.md -msgid "First, configure a DI container. Create `config/common/db.php` with the following content:" +msgid "And the following steps show how to deploy a new release with database migrations to production:" msgstr "" -#. type: Fenced code block (php) +#. type: Bullet: '1. ' +#: ../src/guide/databases/db-migrations.md +msgid "Scott creates a release tag for the project repository that contains some new database migrations." +msgstr "" + +#. type: Bullet: '2. ' +#: ../src/guide/databases/db-migrations.md +msgid "Scott updates the source code on the production server to the release tag." +msgstr "" + +#. type: Bullet: '3. ' +#: ../src/guide/databases/db-migrations.md +msgid "Scott applies any accumulated database migrations to the production database." +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +msgid "Yii provides a set of migration command line tools that allow you to:" +msgstr "" + +#. type: Bullet: '* ' +#: ../src/guide/databases/db-migrations.md +#, fuzzy +#| msgid "Sentry integration" +msgid "create new migrations;" +msgstr "Интеграция с Sentry" + +#. type: Bullet: '* ' +#: ../src/guide/databases/db-migrations.md +msgid "apply migrations;" +msgstr "" + +#. type: Bullet: '* ' +#: ../src/guide/databases/db-migrations.md +#, fuzzy +#| msgid "Sentry integration" +msgid "revert migrations;" +msgstr "Интеграция с Sentry" + +#. type: Bullet: '* ' +#: ../src/guide/databases/db-migrations.md +msgid "re-apply migrations;" +msgstr "" + +#. type: Bullet: '* ' +#: ../src/guide/databases/db-migrations.md +msgid "show migration history and status." +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +msgid "All these tools are accessible through the command `yii migrate`. In this section we will describe in detail how to accomplish various tasks using these tools." +msgstr "" + +#. type: Plain text #: ../src/guide/databases/db-migrations.md #, no-wrap msgid "" -" [\n" -" 'class' => SqliteConnection::class,\n" -" '__construct()' => [\n" -" 'dsn' => 'sqlite:' . __DIR__ . '/Data/yiitest.sq3'\n" -" ]\n" -" ]\n" -"];\n" +"> [!TIP]\n" +"> Migrations could affect not only database schema but adjust existing data to fit new schema, create RBAC\n" +"hierarchy or clean up cache.\n" +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +#, no-wrap +msgid "" +"> [!NOTE]\n" +"> When manipulating data using a migration you may find that using your Active Record or entity classes\n" +"> for this might be useful because some of the logic is already implemented there. Keep in mind however, that in contrast\n" +"> to code written in the migrations, whose nature is to stay constant forever, application logic is subject to change.\n" +"> So when using Active Record or entity classes in migration code, changes to the logic in the source code\n" +"> may accidentally break the existing migrations. For this reason migration code should be kept independent of other\n" +"> application logic such.\n" +msgstr "" + +#. type: Title ## +#: ../src/guide/databases/db-migrations.md +#, fuzzy, no-wrap +msgid "Initial configuration" +msgstr "Безопасная конфигурация сервера" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +msgid "To use migrations, install [yiisoft/db-migration](https://github.com/yiisoft/db-migration/) package:" +msgstr "" + +#. type: Fenced code block (sh) +#: ../src/guide/databases/db-migrations.md ../src/guide/start/databases.md +#, fuzzy, no-wrap +msgid "make composer require yiisoft/db-migration\n" +msgstr "composer install yiisoft/security\n" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +msgid "Create a directory to store migrations `src/Migration` right in the project root." msgstr "" #. type: Plain text #: ../src/guide/databases/db-migrations.md #, fuzzy #| msgid "Add the following to your php.ini:" -msgid "Add the following to `config/params.php`:" +msgid "Add the following configuration to `config/common/params.php`:" msgstr "Добавьте в свой php.ini следующее:" #. type: Fenced code block (php) -#: ../src/guide/databases/db-migrations.md +#: ../src/guide/databases/db-migrations.md ../src/guide/start/databases.md #, no-wrap msgid "" -"...\n" "'yiisoft/db-migration' => [\n" " 'newMigrationNamespace' => 'App\\\\Migration',\n" " 'sourceNamespaces' => ['App\\\\Migration'],\n" "],\n" -"...\n" msgstr "" #. type: Plain text #: ../src/guide/databases/db-migrations.md -msgid "Now test if it works:" +msgid "You need a database connection configured as well. See [Working with databases](../start/databases.md) for an example of configuring it for PostgreSQL." msgstr "" -#. type: Fenced code block (shell) +#. type: Title ### #: ../src/guide/databases/db-migrations.md #, no-wrap -msgid "./yii list migrate\n" +msgid "Creating a migration" msgstr "" -#. type: Title ### +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +#, fuzzy +#| msgid "To install the packages, run the following command:" +msgid "To create a new empty migration, run the following command:" +msgstr "Для установки пакетов выполните в консоли следующую команду:" + +#. type: Fenced code block (sh) #: ../src/guide/databases/db-migrations.md #, no-wrap -msgid "Creating a migration" +msgid "make yii migrate:create \n" msgstr "" #. type: Plain text #: ../src/guide/databases/db-migrations.md -msgid "To work with migrations, you can use the provided [view](https://github.com/yiisoft/db-migration/tree/master/resources/views)." +msgid "The required `name` argument gives a brief description about the new migration. For example, if the migration is about creating a new table named *news*, you may use the name `create_news_table` and run the following command:" msgstr "" -#. type: Fenced code block (shell) +#. type: Fenced code block #: ../src/guide/databases/db-migrations.md #, no-wrap -msgid "./yii migrate:create my_first_table --command=table --fields=name,example --table-comment=my_first_table\n" +msgid "make yii migrate:create create_news_table\n" msgstr "" #. type: Plain text #: ../src/guide/databases/db-migrations.md -#, fuzzy -#| msgid "That's equal to the following:" -msgid "That would generate the following:" -msgstr "Это соответствует:" +#, no-wrap +msgid "" +"> [!NOTE]\n" +"> Because the `name` argument will be used as part of the generated migration class name,\n" +"> it should only contain letters, digits, and/or underscore characters.\n" +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +msgid "The above command will create a new PHP class file named `src/Migration/M251225221906CreateNewsTable.php`. The file contains the following code which mainly declares a migration class with the skeleton code:" +msgstr "" #. type: Fenced code block (php) #: ../src/guide/databases/db-migrations.md @@ -131,43 +233,759 @@ msgid "" "\n" "use Yiisoft\\Db\\Migration\\MigrationBuilder;\n" "use Yiisoft\\Db\\Migration\\RevertibleMigrationInterface;\n" -"use Yiisoft\\Db\\Migration\\TransactionalMigrationInterface;\n" "\n" -"/**\n" -" * Handles the creation of a table `my_first_table`.\n" -" */\n" -"final class M240115143455CreateMyFirstTableTable implements RevertibleMigrationInterface, TransactionalMigrationInterface\n" +"final class M251225221906CreateNewsTable implements RevertibleMigrationInterface\n" "{\n" " public function up(MigrationBuilder $b): void\n" " {\n" -" $b->createTable('my_first_table', [\n" -" 'id' => $b->primaryKey(),\n" -" 'name',\n" -" 'example',\n" +" // TODO: Implement the logic to apply the migration.\n" +" }\n" +"\n" +" public function down(MigrationBuilder $b): void\n" +" {\n" +" // TODO: Implement the logic to revert the migration.\n" +" }\n" +"}\n" +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +msgid "In the migration class, you are expected to write code in the `up()` method that makes changes to the database structure. You may also want to write code in the `down()` method to revert the changes made by `up()`. The `up()` method is invoked when you upgrade the database with this migration, while the `down()` method is invoked when you downgrade the database. The following code shows how you may implement the migration class to create a `news` table:" +msgstr "" + +#. type: Fenced code block (php) +#: ../src/guide/databases/db-migrations.md +#, no-wrap +msgid "" +"columnBuilder();\n" +"\n" +" $b->createTable('news', [\n" +" 'id' => $cb::uuidPrimaryKey(),\n" +" 'title' => $cb::string()->notNull(),\n" +" 'content' => $cb::text(),\n" " ]);\n" -" \n" -" $b->addCommentOnTable('my_first_table', 'dest');\n" " }\n" "\n" " public function down(MigrationBuilder $b): void\n" " {\n" -" $b->dropTable('my_first_table');\n" +" $b->dropTable('news');\n" " }\n" "}\n" msgstr "" #. type: Plain text #: ../src/guide/databases/db-migrations.md -msgid "For more information [see](https://github.com/yiisoft/db-migration/tree/master/docs/guide/en)" +#, no-wrap +msgid "" +"TODO: explain $b and $qb\n" +"Below is the list of all these database accessing methods:\n" +msgstr "" + +#. type: Title ### +#: ../src/guide/databases/db-migrations.md +#, no-wrap +msgid "Irreversible migrations" +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +msgid "Not all migrations are reversible. For example, if the `up()` method deletes a row of a table, you may not be able to recover this row in the `down()` method. Sometimes, you may be just too lazy to implement the `down()`, because it is not very common to revert database migrations. In this case, you should implement `Yiisoft\\Db\\Migration\\MigrationInterface` that has `up()` only." +msgstr "" + +#. type: Title ### +#: ../src/guide/databases/db-migrations.md +#, no-wrap +msgid "Transactional migrations (TODO: update!!!)" +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +msgid "While performing complex DB migrations, it is important to ensure each migration to either succeed or fail as a whole so that the database can maintain integrity and consistency. To achieve this goal, it is recommended that you enclose the DB operations of each migration in a [transaction](db-dao.md#performing-transactions)." +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +msgid "An even easier way of implementing transactional migrations is to put migration code in the `safeUp()` and `safeDown()` methods. These two methods differ from `up()` and `down()` in that they are enclosed implicitly in a transaction. As a result, if any operation in these methods fails, all prior operations will be rolled back automatically." +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +msgid "In the following example, besides creating the `news` table we also insert an initial row into this table." +msgstr "" + +#. type: Fenced code block (php) +#: ../src/guide/databases/db-migrations.md +#, no-wrap +msgid "" +"createTable('news', [\n" +" 'id' => $this->primaryKey(),\n" +" 'title' => $this->string()->notNull(),\n" +" 'content' => $this->text(),\n" +" ]);\n" +"\n" +" $this->insert('news', [\n" +" 'title' => 'test 1',\n" +" 'content' => 'content 1',\n" +" ]);\n" +" }\n" +"\n" +" public function safeDown()\n" +" {\n" +" $this->delete('news', ['id' => 1]);\n" +" $this->dropTable('news');\n" +" }\n" +"}\n" +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +msgid "Note that usually when you perform multiple DB operations in `safeUp()`, you should reverse their execution order in `safeDown()`. In the above example we first create the table and then insert a row in `safeUp()`; while in `safeDown()` we first delete the row and then drop the table." +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +#, no-wrap +msgid "" +"> Note: Not all DBMS support transactions. And some DB queries cannot be put into a transaction. For some examples,\n" +"please refer to [implicit commit](https://dev.mysql.com/doc/refman/5.7/en/implicit-commit.html). If this is the case,\n" +"you should still implement `up()` and `down()`, instead.\n" +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +#, no-wrap +msgid "TODO: TransactionalMigrationInterface\n" +msgstr "" + +#. type: Title ## +#: ../src/guide/databases/db-migrations.md +#, no-wrap +msgid "TODO: update" +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +msgid "The base migration class [[yii\\db\\Migration]] exposes a database connection via the [[yii\\db\\Migration::db|db]] property. You can use it to manipulate the database schema using the methods as described in [Working with Database Schema](db-dao.md#database-schema)." +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +#, no-wrap +msgid "" +"Rather than using physical types, when creating a table or column you should use *abstract types*\n" +"so that your migrations are independent of specific DBMS. The [[yii\\db\\Schema]] class defines\n" +"a set of constants to represent the supported abstract types. These constants are named in the format\n" +"of `TYPE_`. For example, `TYPE_PK` refers to auto-incremental primary key type; `TYPE_STRING`\n" +"refers to a string type. When a migration is applied to a particular database, the abstract types\n" +"will be translated into the corresponding physical types. In the case of MySQL, `TYPE_PK` will be turned\n" +"into `int(11) NOT NULL AUTO_INCREMENT PRIMARY KEY`, while `TYPE_STRING` becomes `varchar(255)`.\n" +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +msgid "You can append additional constraints when using abstract types. In the above example, ` NOT NULL` is appended to `Schema::TYPE_STRING` to specify that the column cannot be `null`." +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +#, no-wrap +msgid "" +"> Info: The mapping between abstract types and physical types is specified by\n" +"the [[yii\\db\\QueryBuilder::$typeMap|$typeMap]] property in each concrete `QueryBuilder` class.\n" +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +msgid "Since version 2.0.6, you can make use of the newly introduced schema builder which provides more convenient way of defining column schema. So the migration above could be written like the following:" +msgstr "" + +#. type: Fenced code block (php) +#: ../src/guide/databases/db-migrations.md +#, no-wrap +msgid "" +"createTable('news', [\n" +" 'id' => $this->primaryKey(),\n" +" 'title' => $this->string()->notNull(),\n" +" 'content' => $this->text(),\n" +" ]);\n" +" }\n" +"\n" +" public function down()\n" +" {\n" +" $this->dropTable('news');\n" +" }\n" +"}\n" +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +msgid "A list of all available methods for defining the column types is available in the API documentation of [[yii\\db\\SchemaBuilderTrait]]." +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +#, no-wrap +msgid "" +"> Info: The generated file permissions and ownership will be determined by the current environment. This might lead to\n" +"inaccessible files. This could, for example, happen when the migration is created within a docker container\n" +"and the files are edited on the host. In this case the `newFileMode` and/or `newFileOwnership` of the MigrateController\n" +"can be changed. E.g. in the application config:\n" +msgstr "" + +#. type: Fenced code block (php) +#: ../src/guide/databases/db-migrations.md +#, no-wrap +msgid "" +" [\n" +" 'migrate' => [\n" +" 'class' => 'yii\\console\\controllers\\MigrateController',\n" +" 'newFileOwnership' => '1000:1000', # Default WSL user id\n" +" 'newFileMode' => 0660,\n" +" ],\n" +" ],\n" +" ];\n" +msgstr "" + +#. type: Title ## +#: ../src/guide/databases/db-migrations.md +#, no-wrap +msgid "Generating Migrations (TODO: likely is OK but...)" +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +msgid "The command provides a convenient way to create migrations using the provided [view](https://github.com/yiisoft/db-migration/tree/master/resources/views):" +msgstr "" + +#. type: Fenced code block (shell) +#: ../src/guide/databases/db-migrations.md +#, no-wrap +msgid "make yii migrate:create my_first_table --command=table --fields=name,example --table-comment=my_first_table\n" +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +#, fuzzy +#| msgid "That's equal to the following:" +msgid "That would generate the following:" +msgstr "Это соответствует:" + +#. type: Fenced code block (php) +#: ../src/guide/databases/db-migrations.md +#, no-wrap +msgid "" +"createTable('my_first_table', [\n" +" 'id' => $b->primaryKey(),\n" +" 'name',\n" +" 'example',\n" +" ]);\n" +" \n" +" $b->addCommentOnTable('my_first_table', 'dest');\n" +" }\n" +"\n" +" public function down(MigrationBuilder $b): void\n" +" {\n" +" $b->dropTable('my_first_table');\n" +" }\n" +"}\n" +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +msgid "For more information [see](https://github.com/yiisoft/db-migration/tree/master/docs/guide/en)" +msgstr "" + +#. type: Title ## +#: ../src/guide/databases/db-migrations.md +#, fuzzy, no-wrap +#| msgid "Configuration" +msgid "Applying Migrations" +msgstr "Настройка" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +msgid "To upgrade a database to its latest structure, you should apply all available new migrations using the following command:" +msgstr "" + +#. type: Fenced code block +#: ../src/guide/databases/db-migrations.md +#, no-wrap +msgid "yii migrate\n" +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +msgid "This command will list all migrations that have not been applied so far. If you confirm that you want to apply these migrations, it will run the `up()` or `safeUp()` method in every new migration class, one after another, in the order of their timestamp values. If any of the migrations fails, the command will quit without applying the rest of the migrations." +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +#, no-wrap +msgid "" +"> Tip: In case you don't have command line at your server you may try [web shell](https://github.com/samdark/yii2-webshell)\n" +"> extension.\n" +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +msgid "For each migration that has been successfully applied, the command will insert a row into a database table named `migration` to record the successful application of the migration. This will allow the migration tool to identify which migrations have been applied and which have not." +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +#, no-wrap +msgid "" +"> Info: The migration tool will automatically create the `migration` table in the database specified by\n" +"the [[yii\\console\\controllers\\MigrateController::db|db]] option of the command. By default, the database\n" +"is specified by the `db` [application component](structure-application-components.md).\n" +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +msgid "Sometimes, you may only want to apply one or a few new migrations, instead of all available migrations. You can do so by specifying the number of migrations that you want to apply when running the command. For example, the following command will try to apply the next three available migrations:" +msgstr "" + +#. type: Fenced code block +#: ../src/guide/databases/db-migrations.md +#, no-wrap +msgid "yii migrate 3\n" +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +msgid "You can also explicitly specify a particular migration to which the database should be migrated by using the `migrate/to` command in one of the following formats:" +msgstr "" + +#. type: Fenced code block +#: ../src/guide/databases/db-migrations.md +#, no-wrap +msgid "" +"yii migrate/to 150101_185401 # using timestamp to specify the migration\n" +"yii migrate/to \"2015-01-01 18:54:01\" # using a string that can be parsed by strtotime()\n" +"yii migrate/to m150101_185401_create_news_table # using full name\n" +"yii migrate/to 1392853618 # using UNIX timestamp\n" +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +msgid "If there are any unapplied migrations earlier than the specified one, they will all be applied before the specified migration is applied." +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +msgid "If the specified migration has already been applied before, any later applied migrations will be reverted." +msgstr "" + +#. type: Title ## +#: ../src/guide/databases/db-migrations.md +#, fuzzy, no-wrap +#| msgid "Defining aliases " +msgid "Reverting Migrations " +msgstr "Определение псевдонимов " + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +msgid "To revert (undo) one or multiple migrations that have been applied before, you can run the following command:" +msgstr "" + +#. type: Fenced code block +#: ../src/guide/databases/db-migrations.md +#, no-wrap +msgid "" +"yii migrate/down # revert the most recently applied migration\n" +"yii migrate/down 3 # revert the most 3 recently applied migrations\n" +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +#, no-wrap +msgid "" +"> Note: Not all migrations are reversible. Trying to revert such migrations will cause an error and stop the\n" +"entire reverting process.\n" +msgstr "" + +#. type: Title ## +#: ../src/guide/databases/db-migrations.md +#, fuzzy, no-wrap +#| msgid "Resolving aliases " +msgid "Redoing Migrations " +msgstr "Разрешение псевдонимов " + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +msgid "Redoing migrations means first reverting the specified migrations and then applying again. This can be done as follows:" +msgstr "" + +#. type: Fenced code block +#: ../src/guide/databases/db-migrations.md +#, no-wrap +msgid "" +"yii migrate/redo # redo the last applied migration\n" +"yii migrate/redo 3 # redo the last 3 applied migrations\n" +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +#, no-wrap +msgid "> Note: If a migration is not reversible, you will not be able to redo it.\n" +msgstr "" + +#. type: Title ## +#: ../src/guide/databases/db-migrations.md +#, fuzzy, no-wrap +#| msgid "Resolving aliases " +msgid "Refreshing Migrations " +msgstr "Разрешение псевдонимов " + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +msgid "Since Yii 2.0.13 you can delete all tables and foreign keys from the database and apply all migrations from the beginning." +msgstr "" + +#. type: Fenced code block +#: ../src/guide/databases/db-migrations.md +#, no-wrap +msgid "yii migrate/fresh # truncate the database and apply all migrations from the beginning\n" +msgstr "" + +#. type: Title ## +#: ../src/guide/databases/db-migrations.md +#, fuzzy, no-wrap +#| msgid "Resolving aliases " +msgid "Listing Migrations " +msgstr "Разрешение псевдонимов " + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +msgid "To list which migrations have been applied and which are not, you may use the following commands:" +msgstr "" + +#. type: Fenced code block +#: ../src/guide/databases/db-migrations.md +#, no-wrap +msgid "" +"yii migrate/history # showing the last 10 applied migrations\n" +"yii migrate/history 5 # showing the last 5 applied migrations\n" +"yii migrate/history all # showing all applied migrations\n" +"\n" +"yii migrate/new # showing the first 10 new migrations\n" +"yii migrate/new 5 # showing the first 5 new migrations\n" +"yii migrate/new all # showing all new migrations\n" +msgstr "" + +#. type: Title ## +#: ../src/guide/databases/db-migrations.md +#, fuzzy, no-wrap +#| msgid "Resolving aliases " +msgid "Modifying Migration History " +msgstr "Разрешение псевдонимов " + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +msgid "Instead of actually applying or reverting migrations, sometimes you may simply want to mark that your database has been upgraded to a particular migration. This often happens when you manually change the database to a particular state and you do not want the migration(s) for that change to be re-applied later. You can achieve this goal with the following command:" +msgstr "" + +#. type: Fenced code block +#: ../src/guide/databases/db-migrations.md +#, no-wrap +msgid "" +"yii migrate/mark 150101_185401 # using timestamp to specify the migration\n" +"yii migrate/mark \"2015-01-01 18:54:01\" # using a string that can be parsed by strtotime()\n" +"yii migrate/mark m150101_185401_create_news_table # using full name\n" +"yii migrate/mark 1392853618 # using UNIX timestamp\n" +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +msgid "The command will modify the `migration` table by adding or deleting certain rows to indicate that the database has been applied migrations to the specified one. No migrations will be applied or reverted by this command." +msgstr "" + +#. type: Title ## +#: ../src/guide/databases/db-migrations.md +#, fuzzy, no-wrap +#| msgid "Resolving aliases " +msgid "Customizing Migrations " +msgstr "Разрешение псевдонимов " + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +msgid "There are several ways to customize the migration command." +msgstr "" + +#. type: Title ### +#: ../src/guide/databases/db-migrations.md +#, fuzzy, no-wrap +#| msgid "Resolving aliases " +msgid "Using Command Line Options " +msgstr "Разрешение псевдонимов " + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +msgid "The migration command comes with a few command-line options that can be used to customize its behaviors:" +msgstr "" + +#. type: Bullet: '* ' +#: ../src/guide/databases/db-migrations.md +msgid "`interactive`: boolean (defaults to `true`), specifies whether to perform migrations in an interactive mode. When this is `true`, the user will be prompted before the command performs certain actions. You may want to set this to `false` if the command is being used in a background process." +msgstr "" + +#. type: Bullet: '* ' +#: ../src/guide/databases/db-migrations.md +msgid "`migrationPath`: string|array (defaults to `@app/migrations`), specifies the directory storing all migration class files. This can be specified as either a directory path or a path [alias](concept-aliases.md). Note that the directory must exist, or the command may trigger an error. Since version 2.0.12 an array can be specified for loading migrations from multiple sources." +msgstr "" + +#. type: Bullet: '* ' +#: ../src/guide/databases/db-migrations.md +msgid "`migrationTable`: string (defaults to `migration`), specifies the name of the database table for storing migration history information. The table will be automatically created by the command if it does not exist. You may also manually create it using the structure `version varchar(255) primary key, apply_time integer`." +msgstr "" + +#. type: Bullet: '* ' +#: ../src/guide/databases/db-migrations.md +msgid "`db`: string (defaults to `db`), specifies the ID of the database [application component](structure-application-components.md). It represents the database that will be migrated using this command." +msgstr "" + +#. type: Bullet: '* ' +#: ../src/guide/databases/db-migrations.md +msgid "`templateFile`: string (defaults to `@yii/views/migration.php`), specifies the path of the template file that is used for generating skeleton migration class files. This can be specified as either a file path or a path [alias](concept-aliases.md). The template file is a PHP script in which you can use a predefined variable named `$className` to get the migration class name." +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +#, no-wrap +msgid "" +"* `generatorTemplateFiles`: array (defaults to `[\n" +" 'create_table' => '@yii/views/createTableMigration.php',\n" +" 'drop_table' => '@yii/views/dropTableMigration.php',\n" +" 'add_column' => '@yii/views/addColumnMigration.php',\n" +" 'drop_column' => '@yii/views/dropColumnMigration.php',\n" +" 'create_junction' => '@yii/views/createTableMigration.php'\n" +" ]`), specifies template files for generating migration code. See \"[Generating Migrations](#generating-migrations)\"\n" +" for more details.\n" +msgstr "" + +#. type: Bullet: '* ' +#: ../src/guide/databases/db-migrations.md +msgid "`fields`: array of column definition strings used for creating migration code. Defaults to `[]`. The format of each definition is `COLUMN_NAME:COLUMN_TYPE:COLUMN_DECORATOR`. For example, `--fields=name:string(12):notNull` produces a string column of size 12 which is not `null`." +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +msgid "The following example shows how you can use these options." +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +msgid "For example, if we want to migrate a `forum` module whose migration files are located within the module's `migrations` directory, we can use the following command:" +msgstr "" + +#. type: Fenced code block +#: ../src/guide/databases/db-migrations.md +#, no-wrap +msgid "" +"# migrate the migrations in a forum module non-interactively\n" +"yii migrate --migrationPath=@app/modules/forum/migrations --interactive=0\n" +msgstr "" + +#. type: Title ### +#: ../src/guide/databases/db-migrations.md +#, fuzzy, no-wrap +#| msgid "Sentry integration" +msgid "Separated Migrations" +msgstr "Интеграция с Sentry" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +msgid "Sometimes using single migration history for all project migrations is not desirable. For example: you may install some 'blog' extension, which contains fully separated functionality and contain its own migrations, which should not affect the ones dedicated to main project functionality." +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +msgid "If you want several migrations to be applied and tracked down completely separated from each other, you can configure multiple migration commands which will use different namespaces and migration history tables:" +msgstr "" + +#. type: Fenced code block (php) +#: ../src/guide/databases/db-migrations.md +#, no-wrap +msgid "" +"return [\n" +" 'controllerMap' => [\n" +" // Common migrations for the whole application\n" +" 'migrate-app' => [\n" +" 'class' => 'yii\\console\\controllers\\MigrateController',\n" +" 'migrationNamespaces' => ['app\\migrations'],\n" +" 'migrationTable' => 'migration_app',\n" +" 'migrationPath' => null,\n" +" ],\n" +" // Migrations for the specific project's module\n" +" 'migrate-module' => [\n" +" 'class' => 'yii\\console\\controllers\\MigrateController',\n" +" 'migrationNamespaces' => ['module\\migrations'],\n" +" 'migrationTable' => 'migration_module',\n" +" 'migrationPath' => null,\n" +" ],\n" +" // Migrations for the specific extension\n" +" 'migrate-rbac' => [\n" +" 'class' => 'yii\\console\\controllers\\MigrateController',\n" +" 'migrationPath' => '@yii/rbac/migrations',\n" +" 'migrationTable' => 'migration_rbac',\n" +" ],\n" +" ],\n" +"];\n" +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +msgid "Note that to synchronize database you now need to run multiple commands instead of one:" +msgstr "" + +#. type: Fenced code block +#: ../src/guide/databases/db-migrations.md +#, no-wrap +msgid "" +"yii migrate-app\n" +"yii migrate-module\n" +"yii migrate-rbac\n" +msgstr "" + +#. type: Title ## +#: ../src/guide/databases/db-migrations.md +#, fuzzy, no-wrap +#| msgid "Defining aliases " +msgid "Migrating Multiple Databases " +msgstr "Определение псевдонимов " + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +msgid "By default, migrations are applied to the same database specified by the `db` [application component](structure-application-components.md). If you want them to be applied to a different database, you may specify the `db` command-line option like shown below," +msgstr "" + +#. type: Fenced code block +#: ../src/guide/databases/db-migrations.md +#, no-wrap +msgid "yii migrate --db=db2\n" +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +msgid "The above command will apply migrations to the `db2` database." +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +msgid "Sometimes it may happen that you want to apply *some* of the migrations to one database, while some others to another database. To achieve this goal, when implementing a migration class you should explicitly specify the DB component ID that the migration would use, like the following:" +msgstr "" + +#. type: Fenced code block (php) +#: ../src/guide/databases/db-migrations.md +#, no-wrap +msgid "" +"db = 'db2';\n" +" parent::init();\n" +" }\n" +"}\n" +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +msgid "The above migration will be applied to `db2`, even if you specify a different database through the `db` command-line option. Note that the migration history will still be recorded in the database specified by the `db` command-line option." +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +msgid "If you have multiple migrations that use the same database, it is recommended that you create a base migration class with the above `init()` code. Then each migration class can extend from this base class." +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +#, no-wrap +msgid "" +"> Tip: Besides setting the [[yii\\db\\Migration::db|db]] property, you can also operate on different databases\n" +"by creating new database connections to them in your migration classes. You then use the [DAO methods](db-dao.md)\n" +"with these connections to manipulate different databases.\n" +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +msgid "Another strategy that you can take to migrate multiple databases is to keep migrations for different databases in different migration paths. Then you can migrate these databases in separate commands like the following:" +msgstr "" + +#. type: Fenced code block +#: ../src/guide/databases/db-migrations.md +#, no-wrap +msgid "" +"yii migrate --migrationPath=@app/migrations/db1 --db=db1\n" +"yii migrate --migrationPath=@app/migrations/db2 --db=db2\n" +"...\n" +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +msgid "The first command will apply migrations in `@app/migrations/db1` to the `db1` database, the second command will apply migrations in `@app/migrations/db2` to `db2`, and so on." msgstr "" #. type: Title ### #: ../src/guide/databases/db-migrations.md #, no-wrap -msgid "Upgrading from Yii 2.0" +msgid "Upgrading from Yii2" msgstr "" #. type: Plain text #: ../src/guide/databases/db-migrations.md -msgid "Migrations in Yii 2.0 and the [yiisoft/db-migration](https://github.com/yiisoft/db-migration/) package are not compatible, and the `migration` table is also not compatible. A probable solution is to use structure dumps and rename the old `migration` table. Upon the initial execution of migrations, a new `migration` table with new fields will be created. All further changes in the database schema are applied using the new `migration` component and recorded in the new migration table." +msgid "Migrations in Yii2 and the [yiisoft/db-migration](https://github.com/yiisoft/db-migration/) package are not compatible, and the `migration` table is also not compatible. A probable solution is to use structure dumps and rename the old `migration` table. Upon the initial execution of migrations, a new `migration` table with new fields will be created. All further changes in the database schema are applied using the new `migration` component and recorded in the new migration table." msgstr "" diff --git a/_translations/pot/guide_databases_db-migrations.md.pot b/_translations/pot/guide_databases_db-migrations.md.pot index 66c6438d..176b773a 100644 --- a/_translations/pot/guide_databases_db-migrations.md.pot +++ b/_translations/pot/guide_databases_db-migrations.md.pot @@ -7,7 +7,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" -"POT-Creation-Date: 2025-12-27 07:40+0000\n" +"POT-Creation-Date: 2025-12-27 07:55+0000\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -25,100 +25,235 @@ msgstr "" #. type: Plain text #: ../src/guide/databases/db-migrations.md msgid "" -"To use migrations, install [yiisoft/db-migration](https://github.com/yiisoft/" -"db-migration/) package:" +"During the course of developing and maintaining a database-driven " +"application, the structure of the database being used evolves just like the " +"source code does. For example, during the development of an application, a " +"new table may be found necessary; after the application is deployed to " +"production, it may be discovered that an index should be created to improve " +"the query performance; and so on. Because a database structure change often " +"requires some source code changes, Yii supports the so-called *database " +"migration* feature that allows you to keep track of database changes in " +"terms of *database migrations* which are version-controlled together with " +"the source code." msgstr "" -#. type: Fenced code block (shell) +#. type: Plain text #: ../src/guide/databases/db-migrations.md -#, no-wrap -msgid "composer require yiisoft/db-migration\n" +msgid "" +"The following steps show how database migration can be used by a team during " +"development:" msgstr "" -#. type: Title ### +#. type: Bullet: '1. ' +#: ../src/guide/databases/db-migrations.md +msgid "" +"Tim creates a new migration (e.g. creates a new table, changes a column " +"definition, etc.)." +msgstr "" + +#. type: Bullet: '2. ' +#: ../src/guide/databases/db-migrations.md +msgid "" +"Tim commits the new migration into the source control system (e.g. Git, " +"Mercurial)." +msgstr "" + +#. type: Bullet: '3. ' +#: ../src/guide/databases/db-migrations.md +msgid "" +"Doug updates his repository from the source control system and receives the " +"new migration." +msgstr "" + +#. type: Bullet: '4. ' +#: ../src/guide/databases/db-migrations.md +msgid "" +"Doug applies the migration to his local development database, thereby " +"synchronizing his database to reflect the changes that Tim has made." +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +msgid "" +"And the following steps show how to deploy a new release with database " +"migrations to production:" +msgstr "" + +#. type: Bullet: '1. ' +#: ../src/guide/databases/db-migrations.md +msgid "" +"Scott creates a release tag for the project repository that contains some " +"new database migrations." +msgstr "" + +#. type: Bullet: '2. ' +#: ../src/guide/databases/db-migrations.md +msgid "" +"Scott updates the source code on the production server to the release tag." +msgstr "" + +#. type: Bullet: '3. ' +#: ../src/guide/databases/db-migrations.md +msgid "" +"Scott applies any accumulated database migrations to the production database." +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +msgid "Yii provides a set of migration command line tools that allow you to:" +msgstr "" + +#. type: Bullet: '* ' +#: ../src/guide/databases/db-migrations.md +msgid "create new migrations;" +msgstr "" + +#. type: Bullet: '* ' +#: ../src/guide/databases/db-migrations.md +msgid "apply migrations;" +msgstr "" + +#. type: Bullet: '* ' +#: ../src/guide/databases/db-migrations.md +msgid "revert migrations;" +msgstr "" + +#. type: Bullet: '* ' +#: ../src/guide/databases/db-migrations.md +msgid "re-apply migrations;" +msgstr "" + +#. type: Bullet: '* ' +#: ../src/guide/databases/db-migrations.md +msgid "show migration history and status." +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +msgid "" +"All these tools are accessible through the command `yii migrate`. In this " +"section we will describe in detail how to accomplish various tasks using " +"these tools." +msgstr "" + +#. type: Plain text #: ../src/guide/databases/db-migrations.md #, no-wrap -msgid "Example usage" +msgid "" +"> [!TIP]\n" +"> Migrations could affect not only database schema but adjust existing data to fit new schema, create RBAC\n" +"hierarchy or clean up cache.\n" msgstr "" #. type: Plain text #: ../src/guide/databases/db-migrations.md +#, no-wrap msgid "" -"First, configure a DI container. Create `config/common/db.php` with the " -"following content:" +"> [!NOTE]\n" +"> When manipulating data using a migration you may find that using your Active Record or entity classes\n" +"> for this might be useful because some of the logic is already implemented there. Keep in mind however, that in contrast\n" +"> to code written in the migrations, whose nature is to stay constant forever, application logic is subject to change.\n" +"> So when using Active Record or entity classes in migration code, changes to the logic in the source code\n" +"> may accidentally break the existing migrations. For this reason migration code should be kept independent of other\n" +"> application logic such.\n" msgstr "" -#. type: Fenced code block (php) +#. type: Title ## #: ../src/guide/databases/db-migrations.md #, no-wrap +msgid "Initial configuration" +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md msgid "" -" [\n" -" 'class' => SqliteConnection::class,\n" -" '__construct()' => [\n" -" 'dsn' => 'sqlite:' . __DIR__ . '/Data/yiitest.sq3'\n" -" ]\n" -" ]\n" -"];\n" +"To use migrations, install [yiisoft/db-migration](https://github.com/yiisoft/" +"db-migration/) package:" +msgstr "" + +#. type: Fenced code block (sh) +#: ../src/guide/databases/db-migrations.md ../src/guide/start/databases.md +#, no-wrap +msgid "make composer require yiisoft/db-migration\n" msgstr "" #. type: Plain text #: ../src/guide/databases/db-migrations.md -msgid "Add the following to `config/params.php`:" +msgid "" +"Create a directory to store migrations `src/Migration` right in the project " +"root." msgstr "" -#. type: Fenced code block (php) +#. type: Plain text #: ../src/guide/databases/db-migrations.md +msgid "Add the following configuration to `config/common/params.php`:" +msgstr "" + +#. type: Fenced code block (php) +#: ../src/guide/databases/db-migrations.md ../src/guide/start/databases.md #, no-wrap msgid "" -"...\n" "'yiisoft/db-migration' => [\n" " 'newMigrationNamespace' => 'App\\\\Migration',\n" " 'sourceNamespaces' => ['App\\\\Migration'],\n" "],\n" -"...\n" msgstr "" #. type: Plain text #: ../src/guide/databases/db-migrations.md -msgid "Now test if it works:" +msgid "" +"You need a database connection configured as well. See [Working with " +"databases](../start/databases.md) for an example of configuring it for " +"PostgreSQL." msgstr "" -#. type: Fenced code block (shell) +#. type: Title ### #: ../src/guide/databases/db-migrations.md #, no-wrap -msgid "./yii list migrate\n" +msgid "Creating a migration" msgstr "" -#. type: Title ### +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +msgid "To create a new empty migration, run the following command:" +msgstr "" + +#. type: Fenced code block (sh) #: ../src/guide/databases/db-migrations.md #, no-wrap -msgid "Creating a migration" +msgid "make yii migrate:create \n" msgstr "" #. type: Plain text #: ../src/guide/databases/db-migrations.md msgid "" -"To work with migrations, you can use the provided [view](https://github.com/" -"yiisoft/db-migration/tree/master/resources/views)." +"The required `name` argument gives a brief description about the new " +"migration. For example, if the migration is about creating a new table named " +"*news*, you may use the name `create_news_table` and run the following " +"command:" msgstr "" -#. type: Fenced code block (shell) +#. type: Fenced code block #: ../src/guide/databases/db-migrations.md #, no-wrap -msgid "./yii migrate:create my_first_table --command=table --fields=name,example --table-comment=my_first_table\n" +msgid "make yii migrate:create create_news_table\n" msgstr "" #. type: Plain text #: ../src/guide/databases/db-migrations.md -msgid "That would generate the following:" +#, no-wrap +msgid "" +"> [!NOTE]\n" +"> Because the `name` argument will be used as part of the generated migration class name,\n" +"> it should only contain letters, digits, and/or underscore characters.\n" +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +msgid "" +"The above command will create a new PHP class file named `src/Migration/" +"M251225221906CreateNewsTable.php`. The file contains the following code " +"which mainly declares a migration class with the skeleton code:" msgstr "" #. type: Fenced code block (php) @@ -133,52 +268,900 @@ msgid "" "\n" "use Yiisoft\\Db\\Migration\\MigrationBuilder;\n" "use Yiisoft\\Db\\Migration\\RevertibleMigrationInterface;\n" -"use Yiisoft\\Db\\Migration\\TransactionalMigrationInterface;\n" "\n" -"/**\n" -" * Handles the creation of a table `my_first_table`.\n" -" */\n" -"final class M240115143455CreateMyFirstTableTable implements RevertibleMigrationInterface, TransactionalMigrationInterface\n" +"final class M251225221906CreateNewsTable implements RevertibleMigrationInterface\n" "{\n" " public function up(MigrationBuilder $b): void\n" " {\n" -" $b->createTable('my_first_table', [\n" -" 'id' => $b->primaryKey(),\n" -" 'name',\n" -" 'example',\n" +" // TODO: Implement the logic to apply the migration.\n" +" }\n" +"\n" +" public function down(MigrationBuilder $b): void\n" +" {\n" +" // TODO: Implement the logic to revert the migration.\n" +" }\n" +"}\n" +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +msgid "" +"In the migration class, you are expected to write code in the `up()` method " +"that makes changes to the database structure. You may also want to write " +"code in the `down()` method to revert the changes made by `up()`. The `up()` " +"method is invoked when you upgrade the database with this migration, while " +"the `down()` method is invoked when you downgrade the database. The " +"following code shows how you may implement the migration class to create a " +"`news` table:" +msgstr "" + +#. type: Fenced code block (php) +#: ../src/guide/databases/db-migrations.md +#, no-wrap +msgid "" +"columnBuilder();\n" +"\n" +" $b->createTable('news', [\n" +" 'id' => $cb::uuidPrimaryKey(),\n" +" 'title' => $cb::string()->notNull(),\n" +" 'content' => $cb::text(),\n" " ]);\n" -" \n" -" $b->addCommentOnTable('my_first_table', 'dest');\n" " }\n" "\n" " public function down(MigrationBuilder $b): void\n" " {\n" -" $b->dropTable('my_first_table');\n" +" $b->dropTable('news');\n" " }\n" "}\n" msgstr "" #. type: Plain text #: ../src/guide/databases/db-migrations.md +#, no-wrap msgid "" -"For more information [see](https://github.com/yiisoft/db-migration/tree/" -"master/docs/guide/en)" +"TODO: explain $b and $qb\n" +"Below is the list of all these database accessing methods:\n" +msgstr "" + +#. type: Title ### +#: ../src/guide/databases/db-migrations.md +#, no-wrap +msgid "Irreversible migrations" +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +msgid "" +"Not all migrations are reversible. For example, if the `up()` method deletes " +"a row of a table, you may not be able to recover this row in the `down()` " +"method. Sometimes, you may be just too lazy to implement the `down()`, " +"because it is not very common to revert database migrations. In this case, " +"you should implement `Yiisoft\\Db\\Migration\\MigrationInterface` that has " +"`up()` only." +msgstr "" + +#. type: Title ### +#: ../src/guide/databases/db-migrations.md +#, no-wrap +msgid "Transactional migrations (TODO: update!!!)" +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +msgid "" +"While performing complex DB migrations, it is important to ensure each " +"migration to either succeed or fail as a whole so that the database can " +"maintain integrity and consistency. To achieve this goal, it is recommended " +"that you enclose the DB operations of each migration in a [transaction](db-" +"dao.md#performing-transactions)." +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +msgid "" +"An even easier way of implementing transactional migrations is to put " +"migration code in the `safeUp()` and `safeDown()` methods. These two methods " +"differ from `up()` and `down()` in that they are enclosed implicitly in a " +"transaction. As a result, if any operation in these methods fails, all " +"prior operations will be rolled back automatically." +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +msgid "" +"In the following example, besides creating the `news` table we also insert " +"an initial row into this table." +msgstr "" + +#. type: Fenced code block (php) +#: ../src/guide/databases/db-migrations.md +#, no-wrap +msgid "" +"createTable('news', [\n" +" 'id' => $this->primaryKey(),\n" +" 'title' => $this->string()->notNull(),\n" +" 'content' => $this->text(),\n" +" ]);\n" +"\n" +" $this->insert('news', [\n" +" 'title' => 'test 1',\n" +" 'content' => 'content 1',\n" +" ]);\n" +" }\n" +"\n" +" public function safeDown()\n" +" {\n" +" $this->delete('news', ['id' => 1]);\n" +" $this->dropTable('news');\n" +" }\n" +"}\n" +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +msgid "" +"Note that usually when you perform multiple DB operations in `safeUp()`, you " +"should reverse their execution order in `safeDown()`. In the above example " +"we first create the table and then insert a row in `safeUp()`; while in " +"`safeDown()` we first delete the row and then drop the table." +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +#, no-wrap +msgid "" +"> Note: Not all DBMS support transactions. And some DB queries cannot be put into a transaction. For some examples,\n" +"please refer to [implicit commit](https://dev.mysql.com/doc/refman/5.7/en/implicit-commit.html). If this is the case,\n" +"you should still implement `up()` and `down()`, instead.\n" +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +#, no-wrap +msgid "TODO: TransactionalMigrationInterface\n" +msgstr "" + +#. type: Title ## +#: ../src/guide/databases/db-migrations.md +#, no-wrap +msgid "TODO: update" +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +msgid "" +"The base migration class [[yii\\db\\Migration]] exposes a database " +"connection via the [[yii\\db\\Migration::db|db]] property. You can use it to " +"manipulate the database schema using the methods as described in [Working " +"with Database Schema](db-dao.md#database-schema)." +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +#, no-wrap +msgid "" +"Rather than using physical types, when creating a table or column you should use *abstract types*\n" +"so that your migrations are independent of specific DBMS. The [[yii\\db\\Schema]] class defines\n" +"a set of constants to represent the supported abstract types. These constants are named in the format\n" +"of `TYPE_`. For example, `TYPE_PK` refers to auto-incremental primary key type; `TYPE_STRING`\n" +"refers to a string type. When a migration is applied to a particular database, the abstract types\n" +"will be translated into the corresponding physical types. In the case of MySQL, `TYPE_PK` will be turned\n" +"into `int(11) NOT NULL AUTO_INCREMENT PRIMARY KEY`, while `TYPE_STRING` becomes `varchar(255)`.\n" +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +msgid "" +"You can append additional constraints when using abstract types. In the " +"above example, ` NOT NULL` is appended to `Schema::TYPE_STRING` to specify " +"that the column cannot be `null`." +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +#, no-wrap +msgid "" +"> Info: The mapping between abstract types and physical types is specified by\n" +"the [[yii\\db\\QueryBuilder::$typeMap|$typeMap]] property in each concrete `QueryBuilder` class.\n" +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +msgid "" +"Since version 2.0.6, you can make use of the newly introduced schema builder " +"which provides more convenient way of defining column schema. So the " +"migration above could be written like the following:" +msgstr "" + +#. type: Fenced code block (php) +#: ../src/guide/databases/db-migrations.md +#, no-wrap +msgid "" +"createTable('news', [\n" +" 'id' => $this->primaryKey(),\n" +" 'title' => $this->string()->notNull(),\n" +" 'content' => $this->text(),\n" +" ]);\n" +" }\n" +"\n" +" public function down()\n" +" {\n" +" $this->dropTable('news');\n" +" }\n" +"}\n" +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +msgid "" +"A list of all available methods for defining the column types is available " +"in the API documentation of [[yii\\db\\SchemaBuilderTrait]]." +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +#, no-wrap +msgid "" +"> Info: The generated file permissions and ownership will be determined by the current environment. This might lead to\n" +"inaccessible files. This could, for example, happen when the migration is created within a docker container\n" +"and the files are edited on the host. In this case the `newFileMode` and/or `newFileOwnership` of the MigrateController\n" +"can be changed. E.g. in the application config:\n" +msgstr "" + +#. type: Fenced code block (php) +#: ../src/guide/databases/db-migrations.md +#, no-wrap +msgid "" +" [\n" +" 'migrate' => [\n" +" 'class' => 'yii\\console\\controllers\\MigrateController',\n" +" 'newFileOwnership' => '1000:1000', # Default WSL user id\n" +" 'newFileMode' => 0660,\n" +" ],\n" +" ],\n" +" ];\n" +msgstr "" + +#. type: Title ## +#: ../src/guide/databases/db-migrations.md +#, no-wrap +msgid "Generating Migrations (TODO: likely is OK but...)" +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +msgid "" +"The command provides a convenient way to create migrations using the " +"provided [view](https://github.com/yiisoft/db-migration/tree/master/" +"resources/views):" +msgstr "" + +#. type: Fenced code block (shell) +#: ../src/guide/databases/db-migrations.md +#, no-wrap +msgid "make yii migrate:create my_first_table --command=table --fields=name,example --table-comment=my_first_table\n" +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +msgid "That would generate the following:" +msgstr "" + +#. type: Fenced code block (php) +#: ../src/guide/databases/db-migrations.md +#, no-wrap +msgid "" +"createTable('my_first_table', [\n" +" 'id' => $b->primaryKey(),\n" +" 'name',\n" +" 'example',\n" +" ]);\n" +" \n" +" $b->addCommentOnTable('my_first_table', 'dest');\n" +" }\n" +"\n" +" public function down(MigrationBuilder $b): void\n" +" {\n" +" $b->dropTable('my_first_table');\n" +" }\n" +"}\n" +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +msgid "" +"For more information [see](https://github.com/yiisoft/db-migration/tree/" +"master/docs/guide/en)" +msgstr "" + +#. type: Title ## +#: ../src/guide/databases/db-migrations.md +#, no-wrap +msgid "Applying Migrations" +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +msgid "" +"To upgrade a database to its latest structure, you should apply all " +"available new migrations using the following command:" +msgstr "" + +#. type: Fenced code block +#: ../src/guide/databases/db-migrations.md +#, no-wrap +msgid "yii migrate\n" +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +msgid "" +"This command will list all migrations that have not been applied so far. If " +"you confirm that you want to apply these migrations, it will run the `up()` " +"or `safeUp()` method in every new migration class, one after another, in the " +"order of their timestamp values. If any of the migrations fails, the command " +"will quit without applying the rest of the migrations." +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +#, no-wrap +msgid "" +"> Tip: In case you don't have command line at your server you may try [web shell](https://github.com/samdark/yii2-webshell)\n" +"> extension.\n" +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +msgid "" +"For each migration that has been successfully applied, the command will " +"insert a row into a database table named `migration` to record the " +"successful application of the migration. This will allow the migration tool " +"to identify which migrations have been applied and which have not." +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +#, no-wrap +msgid "" +"> Info: The migration tool will automatically create the `migration` table in the database specified by\n" +"the [[yii\\console\\controllers\\MigrateController::db|db]] option of the command. By default, the database\n" +"is specified by the `db` [application component](structure-application-components.md).\n" +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +msgid "" +"Sometimes, you may only want to apply one or a few new migrations, instead " +"of all available migrations. You can do so by specifying the number of " +"migrations that you want to apply when running the command. For example, " +"the following command will try to apply the next three available migrations:" +msgstr "" + +#. type: Fenced code block +#: ../src/guide/databases/db-migrations.md +#, no-wrap +msgid "yii migrate 3\n" +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +msgid "" +"You can also explicitly specify a particular migration to which the database " +"should be migrated by using the `migrate/to` command in one of the following " +"formats:" +msgstr "" + +#. type: Fenced code block +#: ../src/guide/databases/db-migrations.md +#, no-wrap +msgid "" +"yii migrate/to 150101_185401 # using timestamp to specify the migration\n" +"yii migrate/to \"2015-01-01 18:54:01\" # using a string that can be parsed by strtotime()\n" +"yii migrate/to m150101_185401_create_news_table # using full name\n" +"yii migrate/to 1392853618 # using UNIX timestamp\n" +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +msgid "" +"If there are any unapplied migrations earlier than the specified one, they " +"will all be applied before the specified migration is applied." +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +msgid "" +"If the specified migration has already been applied before, any later " +"applied migrations will be reverted." +msgstr "" + +#. type: Title ## +#: ../src/guide/databases/db-migrations.md +#, no-wrap +msgid "Reverting Migrations " +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +msgid "" +"To revert (undo) one or multiple migrations that have been applied before, " +"you can run the following command:" +msgstr "" + +#. type: Fenced code block +#: ../src/guide/databases/db-migrations.md +#, no-wrap +msgid "" +"yii migrate/down # revert the most recently applied migration\n" +"yii migrate/down 3 # revert the most 3 recently applied migrations\n" +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +#, no-wrap +msgid "" +"> Note: Not all migrations are reversible. Trying to revert such migrations will cause an error and stop the\n" +"entire reverting process.\n" +msgstr "" + +#. type: Title ## +#: ../src/guide/databases/db-migrations.md +#, no-wrap +msgid "Redoing Migrations " +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +msgid "" +"Redoing migrations means first reverting the specified migrations and then " +"applying again. This can be done as follows:" +msgstr "" + +#. type: Fenced code block +#: ../src/guide/databases/db-migrations.md +#, no-wrap +msgid "" +"yii migrate/redo # redo the last applied migration\n" +"yii migrate/redo 3 # redo the last 3 applied migrations\n" +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +#, no-wrap +msgid "> Note: If a migration is not reversible, you will not be able to redo it.\n" +msgstr "" + +#. type: Title ## +#: ../src/guide/databases/db-migrations.md +#, no-wrap +msgid "Refreshing Migrations " +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +msgid "" +"Since Yii 2.0.13 you can delete all tables and foreign keys from the " +"database and apply all migrations from the beginning." +msgstr "" + +#. type: Fenced code block +#: ../src/guide/databases/db-migrations.md +#, no-wrap +msgid "yii migrate/fresh # truncate the database and apply all migrations from the beginning\n" +msgstr "" + +#. type: Title ## +#: ../src/guide/databases/db-migrations.md +#, no-wrap +msgid "Listing Migrations " +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +msgid "" +"To list which migrations have been applied and which are not, you may use " +"the following commands:" +msgstr "" + +#. type: Fenced code block +#: ../src/guide/databases/db-migrations.md +#, no-wrap +msgid "" +"yii migrate/history # showing the last 10 applied migrations\n" +"yii migrate/history 5 # showing the last 5 applied migrations\n" +"yii migrate/history all # showing all applied migrations\n" +"\n" +"yii migrate/new # showing the first 10 new migrations\n" +"yii migrate/new 5 # showing the first 5 new migrations\n" +"yii migrate/new all # showing all new migrations\n" +msgstr "" + +#. type: Title ## +#: ../src/guide/databases/db-migrations.md +#, no-wrap +msgid "Modifying Migration History " +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +msgid "" +"Instead of actually applying or reverting migrations, sometimes you may " +"simply want to mark that your database has been upgraded to a particular " +"migration. This often happens when you manually change the database to a " +"particular state and you do not want the migration(s) for that change to be " +"re-applied later. You can achieve this goal with the following command:" +msgstr "" + +#. type: Fenced code block +#: ../src/guide/databases/db-migrations.md +#, no-wrap +msgid "" +"yii migrate/mark 150101_185401 # using timestamp to specify the migration\n" +"yii migrate/mark \"2015-01-01 18:54:01\" # using a string that can be parsed by strtotime()\n" +"yii migrate/mark m150101_185401_create_news_table # using full name\n" +"yii migrate/mark 1392853618 # using UNIX timestamp\n" +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +msgid "" +"The command will modify the `migration` table by adding or deleting certain " +"rows to indicate that the database has been applied migrations to the " +"specified one. No migrations will be applied or reverted by this command." +msgstr "" + +#. type: Title ## +#: ../src/guide/databases/db-migrations.md +#, no-wrap +msgid "Customizing Migrations " +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +msgid "There are several ways to customize the migration command." +msgstr "" + +#. type: Title ### +#: ../src/guide/databases/db-migrations.md +#, no-wrap +msgid "Using Command Line Options " +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +msgid "" +"The migration command comes with a few command-line options that can be used " +"to customize its behaviors:" +msgstr "" + +#. type: Bullet: '* ' +#: ../src/guide/databases/db-migrations.md +msgid "" +"`interactive`: boolean (defaults to `true`), specifies whether to perform " +"migrations in an interactive mode. When this is `true`, the user will be " +"prompted before the command performs certain actions. You may want to set " +"this to `false` if the command is being used in a background process." +msgstr "" + +#. type: Bullet: '* ' +#: ../src/guide/databases/db-migrations.md +msgid "" +"`migrationPath`: string|array (defaults to `@app/migrations`), specifies the " +"directory storing all migration class files. This can be specified as either " +"a directory path or a path [alias](concept-aliases.md). Note that the " +"directory must exist, or the command may trigger an error. Since version " +"2.0.12 an array can be specified for loading migrations from multiple " +"sources." +msgstr "" + +#. type: Bullet: '* ' +#: ../src/guide/databases/db-migrations.md +msgid "" +"`migrationTable`: string (defaults to `migration`), specifies the name of " +"the database table for storing migration history information. The table will " +"be automatically created by the command if it does not exist. You may also " +"manually create it using the structure `version varchar(255) primary key, " +"apply_time integer`." +msgstr "" + +#. type: Bullet: '* ' +#: ../src/guide/databases/db-migrations.md +msgid "" +"`db`: string (defaults to `db`), specifies the ID of the database " +"[application component](structure-application-components.md). It represents " +"the database that will be migrated using this command." +msgstr "" + +#. type: Bullet: '* ' +#: ../src/guide/databases/db-migrations.md +msgid "" +"`templateFile`: string (defaults to `@yii/views/migration.php`), specifies " +"the path of the template file that is used for generating skeleton migration " +"class files. This can be specified as either a file path or a path [alias]" +"(concept-aliases.md). The template file is a PHP script in which you can use " +"a predefined variable named `$className` to get the migration class name." +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +#, no-wrap +msgid "" +"* `generatorTemplateFiles`: array (defaults to `[\n" +" 'create_table' => '@yii/views/createTableMigration.php',\n" +" 'drop_table' => '@yii/views/dropTableMigration.php',\n" +" 'add_column' => '@yii/views/addColumnMigration.php',\n" +" 'drop_column' => '@yii/views/dropColumnMigration.php',\n" +" 'create_junction' => '@yii/views/createTableMigration.php'\n" +" ]`), specifies template files for generating migration code. See \"[Generating Migrations](#generating-migrations)\"\n" +" for more details.\n" +msgstr "" + +#. type: Bullet: '* ' +#: ../src/guide/databases/db-migrations.md +msgid "" +"`fields`: array of column definition strings used for creating migration " +"code. Defaults to `[]`. The format of each definition is `COLUMN_NAME:" +"COLUMN_TYPE:COLUMN_DECORATOR`. For example, `--fields=name:string(12):" +"notNull` produces a string column of size 12 which is not `null`." +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +msgid "The following example shows how you can use these options." +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +msgid "" +"For example, if we want to migrate a `forum` module whose migration files " +"are located within the module's `migrations` directory, we can use the " +"following command:" +msgstr "" + +#. type: Fenced code block +#: ../src/guide/databases/db-migrations.md +#, no-wrap +msgid "" +"# migrate the migrations in a forum module non-interactively\n" +"yii migrate --migrationPath=@app/modules/forum/migrations --interactive=0\n" +msgstr "" + +#. type: Title ### +#: ../src/guide/databases/db-migrations.md +#, no-wrap +msgid "Separated Migrations" +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +msgid "" +"Sometimes using single migration history for all project migrations is not " +"desirable. For example: you may install some 'blog' extension, which " +"contains fully separated functionality and contain its own migrations, which " +"should not affect the ones dedicated to main project functionality." +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +msgid "" +"If you want several migrations to be applied and tracked down completely " +"separated from each other, you can configure multiple migration commands " +"which will use different namespaces and migration history tables:" +msgstr "" + +#. type: Fenced code block (php) +#: ../src/guide/databases/db-migrations.md +#, no-wrap +msgid "" +"return [\n" +" 'controllerMap' => [\n" +" // Common migrations for the whole application\n" +" 'migrate-app' => [\n" +" 'class' => 'yii\\console\\controllers\\MigrateController',\n" +" 'migrationNamespaces' => ['app\\migrations'],\n" +" 'migrationTable' => 'migration_app',\n" +" 'migrationPath' => null,\n" +" ],\n" +" // Migrations for the specific project's module\n" +" 'migrate-module' => [\n" +" 'class' => 'yii\\console\\controllers\\MigrateController',\n" +" 'migrationNamespaces' => ['module\\migrations'],\n" +" 'migrationTable' => 'migration_module',\n" +" 'migrationPath' => null,\n" +" ],\n" +" // Migrations for the specific extension\n" +" 'migrate-rbac' => [\n" +" 'class' => 'yii\\console\\controllers\\MigrateController',\n" +" 'migrationPath' => '@yii/rbac/migrations',\n" +" 'migrationTable' => 'migration_rbac',\n" +" ],\n" +" ],\n" +"];\n" +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +msgid "" +"Note that to synchronize database you now need to run multiple commands " +"instead of one:" +msgstr "" + +#. type: Fenced code block +#: ../src/guide/databases/db-migrations.md +#, no-wrap +msgid "" +"yii migrate-app\n" +"yii migrate-module\n" +"yii migrate-rbac\n" +msgstr "" + +#. type: Title ## +#: ../src/guide/databases/db-migrations.md +#, no-wrap +msgid "Migrating Multiple Databases " +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +msgid "" +"By default, migrations are applied to the same database specified by the " +"`db` [application component](structure-application-components.md). If you " +"want them to be applied to a different database, you may specify the `db` " +"command-line option like shown below," +msgstr "" + +#. type: Fenced code block +#: ../src/guide/databases/db-migrations.md +#, no-wrap +msgid "yii migrate --db=db2\n" +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +msgid "The above command will apply migrations to the `db2` database." +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +msgid "" +"Sometimes it may happen that you want to apply *some* of the migrations to " +"one database, while some others to another database. To achieve this goal, " +"when implementing a migration class you should explicitly specify the DB " +"component ID that the migration would use, like the following:" +msgstr "" + +#. type: Fenced code block (php) +#: ../src/guide/databases/db-migrations.md +#, no-wrap +msgid "" +"db = 'db2';\n" +" parent::init();\n" +" }\n" +"}\n" +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +msgid "" +"The above migration will be applied to `db2`, even if you specify a " +"different database through the `db` command-line option. Note that the " +"migration history will still be recorded in the database specified by the " +"`db` command-line option." +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +msgid "" +"If you have multiple migrations that use the same database, it is " +"recommended that you create a base migration class with the above `init()` " +"code. Then each migration class can extend from this base class." +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +#, no-wrap +msgid "" +"> Tip: Besides setting the [[yii\\db\\Migration::db|db]] property, you can also operate on different databases\n" +"by creating new database connections to them in your migration classes. You then use the [DAO methods](db-dao.md)\n" +"with these connections to manipulate different databases.\n" +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +msgid "" +"Another strategy that you can take to migrate multiple databases is to keep " +"migrations for different databases in different migration paths. Then you " +"can migrate these databases in separate commands like the following:" +msgstr "" + +#. type: Fenced code block +#: ../src/guide/databases/db-migrations.md +#, no-wrap +msgid "" +"yii migrate --migrationPath=@app/migrations/db1 --db=db1\n" +"yii migrate --migrationPath=@app/migrations/db2 --db=db2\n" +"...\n" +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +msgid "" +"The first command will apply migrations in `@app/migrations/db1` to the " +"`db1` database, the second command will apply migrations in `@app/migrations/" +"db2` to `db2`, and so on." msgstr "" #. type: Title ### #: ../src/guide/databases/db-migrations.md #, no-wrap -msgid "Upgrading from Yii 2.0" +msgid "Upgrading from Yii2" msgstr "" #. type: Plain text #: ../src/guide/databases/db-migrations.md msgid "" -"Migrations in Yii 2.0 and the [yiisoft/db-migration](https://github.com/" -"yiisoft/db-migration/) package are not compatible, and the `migration` table " -"is also not compatible. A probable solution is to use structure dumps and " -"rename the old `migration` table. Upon the initial execution of migrations, " -"a new `migration` table with new fields will be created. All further changes " -"in the database schema are applied using the new `migration` component and " +"Migrations in Yii2 and the [yiisoft/db-migration](https://github.com/yiisoft/" +"db-migration/) package are not compatible, and the `migration` table is also " +"not compatible. A probable solution is to use structure dumps and rename " +"the old `migration` table. Upon the initial execution of migrations, a new " +"`migration` table with new fields will be created. All further changes in " +"the database schema are applied using the new `migration` component and " "recorded in the new migration table." msgstr "" From 2f881dd29218b3dccf54b68627fbd38cca7f4453 Mon Sep 17 00:00:00 2001 From: Alexander Makarov Date: Sat, 27 Dec 2025 11:43:10 +0300 Subject: [PATCH 5/8] Yii 2.0 usage --- src/guide/databases/db-migrations.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/guide/databases/db-migrations.md b/src/guide/databases/db-migrations.md index 5be2b40f..0c83ae12 100644 --- a/src/guide/databases/db-migrations.md +++ b/src/guide/databases/db-migrations.md @@ -593,9 +593,9 @@ yii migrate --migrationPath=@app/migrations/db2 --db=db2 The first command will apply migrations in `@app/migrations/db1` to the `db1` database, the second command will apply migrations in `@app/migrations/db2` to `db2`, and so on. -### Upgrading from Yii2 +### Upgrading from Yii 2.0 -Migrations in Yii2 and the [yiisoft/db-migration](https://github.com/yiisoft/db-migration/) package are not compatible, +Migrations in Yii 2.0 and the [yiisoft/db-migration](https://github.com/yiisoft/db-migration/) package are not compatible, and the `migration` table is also not compatible. A probable solution is to use structure dumps and rename the old `migration` table. Upon the initial execution of From 3b6264403786cefa1a6ce1f1f14c32f9e500715c Mon Sep 17 00:00:00 2001 From: samdark <47294+samdark@users.noreply.github.com> Date: Sat, 27 Dec 2025 08:44:35 +0000 Subject: [PATCH 6/8] Update translation --- .../po/es/guide_databases_db-migrations.md.po | 6 +++--- .../po/id/guide_databases_db-migrations.md.po | 6 +++--- .../po/ru/guide_databases_db-migrations.md.po | 6 +++--- .../pot/guide_databases_db-migrations.md.pot | 16 ++++++++-------- src/es/guide/databases/db-migrations.md | 4 ++-- src/id/guide/databases/db-migrations.md | 4 ++-- src/ru/guide/databases/db-migrations.md | 4 ++-- 7 files changed, 23 insertions(+), 23 deletions(-) diff --git a/_translations/po/es/guide_databases_db-migrations.md.po b/_translations/po/es/guide_databases_db-migrations.md.po index 7f9281c7..1347fcd9 100644 --- a/_translations/po/es/guide_databases_db-migrations.md.po +++ b/_translations/po/es/guide_databases_db-migrations.md.po @@ -6,7 +6,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" -"POT-Creation-Date: 2025-12-27 07:55+0000\n" +"POT-Creation-Date: 2025-12-27 08:43+0000\n" "PO-Revision-Date: 2025-09-04 11:19+0500\n" "Last-Translator: Automatically generated\n" "Language-Team: none\n" @@ -972,10 +972,10 @@ msgstr "" #. type: Title ### #: ../src/guide/databases/db-migrations.md #, no-wrap -msgid "Upgrading from Yii2" +msgid "Upgrading from Yii 2.0" msgstr "" #. type: Plain text #: ../src/guide/databases/db-migrations.md -msgid "Migrations in Yii2 and the [yiisoft/db-migration](https://github.com/yiisoft/db-migration/) package are not compatible, and the `migration` table is also not compatible. A probable solution is to use structure dumps and rename the old `migration` table. Upon the initial execution of migrations, a new `migration` table with new fields will be created. All further changes in the database schema are applied using the new `migration` component and recorded in the new migration table." +msgid "Migrations in Yii 2.0 and the [yiisoft/db-migration](https://github.com/yiisoft/db-migration/) package are not compatible, and the `migration` table is also not compatible. A probable solution is to use structure dumps and rename the old `migration` table. Upon the initial execution of migrations, a new `migration` table with new fields will be created. All further changes in the database schema are applied using the new `migration` component and recorded in the new migration table." msgstr "" diff --git a/_translations/po/id/guide_databases_db-migrations.md.po b/_translations/po/id/guide_databases_db-migrations.md.po index 825d8bc7..c4817764 100644 --- a/_translations/po/id/guide_databases_db-migrations.md.po +++ b/_translations/po/id/guide_databases_db-migrations.md.po @@ -6,7 +6,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" -"POT-Creation-Date: 2025-12-27 07:55+0000\n" +"POT-Creation-Date: 2025-12-27 08:43+0000\n" "PO-Revision-Date: 2025-09-04 11:19+0500\n" "Last-Translator: Automatically generated\n" "Language-Team: none\n" @@ -970,10 +970,10 @@ msgstr "" #. type: Title ### #: ../src/guide/databases/db-migrations.md #, no-wrap -msgid "Upgrading from Yii2" +msgid "Upgrading from Yii 2.0" msgstr "" #. type: Plain text #: ../src/guide/databases/db-migrations.md -msgid "Migrations in Yii2 and the [yiisoft/db-migration](https://github.com/yiisoft/db-migration/) package are not compatible, and the `migration` table is also not compatible. A probable solution is to use structure dumps and rename the old `migration` table. Upon the initial execution of migrations, a new `migration` table with new fields will be created. All further changes in the database schema are applied using the new `migration` component and recorded in the new migration table." +msgid "Migrations in Yii 2.0 and the [yiisoft/db-migration](https://github.com/yiisoft/db-migration/) package are not compatible, and the `migration` table is also not compatible. A probable solution is to use structure dumps and rename the old `migration` table. Upon the initial execution of migrations, a new `migration` table with new fields will be created. All further changes in the database schema are applied using the new `migration` component and recorded in the new migration table." msgstr "" diff --git a/_translations/po/ru/guide_databases_db-migrations.md.po b/_translations/po/ru/guide_databases_db-migrations.md.po index 760c0f61..4f785d49 100644 --- a/_translations/po/ru/guide_databases_db-migrations.md.po +++ b/_translations/po/ru/guide_databases_db-migrations.md.po @@ -6,7 +6,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" -"POT-Creation-Date: 2025-12-27 07:55+0000\n" +"POT-Creation-Date: 2025-12-27 08:43+0000\n" "PO-Revision-Date: 2025-09-04 11:19+0500\n" "Last-Translator: Automatically generated\n" "Language-Team: none\n" @@ -982,10 +982,10 @@ msgstr "" #. type: Title ### #: ../src/guide/databases/db-migrations.md #, no-wrap -msgid "Upgrading from Yii2" +msgid "Upgrading from Yii 2.0" msgstr "" #. type: Plain text #: ../src/guide/databases/db-migrations.md -msgid "Migrations in Yii2 and the [yiisoft/db-migration](https://github.com/yiisoft/db-migration/) package are not compatible, and the `migration` table is also not compatible. A probable solution is to use structure dumps and rename the old `migration` table. Upon the initial execution of migrations, a new `migration` table with new fields will be created. All further changes in the database schema are applied using the new `migration` component and recorded in the new migration table." +msgid "Migrations in Yii 2.0 and the [yiisoft/db-migration](https://github.com/yiisoft/db-migration/) package are not compatible, and the `migration` table is also not compatible. A probable solution is to use structure dumps and rename the old `migration` table. Upon the initial execution of migrations, a new `migration` table with new fields will be created. All further changes in the database schema are applied using the new `migration` component and recorded in the new migration table." msgstr "" diff --git a/_translations/pot/guide_databases_db-migrations.md.pot b/_translations/pot/guide_databases_db-migrations.md.pot index 176b773a..afa70e6a 100644 --- a/_translations/pot/guide_databases_db-migrations.md.pot +++ b/_translations/pot/guide_databases_db-migrations.md.pot @@ -7,7 +7,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" -"POT-Creation-Date: 2025-12-27 07:55+0000\n" +"POT-Creation-Date: 2025-12-27 08:43+0000\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -1151,17 +1151,17 @@ msgstr "" #. type: Title ### #: ../src/guide/databases/db-migrations.md #, no-wrap -msgid "Upgrading from Yii2" +msgid "Upgrading from Yii 2.0" msgstr "" #. type: Plain text #: ../src/guide/databases/db-migrations.md msgid "" -"Migrations in Yii2 and the [yiisoft/db-migration](https://github.com/yiisoft/" -"db-migration/) package are not compatible, and the `migration` table is also " -"not compatible. A probable solution is to use structure dumps and rename " -"the old `migration` table. Upon the initial execution of migrations, a new " -"`migration` table with new fields will be created. All further changes in " -"the database schema are applied using the new `migration` component and " +"Migrations in Yii 2.0 and the [yiisoft/db-migration](https://github.com/" +"yiisoft/db-migration/) package are not compatible, and the `migration` table " +"is also not compatible. A probable solution is to use structure dumps and " +"rename the old `migration` table. Upon the initial execution of migrations, " +"a new `migration` table with new fields will be created. All further changes " +"in the database schema are applied using the new `migration` component and " "recorded in the new migration table." msgstr "" diff --git a/src/es/guide/databases/db-migrations.md b/src/es/guide/databases/db-migrations.md index 76ba389d..dd6a9e29 100644 --- a/src/es/guide/databases/db-migrations.md +++ b/src/es/guide/databases/db-migrations.md @@ -662,9 +662,9 @@ The first command will apply migrations in `@app/migrations/db1` to the `db1` database, the second command will apply migrations in `@app/migrations/db2` to `db2`, and so on. -### Upgrading from Yii2 +### Upgrading from Yii 2.0 -Migrations in Yii2 and the +Migrations in Yii 2.0 and the [yiisoft/db-migration](https://github.com/yiisoft/db-migration/) package are not compatible, and the `migration` table is also not compatible. A probable solution is to use structure dumps and rename the old `migration` diff --git a/src/id/guide/databases/db-migrations.md b/src/id/guide/databases/db-migrations.md index 76ba389d..dd6a9e29 100644 --- a/src/id/guide/databases/db-migrations.md +++ b/src/id/guide/databases/db-migrations.md @@ -662,9 +662,9 @@ The first command will apply migrations in `@app/migrations/db1` to the `db1` database, the second command will apply migrations in `@app/migrations/db2` to `db2`, and so on. -### Upgrading from Yii2 +### Upgrading from Yii 2.0 -Migrations in Yii2 and the +Migrations in Yii 2.0 and the [yiisoft/db-migration](https://github.com/yiisoft/db-migration/) package are not compatible, and the `migration` table is also not compatible. A probable solution is to use structure dumps and rename the old `migration` diff --git a/src/ru/guide/databases/db-migrations.md b/src/ru/guide/databases/db-migrations.md index 76ba389d..dd6a9e29 100644 --- a/src/ru/guide/databases/db-migrations.md +++ b/src/ru/guide/databases/db-migrations.md @@ -662,9 +662,9 @@ The first command will apply migrations in `@app/migrations/db1` to the `db1` database, the second command will apply migrations in `@app/migrations/db2` to `db2`, and so on. -### Upgrading from Yii2 +### Upgrading from Yii 2.0 -Migrations in Yii2 and the +Migrations in Yii 2.0 and the [yiisoft/db-migration](https://github.com/yiisoft/db-migration/) package are not compatible, and the `migration` table is also not compatible. A probable solution is to use structure dumps and rename the old `migration` From 6604f1acb192a22edcc62ab98da83c93138886d2 Mon Sep 17 00:00:00 2001 From: Alexander Makarov Date: Sat, 27 Dec 2025 13:28:11 +0300 Subject: [PATCH 7/8] Finish the guide --- src/guide/databases/db-migrations.md | 473 ++++++++------------------- 1 file changed, 128 insertions(+), 345 deletions(-) diff --git a/src/guide/databases/db-migrations.md b/src/guide/databases/db-migrations.md index 0c83ae12..1b2b2658 100644 --- a/src/guide/databases/db-migrations.md +++ b/src/guide/databases/db-migrations.md @@ -64,15 +64,19 @@ Add the following configuration to `config/common/params.php`: ], ``` +If you want to place migrations elsewhere, you can define the path in `newMigrationPath`. If your migrations to be +applied are from multiple sources, such as external modules, `sourcePaths` could be used to define these. + You need a database connection configured as well. See [Working with databases](../start/databases.md) for an example of configuring it for PostgreSQL. -### Creating a migration +## Creating a migration To create a new empty migration, run the following command: ```sh -make yii migrate:create +make shell +./yii migrate:create ``` The required `name` argument gives a brief description about the new migration. For example, if @@ -80,7 +84,8 @@ the migration is about creating a new table named *news*, you may use the name ` and run the following command: ``` -make yii migrate:create create_news_table +make shell +./yii migrate:create create_news_table ``` @@ -150,8 +155,83 @@ final class M251225221906CreateNewsTable implements RevertibleMigrationInterface } ``` -TODO: explain $b and $qb -Below is the list of all these database accessing methods: +Migration builder `$b` in the above manages database schema while the column builder `$cb` manages column types. Both +allow using *abstract types*. When a migration is applied to a particular database, the abstract types will +be translated into the corresponding database physical types and corresponding SQL to define them. + +Methods available in migration builder belong to the following types: + +- Raw queries + - getDb — to get database connection instance. + - execute — to execute raw SQL query. +- Data + - insert / update / delete + - batchInsert + - upsert +- Tables and views + - createTable / renameTable / dropTable + - truncateTable + - addCommentOnTable / dropCommentFromTable + - createView / dropView +- Columns + - addColumn / renameColumn / alterColumn / dropColumn + - addCommentOnColumn / dropCommentFromColumn +- Keys and indexes + - addPrimaryKey / dropPrimaryKey + - addForeignKey / dropForeignKey + - createIndex / dropIndex + +Additionally, there's a `columnBuilder()` which is used to obtain a column builder as in example above. The builder +has static methods that define various column types: + +- Keys + - primaryKey + - smallPrimaryKey + - bigPrimaryKey + - uuidPrimaryKey +- Boolean + - boolean +- Numbers + - bit + - tinyint + - smallint + - integer + - bigint + - flat + - double + - decimal +- Strings + - char + - string + - text +- Date and time + - timestamp + - datetime + - datetimeWithTimezone + - time + - timeWithTimezone + - date +- Special types + - money + - binary + - uuid + - array + - structured + - json +- enum + +All the above methods create a base type which could be adjusted with additional methods: + +- null / notNull +- defaultValue +- unique +- scale / size / unsigned +- primaryKey / autoIncrement +- check +- comment +- computed +- extra +- reference ### Irreversible migrations @@ -161,134 +241,28 @@ the `down()`, because it is not very common to revert database migrations. In th `Yiisoft\Db\Migration\MigrationInterface` that has `up()` only. -### Transactional migrations (TODO: update!!!) +### Transactional migrations While performing complex DB migrations, it is important to ensure each migration to either succeed or fail as a whole -so that the database can maintain integrity and consistency. To achieve this goal, it is recommended that you -enclose the DB operations of each migration in a [transaction](db-dao.md#performing-transactions). - -An even easier way of implementing transactional migrations is to put migration code in the `safeUp()` and `safeDown()` -methods. These two methods differ from `up()` and `down()` in that they are enclosed implicitly in a transaction. -As a result, if any operation in these methods fails, all prior operations will be rolled back automatically. - -In the following example, besides creating the `news` table we also insert an initial row into this table. - -```php -createTable('news', [ - 'id' => $this->primaryKey(), - 'title' => $this->string()->notNull(), - 'content' => $this->text(), - ]); +so that the database can maintain integrity and consistency. To achieve this goal, it is recommended that you may +enclose the DB operations of each migration in a transaction automatically by adding `TransactionalMigrationInterface` +to `implements` of your migration. - $this->insert('news', [ - 'title' => 'test 1', - 'content' => 'content 1', - ]); - } - - public function safeDown() - { - $this->delete('news', ['id' => 1]); - $this->dropTable('news'); - } -} -``` - -Note that usually when you perform multiple DB operations in `safeUp()`, you should reverse their execution order -in `safeDown()`. In the above example we first create the table and then insert a row in `safeUp()`; while -in `safeDown()` we first delete the row and then drop the table. +As a result, if any operation in the `up()` or `down()` method fails, all prior operations will +be rolled back automatically. > Note: Not all DBMS support transactions. And some DB queries cannot be put into a transaction. For some examples, -please refer to [implicit commit](https://dev.mysql.com/doc/refman/5.7/en/implicit-commit.html). If this is the case, -you should still implement `up()` and `down()`, instead. - -TODO: TransactionalMigrationInterface - - - -## TODO: update - -The base migration class [[yii\db\Migration]] exposes a database connection via the [[yii\db\Migration::db|db]] -property. You can use it to manipulate the database schema using the methods as described in -[Working with Database Schema](db-dao.md#database-schema). +please refer to [implicit commit](https://dev.mysql.com/doc/refman/5.7/en/implicit-commit.html). -Rather than using physical types, when creating a table or column you should use *abstract types* -so that your migrations are independent of specific DBMS. The [[yii\db\Schema]] class defines -a set of constants to represent the supported abstract types. These constants are named in the format -of `TYPE_`. For example, `TYPE_PK` refers to auto-incremental primary key type; `TYPE_STRING` -refers to a string type. When a migration is applied to a particular database, the abstract types -will be translated into the corresponding physical types. In the case of MySQL, `TYPE_PK` will be turned -into `int(11) NOT NULL AUTO_INCREMENT PRIMARY KEY`, while `TYPE_STRING` becomes `varchar(255)`. +## Generating a migration -You can append additional constraints when using abstract types. In the above example, ` NOT NULL` is appended -to `Schema::TYPE_STRING` to specify that the column cannot be `null`. - -> Info: The mapping between abstract types and physical types is specified by -the [[yii\db\QueryBuilder::$typeMap|$typeMap]] property in each concrete `QueryBuilder` class. - -Since version 2.0.6, you can make use of the newly introduced schema builder which provides more convenient way of defining column schema. -So the migration above could be written like the following: - -```php -createTable('news', [ - 'id' => $this->primaryKey(), - 'title' => $this->string()->notNull(), - 'content' => $this->text(), - ]); - } - - public function down() - { - $this->dropTable('news'); - } -} -``` - -A list of all available methods for defining the column types is available in the API documentation of [[yii\db\SchemaBuilderTrait]]. - -> Info: The generated file permissions and ownership will be determined by the current environment. This might lead to -inaccessible files. This could, for example, happen when the migration is created within a docker container -and the files are edited on the host. In this case the `newFileMode` and/or `newFileOwnership` of the MigrateController -can be changed. E.g. in the application config: - ```php - [ - 'migrate' => [ - 'class' => 'yii\console\controllers\MigrateController', - 'newFileOwnership' => '1000:1000', # Default WSL user id - 'newFileMode' => 0660, - ], - ], - ]; - ``` - -## Generating Migrations (TODO: likely is OK but...) - -The command provides a convenient way to create migrations using the provided [view](https://github.com/yiisoft/db-migration/tree/master/resources/views): +Instead of writing migrations by hand, the command provides a convenient way generate some of the code. ```shell -make yii migrate:create my_first_table --command=table --fields=name,example --table-comment=my_first_table +make shell +./yii migrate:create -- my_first_table --command=table --fields=name,example --table-comment=my_first_table ``` - - That would generate the following: ```php @@ -303,19 +277,21 @@ use Yiisoft\Db\Migration\RevertibleMigrationInterface; use Yiisoft\Db\Migration\TransactionalMigrationInterface; /** - * Handles the creation of a table `my_first_table`. + * Handles the creation of table `my_first_table`. */ -final class M240115143455CreateMyFirstTableTable implements RevertibleMigrationInterface, TransactionalMigrationInterface +final class M251227095006CreateMyFirstTableTable implements RevertibleMigrationInterface, TransactionalMigrationInterface { public function up(MigrationBuilder $b): void { + $columnBuilder = $b->columnBuilder(); + $b->createTable('my_first_table', [ - 'id' => $b->primaryKey(), + 'id' => $columnBuilder::primaryKey(), 'name', 'example', ]); - - $b->addCommentOnTable('my_first_table', 'dest'); + + $b->addCommentOnTable('my_first_table', 'my_first_table'); } public function down(MigrationBuilder $b): void @@ -325,64 +301,49 @@ final class M240115143455CreateMyFirstTableTable implements RevertibleMigrationI } ``` -For more information [see](https://github.com/yiisoft/db-migration/tree/master/docs/guide/en) +Commands available are: +- create - empty migration. +- table - creating a table. Use `--fields` specify a list of fields to use. Types could be specified as well such as + `id:primaryKey,name:string:defaultValue("Alex"),user_id:integer:foreignKey,category_id2:integer:foreignKey(category id2)`. +- dropTable - dropping a table. +- addColumn - adding a column. +- dropColumn - dropping a column. +- junction - creating a junction table. Use `--and` specify a second table. ## Applying Migrations To upgrade a database to its latest structure, you should apply all available new migrations using the following command: ``` -yii migrate +./yii migrate:up ``` This command will list all migrations that have not been applied so far. If you confirm that you want to apply -these migrations, it will run the `up()` or `safeUp()` method in every new migration class, one after another, +these migrations, it will run the `up()` method in every new migration class, one after another, in the order of their timestamp values. If any of the migrations fails, the command will quit without applying the rest of the migrations. -> Tip: In case you don't have command line at your server you may try [web shell](https://github.com/samdark/yii2-webshell) -> extension. - For each migration that has been successfully applied, the command will insert a row into a database table named `migration` to record the successful application of the migration. This will allow the migration tool to identify which migrations have been applied and which have not. -> Info: The migration tool will automatically create the `migration` table in the database specified by -the [[yii\console\controllers\MigrateController::db|db]] option of the command. By default, the database -is specified by the `db` [application component](structure-application-components.md). - Sometimes, you may only want to apply one or a few new migrations, instead of all available migrations. You can do so by specifying the number of migrations that you want to apply when running the command. For example, the following command will try to apply the next three available migrations: ``` -yii migrate 3 -``` - -You can also explicitly specify a particular migration to which the database should be migrated -by using the `migrate/to` command in one of the following formats: - -``` -yii migrate/to 150101_185401 # using timestamp to specify the migration -yii migrate/to "2015-01-01 18:54:01" # using a string that can be parsed by strtotime() -yii migrate/to m150101_185401_create_news_table # using full name -yii migrate/to 1392853618 # using UNIX timestamp +./yii migrate:up --limit=3 ``` -If there are any unapplied migrations earlier than the specified one, they will all be applied before the specified -migration is applied. - -If the specified migration has already been applied before, any later applied migrations will be reverted. - - ## Reverting Migrations To revert (undo) one or multiple migrations that have been applied before, you can run the following command: ``` -yii migrate/down # revert the most recently applied migration -yii migrate/down 3 # revert the most 3 recently applied migrations +./yii migrate:down # revert the most recently applied migration +./yii migrate:down --limit=3 # revert the most 3 recently applied migrations +./yii migrate:down --all # revert all migrations ``` > Note: Not all migrations are reversible. Trying to revert such migrations will cause an error and stop the @@ -395,210 +356,32 @@ Redoing migrations means first reverting the specified migrations and then apply as follows: ``` -yii migrate/redo # redo the last applied migration -yii migrate/redo 3 # redo the last 3 applied migrations +./yii migrate:redo # redo the last applied migration +./yii migrate:redo --limit=3 # redo the last 3 applied migrations +./yii migrate:redo --all # redo all migrations ``` > Note: If a migration is not reversible, you will not be able to redo it. -## Refreshing Migrations - -Since Yii 2.0.13 you can delete all tables and foreign keys from the database and apply all migrations from the beginning. - -``` -yii migrate/fresh # truncate the database and apply all migrations from the beginning -``` - ## Listing Migrations To list which migrations have been applied and which are not, you may use the following commands: ``` -yii migrate/history # showing the last 10 applied migrations -yii migrate/history 5 # showing the last 5 applied migrations -yii migrate/history all # showing all applied migrations - -yii migrate/new # showing the first 10 new migrations -yii migrate/new 5 # showing the first 5 new migrations -yii migrate/new all # showing all new migrations -``` +./yii migrate/history # showing the last 10 applied migrations +./yii migrate:history --limit=5 # showing the last 5 applied migrations +./yii migrate:history --all # showing all applied migrations - -## Modifying Migration History - -Instead of actually applying or reverting migrations, sometimes you may simply want to mark that your database -has been upgraded to a particular migration. This often happens when you manually change the database to a particular -state and you do not want the migration(s) for that change to be re-applied later. You can achieve this goal with -the following command: - -``` -yii migrate/mark 150101_185401 # using timestamp to specify the migration -yii migrate/mark "2015-01-01 18:54:01" # using a string that can be parsed by strtotime() -yii migrate/mark m150101_185401_create_news_table # using full name -yii migrate/mark 1392853618 # using UNIX timestamp +./yii migrate:new # showing the first 10 new migrations +./yii migrate:new --limit=5 # showing the first 5 new migrations +./yii migrate:new --all # showing all new migrations ``` -The command will modify the `migration` table by adding or deleting certain rows to indicate that the database -has been applied migrations to the specified one. No migrations will be applied or reverted by this command. - - -## Customizing Migrations - -There are several ways to customize the migration command. - - -### Using Command Line Options - -The migration command comes with a few command-line options that can be used to customize its behaviors: - -* `interactive`: boolean (defaults to `true`), specifies whether to perform migrations in an interactive mode. - When this is `true`, the user will be prompted before the command performs certain actions. - You may want to set this to `false` if the command is being used in a background process. - -* `migrationPath`: string|array (defaults to `@app/migrations`), specifies the directory storing all migration - class files. This can be specified as either a directory path or a path [alias](concept-aliases.md). - Note that the directory must exist, or the command may trigger an error. Since version 2.0.12 an array can be - specified for loading migrations from multiple sources. - -* `migrationTable`: string (defaults to `migration`), specifies the name of the database table for storing - migration history information. The table will be automatically created by the command if it does not exist. - You may also manually create it using the structure `version varchar(255) primary key, apply_time integer`. - -* `db`: string (defaults to `db`), specifies the ID of the database [application component](structure-application-components.md). - It represents the database that will be migrated using this command. - -* `templateFile`: string (defaults to `@yii/views/migration.php`), specifies the path of the template file - that is used for generating skeleton migration class files. This can be specified as either a file path - or a path [alias](concept-aliases.md). The template file is a PHP script in which you can use a predefined variable - named `$className` to get the migration class name. - -* `generatorTemplateFiles`: array (defaults to `[ - 'create_table' => '@yii/views/createTableMigration.php', - 'drop_table' => '@yii/views/dropTableMigration.php', - 'add_column' => '@yii/views/addColumnMigration.php', - 'drop_column' => '@yii/views/dropColumnMigration.php', - 'create_junction' => '@yii/views/createTableMigration.php' - ]`), specifies template files for generating migration code. See "[Generating Migrations](#generating-migrations)" - for more details. - -* `fields`: array of column definition strings used for creating migration code. Defaults to `[]`. The format of each - definition is `COLUMN_NAME:COLUMN_TYPE:COLUMN_DECORATOR`. For example, `--fields=name:string(12):notNull` produces - a string column of size 12 which is not `null`. - -The following example shows how you can use these options. - -For example, if we want to migrate a `forum` module whose migration files -are located within the module's `migrations` directory, we can use the following -command: - -``` -# migrate the migrations in a forum module non-interactively -yii migrate --migrationPath=@app/modules/forum/migrations --interactive=0 -``` - -### Separated Migrations - - -Sometimes using single migration history for all project migrations is not desirable. For example: you may install some -'blog' extension, which contains fully separated functionality and contain its own migrations, which should not affect -the ones dedicated to main project functionality. - -If you want several migrations to be applied and tracked down completely separated from each other, you can configure multiple -migration commands which will use different namespaces and migration history tables: - -```php -return [ - 'controllerMap' => [ - // Common migrations for the whole application - 'migrate-app' => [ - 'class' => 'yii\console\controllers\MigrateController', - 'migrationNamespaces' => ['app\migrations'], - 'migrationTable' => 'migration_app', - 'migrationPath' => null, - ], - // Migrations for the specific project's module - 'migrate-module' => [ - 'class' => 'yii\console\controllers\MigrateController', - 'migrationNamespaces' => ['module\migrations'], - 'migrationTable' => 'migration_module', - 'migrationPath' => null, - ], - // Migrations for the specific extension - 'migrate-rbac' => [ - 'class' => 'yii\console\controllers\MigrateController', - 'migrationPath' => '@yii/rbac/migrations', - 'migrationTable' => 'migration_rbac', - ], - ], -]; -``` - -Note that to synchronize database you now need to run multiple commands instead of one: - -``` -yii migrate-app -yii migrate-module -yii migrate-rbac -``` - -## Migrating Multiple Databases - -By default, migrations are applied to the same database specified by the `db` [application component](structure-application-components.md). -If you want them to be applied to a different database, you may specify the `db` command-line option like shown below, - -``` -yii migrate --db=db2 -``` - -The above command will apply migrations to the `db2` database. - -Sometimes it may happen that you want to apply *some* of the migrations to one database, while some others to another -database. To achieve this goal, when implementing a migration class you should explicitly specify the DB component -ID that the migration would use, like the following: - -```php -db = 'db2'; - parent::init(); - } -} -``` - -The above migration will be applied to `db2`, even if you specify a different database through the `db` command-line -option. Note that the migration history will still be recorded in the database specified by the `db` command-line option. - -If you have multiple migrations that use the same database, it is recommended that you create a base migration class -with the above `init()` code. Then each migration class can extend from this base class. - -> Tip: Besides setting the [[yii\db\Migration::db|db]] property, you can also operate on different databases -by creating new database connections to them in your migration classes. You then use the [DAO methods](db-dao.md) -with these connections to manipulate different databases. - -Another strategy that you can take to migrate multiple databases is to keep migrations for different databases in -different migration paths. Then you can migrate these databases in separate commands like the following: - -``` -yii migrate --migrationPath=@app/migrations/db1 --db=db1 -yii migrate --migrationPath=@app/migrations/db2 --db=db2 -... -``` - -The first command will apply migrations in `@app/migrations/db1` to the `db1` database, the second command -will apply migrations in `@app/migrations/db2` to `db2`, and so on. - ### Upgrading from Yii 2.0 Migrations in Yii 2.0 and the [yiisoft/db-migration](https://github.com/yiisoft/db-migration/) package are not compatible, -and the `migration` table is also not -compatible. +and the `migration` table is also not compatible. + A probable solution is to use structure dumps and rename the old `migration` table. Upon the initial execution of migrations, a new `migration` table with new fields will be created. All further changes in the database schema are applied using the new `migration` component and recorded in the new migration table. - From efe147432285f49a6b83c21acafeaa32da0aaa5d Mon Sep 17 00:00:00 2001 From: samdark <47294+samdark@users.noreply.github.com> Date: Sat, 27 Dec 2025 10:29:39 +0000 Subject: [PATCH 8/8] Update translation --- .../po/es/guide_databases_db-migrations.md.po | 737 +++++++-------- .../po/es/internals_010-code-style.md.po | 156 ++-- .../po/id/guide_databases_db-migrations.md.po | 739 +++++++-------- .../po/id/internals_010-code-style.md.po | 156 ++-- .../po/ru/guide_databases_db-migrations.md.po | 751 +++++++-------- .../po/ru/internals_010-code-style.md.po | 156 ++-- .../pot/guide_databases_db-migrations.md.pot | 867 +++++++----------- .../pot/internals_010-code-style.md.pot | 156 ++-- src/es/guide/databases/db-migrations.md | 523 +++-------- src/id/guide/databases/db-migrations.md | 523 +++-------- src/ru/guide/databases/db-migrations.md | 523 +++-------- 11 files changed, 2081 insertions(+), 3206 deletions(-) diff --git a/_translations/po/es/guide_databases_db-migrations.md.po b/_translations/po/es/guide_databases_db-migrations.md.po index 1347fcd9..30b0c950 100644 --- a/_translations/po/es/guide_databases_db-migrations.md.po +++ b/_translations/po/es/guide_databases_db-migrations.md.po @@ -6,7 +6,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" -"POT-Creation-Date: 2025-12-27 08:43+0000\n" +"POT-Creation-Date: 2025-12-27 10:28+0000\n" "PO-Revision-Date: 2025-09-04 11:19+0500\n" "Last-Translator: Automatically generated\n" "Language-Team: none\n" @@ -167,12 +167,17 @@ msgid "" "],\n" msgstr "" +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +msgid "If you want to place migrations elsewhere, you can define the path in `newMigrationPath`. If your migrations to be applied are from multiple sources, such as external modules, `sourcePaths` could be used to define these." +msgstr "" + #. type: Plain text #: ../src/guide/databases/db-migrations.md msgid "You need a database connection configured as well. See [Working with databases](../start/databases.md) for an example of configuring it for PostgreSQL." msgstr "" -#. type: Title ### +#. type: Title ## #: ../src/guide/databases/db-migrations.md #, no-wrap msgid "Creating a migration" @@ -188,7 +193,9 @@ msgstr "Los eventos se lanzan de la siguiente forma:" #. type: Fenced code block (sh) #: ../src/guide/databases/db-migrations.md #, no-wrap -msgid "make yii migrate:create \n" +msgid "" +"make shell\n" +"./yii migrate:create \n" msgstr "" #. type: Plain text @@ -199,7 +206,9 @@ msgstr "" #. type: Fenced code block #: ../src/guide/databases/db-migrations.md #, no-wrap -msgid "make yii migrate:create create_news_table\n" +msgid "" +"make shell\n" +"./yii migrate:create create_news_table\n" msgstr "" #. type: Plain text @@ -283,690 +292,599 @@ msgstr "" #. type: Plain text #: ../src/guide/databases/db-migrations.md -#, no-wrap -msgid "" -"TODO: explain $b and $qb\n" -"Below is the list of all these database accessing methods:\n" -msgstr "" - -#. type: Title ### -#: ../src/guide/databases/db-migrations.md -#, no-wrap -msgid "Irreversible migrations" +msgid "Migration builder `$b` in the above manages database schema while the column builder `$cb` manages column types. Both allow using *abstract types*. When a migration is applied to a particular database, the abstract types will be translated into the corresponding database physical types and corresponding SQL to define them." msgstr "" #. type: Plain text #: ../src/guide/databases/db-migrations.md -msgid "Not all migrations are reversible. For example, if the `up()` method deletes a row of a table, you may not be able to recover this row in the `down()` method. Sometimes, you may be just too lazy to implement the `down()`, because it is not very common to revert database migrations. In this case, you should implement `Yiisoft\\Db\\Migration\\MigrationInterface` that has `up()` only." +msgid "Methods available in migration builder belong to the following types:" msgstr "" -#. type: Title ### +#. type: Bullet: '- ' #: ../src/guide/databases/db-migrations.md -#, no-wrap -msgid "Transactional migrations (TODO: update!!!)" +msgid "Raw queries" msgstr "" -#. type: Plain text +#. type: Bullet: ' - ' #: ../src/guide/databases/db-migrations.md -msgid "While performing complex DB migrations, it is important to ensure each migration to either succeed or fail as a whole so that the database can maintain integrity and consistency. To achieve this goal, it is recommended that you enclose the DB operations of each migration in a [transaction](db-dao.md#performing-transactions)." +msgid "getDb — to get database connection instance." msgstr "" -#. type: Plain text +#. type: Bullet: ' - ' #: ../src/guide/databases/db-migrations.md -msgid "An even easier way of implementing transactional migrations is to put migration code in the `safeUp()` and `safeDown()` methods. These two methods differ from `up()` and `down()` in that they are enclosed implicitly in a transaction. As a result, if any operation in these methods fails, all prior operations will be rolled back automatically." +msgid "execute — to execute raw SQL query." msgstr "" -#. type: Plain text +#. type: Bullet: '- ' #: ../src/guide/databases/db-migrations.md -msgid "In the following example, besides creating the `news` table we also insert an initial row into this table." +msgid "Data" msgstr "" -#. type: Fenced code block (php) +#. type: Bullet: ' - ' #: ../src/guide/databases/db-migrations.md -#, no-wrap -msgid "" -"createTable('news', [\n" -" 'id' => $this->primaryKey(),\n" -" 'title' => $this->string()->notNull(),\n" -" 'content' => $this->text(),\n" -" ]);\n" -"\n" -" $this->insert('news', [\n" -" 'title' => 'test 1',\n" -" 'content' => 'content 1',\n" -" ]);\n" -" }\n" -"\n" -" public function safeDown()\n" -" {\n" -" $this->delete('news', ['id' => 1]);\n" -" $this->dropTable('news');\n" -" }\n" -"}\n" +msgid "insert / update / delete" msgstr "" -#. type: Plain text +#. type: Bullet: ' - ' #: ../src/guide/databases/db-migrations.md -msgid "Note that usually when you perform multiple DB operations in `safeUp()`, you should reverse their execution order in `safeDown()`. In the above example we first create the table and then insert a row in `safeUp()`; while in `safeDown()` we first delete the row and then drop the table." +msgid "batchInsert" msgstr "" -#. type: Plain text +#. type: Bullet: ' - ' #: ../src/guide/databases/db-migrations.md -#, no-wrap -msgid "" -"> Note: Not all DBMS support transactions. And some DB queries cannot be put into a transaction. For some examples,\n" -"please refer to [implicit commit](https://dev.mysql.com/doc/refman/5.7/en/implicit-commit.html). If this is the case,\n" -"you should still implement `up()` and `down()`, instead.\n" +msgid "upsert" msgstr "" -#. type: Plain text +#. type: Bullet: '- ' #: ../src/guide/databases/db-migrations.md -#, no-wrap -msgid "TODO: TransactionalMigrationInterface\n" +msgid "Tables and views" msgstr "" -#. type: Title ## +#. type: Bullet: ' - ' #: ../src/guide/databases/db-migrations.md -#, no-wrap -msgid "TODO: update" +msgid "createTable / renameTable / dropTable" msgstr "" -#. type: Plain text +#. type: Bullet: ' - ' #: ../src/guide/databases/db-migrations.md -msgid "The base migration class [[yii\\db\\Migration]] exposes a database connection via the [[yii\\db\\Migration::db|db]] property. You can use it to manipulate the database schema using the methods as described in [Working with Database Schema](db-dao.md#database-schema)." +msgid "truncateTable" msgstr "" -#. type: Plain text +#. type: Bullet: ' - ' #: ../src/guide/databases/db-migrations.md -#, no-wrap -msgid "" -"Rather than using physical types, when creating a table or column you should use *abstract types*\n" -"so that your migrations are independent of specific DBMS. The [[yii\\db\\Schema]] class defines\n" -"a set of constants to represent the supported abstract types. These constants are named in the format\n" -"of `TYPE_`. For example, `TYPE_PK` refers to auto-incremental primary key type; `TYPE_STRING`\n" -"refers to a string type. When a migration is applied to a particular database, the abstract types\n" -"will be translated into the corresponding physical types. In the case of MySQL, `TYPE_PK` will be turned\n" -"into `int(11) NOT NULL AUTO_INCREMENT PRIMARY KEY`, while `TYPE_STRING` becomes `varchar(255)`.\n" +msgid "addCommentOnTable / dropCommentFromTable" msgstr "" -#. type: Plain text +#. type: Bullet: ' - ' #: ../src/guide/databases/db-migrations.md -msgid "You can append additional constraints when using abstract types. In the above example, ` NOT NULL` is appended to `Schema::TYPE_STRING` to specify that the column cannot be `null`." +msgid "createView / dropView" msgstr "" -#. type: Plain text +#. type: Bullet: '- ' #: ../src/guide/databases/db-migrations.md -#, no-wrap -msgid "" -"> Info: The mapping between abstract types and physical types is specified by\n" -"the [[yii\\db\\QueryBuilder::$typeMap|$typeMap]] property in each concrete `QueryBuilder` class.\n" +msgid "Columns" msgstr "" -#. type: Plain text +#. type: Bullet: ' - ' #: ../src/guide/databases/db-migrations.md -msgid "Since version 2.0.6, you can make use of the newly introduced schema builder which provides more convenient way of defining column schema. So the migration above could be written like the following:" +msgid "addColumn / renameColumn / alterColumn / dropColumn" msgstr "" -#. type: Fenced code block (php) +#. type: Bullet: ' - ' #: ../src/guide/databases/db-migrations.md -#, no-wrap -msgid "" -"createTable('news', [\n" -" 'id' => $this->primaryKey(),\n" -" 'title' => $this->string()->notNull(),\n" -" 'content' => $this->text(),\n" -" ]);\n" -" }\n" -"\n" -" public function down()\n" -" {\n" -" $this->dropTable('news');\n" -" }\n" -"}\n" +msgid "addCommentOnColumn / dropCommentFromColumn" msgstr "" -#. type: Plain text +#. type: Bullet: '- ' #: ../src/guide/databases/db-migrations.md -msgid "A list of all available methods for defining the column types is available in the API documentation of [[yii\\db\\SchemaBuilderTrait]]." +msgid "Keys and indexes" msgstr "" -#. type: Plain text +#. type: Bullet: ' - ' #: ../src/guide/databases/db-migrations.md -#, no-wrap -msgid "" -"> Info: The generated file permissions and ownership will be determined by the current environment. This might lead to\n" -"inaccessible files. This could, for example, happen when the migration is created within a docker container\n" -"and the files are edited on the host. In this case the `newFileMode` and/or `newFileOwnership` of the MigrateController\n" -"can be changed. E.g. in the application config:\n" +msgid "addPrimaryKey / dropPrimaryKey" msgstr "" -#. type: Fenced code block (php) +#. type: Bullet: ' - ' #: ../src/guide/databases/db-migrations.md -#, no-wrap -msgid "" -" [\n" -" 'migrate' => [\n" -" 'class' => 'yii\\console\\controllers\\MigrateController',\n" -" 'newFileOwnership' => '1000:1000', # Default WSL user id\n" -" 'newFileMode' => 0660,\n" -" ],\n" -" ],\n" -" ];\n" +msgid "addForeignKey / dropForeignKey" msgstr "" -#. type: Title ## +#. type: Bullet: ' - ' #: ../src/guide/databases/db-migrations.md -#, no-wrap -msgid "Generating Migrations (TODO: likely is OK but...)" +msgid "createIndex / dropIndex" msgstr "" #. type: Plain text #: ../src/guide/databases/db-migrations.md -msgid "The command provides a convenient way to create migrations using the provided [view](https://github.com/yiisoft/db-migration/tree/master/resources/views):" +msgid "Additionally, there's a `columnBuilder()` which is used to obtain a column builder as in example above. The builder has static methods that define various column types:" msgstr "" -#. type: Fenced code block (shell) +#. type: Bullet: '- ' #: ../src/guide/databases/db-migrations.md -#, no-wrap -msgid "make yii migrate:create my_first_table --command=table --fields=name,example --table-comment=my_first_table\n" +msgid "Keys" msgstr "" -#. type: Plain text +#. type: Bullet: ' - ' #: ../src/guide/databases/db-migrations.md -msgid "That would generate the following:" +msgid "primaryKey" msgstr "" -#. type: Fenced code block (php) +#. type: Bullet: ' - ' #: ../src/guide/databases/db-migrations.md -#, no-wrap -msgid "" -"createTable('my_first_table', [\n" -" 'id' => $b->primaryKey(),\n" -" 'name',\n" -" 'example',\n" -" ]);\n" -" \n" -" $b->addCommentOnTable('my_first_table', 'dest');\n" -" }\n" -"\n" -" public function down(MigrationBuilder $b): void\n" -" {\n" -" $b->dropTable('my_first_table');\n" -" }\n" -"}\n" +msgid "smallPrimaryKey" msgstr "" -#. type: Plain text +#. type: Bullet: ' - ' #: ../src/guide/databases/db-migrations.md -msgid "For more information [see](https://github.com/yiisoft/db-migration/tree/master/docs/guide/en)" +msgid "bigPrimaryKey" msgstr "" -#. type: Title ## +#. type: Bullet: ' - ' #: ../src/guide/databases/db-migrations.md -#, no-wrap -msgid "Applying Migrations" +msgid "uuidPrimaryKey" msgstr "" -#. type: Plain text +#. type: Bullet: '- ' #: ../src/guide/databases/db-migrations.md -msgid "To upgrade a database to its latest structure, you should apply all available new migrations using the following command:" +msgid "Boolean" msgstr "" -#. type: Fenced code block +#. type: Bullet: ' - ' #: ../src/guide/databases/db-migrations.md -#, no-wrap -msgid "yii migrate\n" +msgid "boolean" msgstr "" -#. type: Plain text +#. type: Bullet: '- ' #: ../src/guide/databases/db-migrations.md -msgid "This command will list all migrations that have not been applied so far. If you confirm that you want to apply these migrations, it will run the `up()` or `safeUp()` method in every new migration class, one after another, in the order of their timestamp values. If any of the migrations fails, the command will quit without applying the rest of the migrations." +msgid "Numbers" msgstr "" -#. type: Plain text +#. type: Bullet: ' - ' #: ../src/guide/databases/db-migrations.md -#, no-wrap -msgid "" -"> Tip: In case you don't have command line at your server you may try [web shell](https://github.com/samdark/yii2-webshell)\n" -"> extension.\n" +msgid "bit" msgstr "" -#. type: Plain text +#. type: Bullet: ' - ' #: ../src/guide/databases/db-migrations.md -msgid "For each migration that has been successfully applied, the command will insert a row into a database table named `migration` to record the successful application of the migration. This will allow the migration tool to identify which migrations have been applied and which have not." +msgid "tinyint" msgstr "" -#. type: Plain text +#. type: Bullet: ' - ' #: ../src/guide/databases/db-migrations.md -#, no-wrap -msgid "" -"> Info: The migration tool will automatically create the `migration` table in the database specified by\n" -"the [[yii\\console\\controllers\\MigrateController::db|db]] option of the command. By default, the database\n" -"is specified by the `db` [application component](structure-application-components.md).\n" +msgid "smallint" msgstr "" -#. type: Plain text +#. type: Bullet: ' - ' #: ../src/guide/databases/db-migrations.md -msgid "Sometimes, you may only want to apply one or a few new migrations, instead of all available migrations. You can do so by specifying the number of migrations that you want to apply when running the command. For example, the following command will try to apply the next three available migrations:" +msgid "integer" msgstr "" -#. type: Fenced code block +#. type: Bullet: ' - ' #: ../src/guide/databases/db-migrations.md -#, no-wrap -msgid "yii migrate 3\n" +msgid "bigint" msgstr "" -#. type: Plain text +#. type: Bullet: ' - ' #: ../src/guide/databases/db-migrations.md -msgid "You can also explicitly specify a particular migration to which the database should be migrated by using the `migrate/to` command in one of the following formats:" +msgid "flat" msgstr "" -#. type: Fenced code block +#. type: Bullet: ' - ' #: ../src/guide/databases/db-migrations.md -#, no-wrap -msgid "" -"yii migrate/to 150101_185401 # using timestamp to specify the migration\n" -"yii migrate/to \"2015-01-01 18:54:01\" # using a string that can be parsed by strtotime()\n" -"yii migrate/to m150101_185401_create_news_table # using full name\n" -"yii migrate/to 1392853618 # using UNIX timestamp\n" +msgid "double" msgstr "" -#. type: Plain text +#. type: Bullet: ' - ' #: ../src/guide/databases/db-migrations.md -msgid "If there are any unapplied migrations earlier than the specified one, they will all be applied before the specified migration is applied." +msgid "decimal" msgstr "" -#. type: Plain text +#. type: Title ## +#: ../src/guide/databases/db-migrations.md ../src/internals/010-code-style.md +#, no-wrap +msgid "Strings" +msgstr "" + +#. type: Bullet: ' - ' #: ../src/guide/databases/db-migrations.md -msgid "If the specified migration has already been applied before, any later applied migrations will be reverted." +msgid "char" msgstr "" -#. type: Title ## +#. type: Bullet: ' - ' #: ../src/guide/databases/db-migrations.md -#, fuzzy, no-wrap -#| msgid "Resolving aliases " -msgid "Reverting Migrations " -msgstr "Resolución de Alias " +msgid "string" +msgstr "" -#. type: Plain text +#. type: Bullet: ' - ' #: ../src/guide/databases/db-migrations.md -msgid "To revert (undo) one or multiple migrations that have been applied before, you can run the following command:" +msgid "text" msgstr "" -#. type: Fenced code block +#. type: Bullet: '- ' #: ../src/guide/databases/db-migrations.md -#, no-wrap -msgid "" -"yii migrate/down # revert the most recently applied migration\n" -"yii migrate/down 3 # revert the most 3 recently applied migrations\n" +msgid "Date and time" msgstr "" -#. type: Plain text +#. type: Bullet: ' - ' #: ../src/guide/databases/db-migrations.md -#, no-wrap -msgid "" -"> Note: Not all migrations are reversible. Trying to revert such migrations will cause an error and stop the\n" -"entire reverting process.\n" +msgid "timestamp" msgstr "" -#. type: Title ## +#. type: Bullet: ' - ' #: ../src/guide/databases/db-migrations.md -#, fuzzy, no-wrap -#| msgid "Resolving aliases " -msgid "Redoing Migrations " -msgstr "Resolución de Alias " +msgid "datetime" +msgstr "" -#. type: Plain text +#. type: Bullet: ' - ' #: ../src/guide/databases/db-migrations.md -msgid "Redoing migrations means first reverting the specified migrations and then applying again. This can be done as follows:" +msgid "datetimeWithTimezone" msgstr "" -#. type: Fenced code block +#. type: Bullet: ' - ' #: ../src/guide/databases/db-migrations.md -#, no-wrap -msgid "" -"yii migrate/redo # redo the last applied migration\n" -"yii migrate/redo 3 # redo the last 3 applied migrations\n" +msgid "time" msgstr "" -#. type: Plain text +#. type: Bullet: ' - ' #: ../src/guide/databases/db-migrations.md -#, no-wrap -msgid "> Note: If a migration is not reversible, you will not be able to redo it.\n" +msgid "timeWithTimezone" msgstr "" -#. type: Title ## +#. type: Bullet: ' - ' #: ../src/guide/databases/db-migrations.md -#, fuzzy, no-wrap -#| msgid "Resolving aliases " -msgid "Refreshing Migrations " -msgstr "Resolución de Alias " +msgid "date" +msgstr "" -#. type: Plain text +#. type: Bullet: '- ' #: ../src/guide/databases/db-migrations.md -msgid "Since Yii 2.0.13 you can delete all tables and foreign keys from the database and apply all migrations from the beginning." +msgid "Special types" msgstr "" -#. type: Fenced code block +#. type: Bullet: ' - ' #: ../src/guide/databases/db-migrations.md -#, no-wrap -msgid "yii migrate/fresh # truncate the database and apply all migrations from the beginning\n" +msgid "money" msgstr "" -#. type: Title ## +#. type: Bullet: ' - ' #: ../src/guide/databases/db-migrations.md -#, fuzzy, no-wrap -#| msgid "Raising events " -msgid "Listing Migrations " -msgstr "Lanzamiento de Eventos " +msgid "binary" +msgstr "" -#. type: Plain text +#. type: Bullet: ' - ' #: ../src/guide/databases/db-migrations.md -msgid "To list which migrations have been applied and which are not, you may use the following commands:" +msgid "uuid" msgstr "" -#. type: Fenced code block +#. type: Bullet: ' - ' #: ../src/guide/databases/db-migrations.md -#, no-wrap -msgid "" -"yii migrate/history # showing the last 10 applied migrations\n" -"yii migrate/history 5 # showing the last 5 applied migrations\n" -"yii migrate/history all # showing all applied migrations\n" -"\n" -"yii migrate/new # showing the first 10 new migrations\n" -"yii migrate/new 5 # showing the first 5 new migrations\n" -"yii migrate/new all # showing all new migrations\n" +msgid "array" msgstr "" -#. type: Title ## +#. type: Bullet: ' - ' #: ../src/guide/databases/db-migrations.md -#, no-wrap -msgid "Modifying Migration History " +msgid "structured" msgstr "" -#. type: Plain text +#. type: Bullet: ' - ' #: ../src/guide/databases/db-migrations.md -msgid "Instead of actually applying or reverting migrations, sometimes you may simply want to mark that your database has been upgraded to a particular migration. This often happens when you manually change the database to a particular state and you do not want the migration(s) for that change to be re-applied later. You can achieve this goal with the following command:" +msgid "json" msgstr "" -#. type: Fenced code block +#. type: Bullet: '- ' #: ../src/guide/databases/db-migrations.md -#, no-wrap -msgid "" -"yii migrate/mark 150101_185401 # using timestamp to specify the migration\n" -"yii migrate/mark \"2015-01-01 18:54:01\" # using a string that can be parsed by strtotime()\n" -"yii migrate/mark m150101_185401_create_news_table # using full name\n" -"yii migrate/mark 1392853618 # using UNIX timestamp\n" +msgid "enum" msgstr "" #. type: Plain text #: ../src/guide/databases/db-migrations.md -msgid "The command will modify the `migration` table by adding or deleting certain rows to indicate that the database has been applied migrations to the specified one. No migrations will be applied or reverted by this command." +msgid "All the above methods create a base type which could be adjusted with additional methods:" msgstr "" -#. type: Title ## +#. type: Bullet: '- ' #: ../src/guide/databases/db-migrations.md -#, fuzzy, no-wrap -#| msgid "Raising events " -msgid "Customizing Migrations " -msgstr "Lanzamiento de Eventos " +msgid "null / notNull" +msgstr "" -#. type: Plain text +#. type: Bullet: '- ' #: ../src/guide/databases/db-migrations.md -msgid "There are several ways to customize the migration command." +msgid "defaultValue" msgstr "" -#. type: Title ### +#. type: Bullet: '- ' #: ../src/guide/databases/db-migrations.md -#, fuzzy, no-wrap -#| msgid "Resolving aliases " -msgid "Using Command Line Options " -msgstr "Resolución de Alias " +msgid "unique" +msgstr "" -#. type: Plain text +#. type: Bullet: '- ' #: ../src/guide/databases/db-migrations.md -msgid "The migration command comes with a few command-line options that can be used to customize its behaviors:" +msgid "scale / size / unsigned" msgstr "" -#. type: Bullet: '* ' +#. type: Bullet: '- ' #: ../src/guide/databases/db-migrations.md -msgid "`interactive`: boolean (defaults to `true`), specifies whether to perform migrations in an interactive mode. When this is `true`, the user will be prompted before the command performs certain actions. You may want to set this to `false` if the command is being used in a background process." +msgid "primaryKey / autoIncrement" msgstr "" -#. type: Bullet: '* ' +#. type: Bullet: '- ' #: ../src/guide/databases/db-migrations.md -msgid "`migrationPath`: string|array (defaults to `@app/migrations`), specifies the directory storing all migration class files. This can be specified as either a directory path or a path [alias](concept-aliases.md). Note that the directory must exist, or the command may trigger an error. Since version 2.0.12 an array can be specified for loading migrations from multiple sources." +msgid "check" msgstr "" -#. type: Bullet: '* ' +#. type: Bullet: '- ' #: ../src/guide/databases/db-migrations.md -msgid "`migrationTable`: string (defaults to `migration`), specifies the name of the database table for storing migration history information. The table will be automatically created by the command if it does not exist. You may also manually create it using the structure `version varchar(255) primary key, apply_time integer`." +msgid "comment" msgstr "" -#. type: Bullet: '* ' +#. type: Bullet: '- ' #: ../src/guide/databases/db-migrations.md -msgid "`db`: string (defaults to `db`), specifies the ID of the database [application component](structure-application-components.md). It represents the database that will be migrated using this command." +msgid "computed" msgstr "" -#. type: Bullet: '* ' +#. type: Bullet: '- ' #: ../src/guide/databases/db-migrations.md -msgid "`templateFile`: string (defaults to `@yii/views/migration.php`), specifies the path of the template file that is used for generating skeleton migration class files. This can be specified as either a file path or a path [alias](concept-aliases.md). The template file is a PHP script in which you can use a predefined variable named `$className` to get the migration class name." +msgid "extra" msgstr "" -#. type: Plain text +#. type: Bullet: '- ' +#: ../src/guide/databases/db-migrations.md +#, fuzzy +#| msgid "References" +msgid "reference" +msgstr "Referencias" + +#. type: Title ### #: ../src/guide/databases/db-migrations.md #, no-wrap -msgid "" -"* `generatorTemplateFiles`: array (defaults to `[\n" -" 'create_table' => '@yii/views/createTableMigration.php',\n" -" 'drop_table' => '@yii/views/dropTableMigration.php',\n" -" 'add_column' => '@yii/views/addColumnMigration.php',\n" -" 'drop_column' => '@yii/views/dropColumnMigration.php',\n" -" 'create_junction' => '@yii/views/createTableMigration.php'\n" -" ]`), specifies template files for generating migration code. See \"[Generating Migrations](#generating-migrations)\"\n" -" for more details.\n" +msgid "Irreversible migrations" msgstr "" -#. type: Bullet: '* ' +#. type: Plain text #: ../src/guide/databases/db-migrations.md -msgid "`fields`: array of column definition strings used for creating migration code. Defaults to `[]`. The format of each definition is `COLUMN_NAME:COLUMN_TYPE:COLUMN_DECORATOR`. For example, `--fields=name:string(12):notNull` produces a string column of size 12 which is not `null`." +msgid "Not all migrations are reversible. For example, if the `up()` method deletes a row of a table, you may not be able to recover this row in the `down()` method. Sometimes, you may be just too lazy to implement the `down()`, because it is not very common to revert database migrations. In this case, you should implement `Yiisoft\\Db\\Migration\\MigrationInterface` that has `up()` only." msgstr "" +#. type: Title ### +#: ../src/guide/databases/db-migrations.md +#, fuzzy, no-wrap +#| msgid "Introduction +" +msgid "Transactional migrations" +msgstr "Introducción" + #. type: Plain text #: ../src/guide/databases/db-migrations.md -msgid "The following example shows how you can use these options." +msgid "While performing complex DB migrations, it is important to ensure each migration to either succeed or fail as a whole so that the database can maintain integrity and consistency. To achieve this goal, it is recommended that you may enclose the DB operations of each migration in a transaction automatically by adding `TransactionalMigrationInterface` to `implements` of your migration." msgstr "" #. type: Plain text #: ../src/guide/databases/db-migrations.md -msgid "For example, if we want to migrate a `forum` module whose migration files are located within the module's `migrations` directory, we can use the following command:" +msgid "As a result, if any operation in the `up()` or `down()` method fails, all prior operations will be rolled back automatically." msgstr "" -#. type: Fenced code block +#. type: Plain text #: ../src/guide/databases/db-migrations.md #, no-wrap msgid "" -"# migrate the migrations in a forum module non-interactively\n" -"yii migrate --migrationPath=@app/modules/forum/migrations --interactive=0\n" +"> Note: Not all DBMS support transactions. And some DB queries cannot be put into a transaction. For some examples,\n" +"please refer to [implicit commit](https://dev.mysql.com/doc/refman/5.7/en/implicit-commit.html).\n" msgstr "" -#. type: Title ### +#. type: Title ## #: ../src/guide/databases/db-migrations.md -#, no-wrap -msgid "Separated Migrations" -msgstr "" +#, fuzzy, no-wrap +#| msgid "Generating API documentation" +msgid "Generating a migration" +msgstr "Generación de Documentación de API" #. type: Plain text #: ../src/guide/databases/db-migrations.md -msgid "Sometimes using single migration history for all project migrations is not desirable. For example: you may install some 'blog' extension, which contains fully separated functionality and contain its own migrations, which should not affect the ones dedicated to main project functionality." +msgid "Instead of writing migrations by hand, the command provides a convenient way generate some of the code." +msgstr "" + +#. type: Fenced code block (shell) +#: ../src/guide/databases/db-migrations.md +#, no-wrap +msgid "" +"make shell\n" +"./yii migrate:create -- my_first_table --command=table --fields=name,example --table-comment=my_first_table\n" msgstr "" #. type: Plain text #: ../src/guide/databases/db-migrations.md -msgid "If you want several migrations to be applied and tracked down completely separated from each other, you can configure multiple migration commands which will use different namespaces and migration history tables:" +msgid "That would generate the following:" msgstr "" #. type: Fenced code block (php) #: ../src/guide/databases/db-migrations.md #, no-wrap msgid "" -"return [\n" -" 'controllerMap' => [\n" -" // Common migrations for the whole application\n" -" 'migrate-app' => [\n" -" 'class' => 'yii\\console\\controllers\\MigrateController',\n" -" 'migrationNamespaces' => ['app\\migrations'],\n" -" 'migrationTable' => 'migration_app',\n" -" 'migrationPath' => null,\n" -" ],\n" -" // Migrations for the specific project's module\n" -" 'migrate-module' => [\n" -" 'class' => 'yii\\console\\controllers\\MigrateController',\n" -" 'migrationNamespaces' => ['module\\migrations'],\n" -" 'migrationTable' => 'migration_module',\n" -" 'migrationPath' => null,\n" -" ],\n" -" // Migrations for the specific extension\n" -" 'migrate-rbac' => [\n" -" 'class' => 'yii\\console\\controllers\\MigrateController',\n" -" 'migrationPath' => '@yii/rbac/migrations',\n" -" 'migrationTable' => 'migration_rbac',\n" -" ],\n" -" ],\n" -"];\n" -msgstr "" - -#. type: Plain text -#: ../src/guide/databases/db-migrations.md -msgid "Note that to synchronize database you now need to run multiple commands instead of one:" +"columnBuilder();\n" +"\n" +" $b->createTable('my_first_table', [\n" +" 'id' => $columnBuilder::primaryKey(),\n" +" 'name',\n" +" 'example',\n" +" ]);\n" +"\n" +" $b->addCommentOnTable('my_first_table', 'my_first_table');\n" +" }\n" +"\n" +" public function down(MigrationBuilder $b): void\n" +" {\n" +" $b->dropTable('my_first_table');\n" +" }\n" +"}\n" msgstr "" -#. type: Fenced code block +#. type: Plain text #: ../src/guide/databases/db-migrations.md -#, no-wrap -msgid "" -"yii migrate-app\n" -"yii migrate-module\n" -"yii migrate-rbac\n" +msgid "Commands available are:" +msgstr "" + +#. type: Bullet: '- ' +#: ../src/guide/databases/db-migrations.md +msgid "create - empty migration." +msgstr "" + +#. type: Bullet: '- ' +#: ../src/guide/databases/db-migrations.md +msgid "table - creating a table. Use `--fields` specify a list of fields to use. Types could be specified as well such as `id:primaryKey,name:string:defaultValue(\"Alex\"),user_id:integer:foreignKey,category_id2:integer:foreignKey(category id2)`." +msgstr "" + +#. type: Bullet: '- ' +#: ../src/guide/databases/db-migrations.md +msgid "dropTable - dropping a table." +msgstr "" + +#. type: Bullet: '- ' +#: ../src/guide/databases/db-migrations.md +msgid "addColumn - adding a column." +msgstr "" + +#. type: Bullet: '- ' +#: ../src/guide/databases/db-migrations.md +msgid "dropColumn - dropping a column." +msgstr "" + +#. type: Bullet: '- ' +#: ../src/guide/databases/db-migrations.md +msgid "junction - creating a junction table. Use `--and` specify a second table." msgstr "" #. type: Title ## #: ../src/guide/databases/db-migrations.md -#, fuzzy, no-wrap -#| msgid "Defining aliases " -msgid "Migrating Multiple Databases " -msgstr "Definir Alias " +#, no-wrap +msgid "Applying Migrations" +msgstr "" #. type: Plain text #: ../src/guide/databases/db-migrations.md -msgid "By default, migrations are applied to the same database specified by the `db` [application component](structure-application-components.md). If you want them to be applied to a different database, you may specify the `db` command-line option like shown below," +msgid "To upgrade a database to its latest structure, you should apply all available new migrations using the following command:" msgstr "" #. type: Fenced code block #: ../src/guide/databases/db-migrations.md #, no-wrap -msgid "yii migrate --db=db2\n" +msgid "./yii migrate:up\n" msgstr "" #. type: Plain text #: ../src/guide/databases/db-migrations.md -msgid "The above command will apply migrations to the `db2` database." +msgid "This command will list all migrations that have not been applied so far. If you confirm that you want to apply these migrations, it will run the `up()` method in every new migration class, one after another, in the order of their timestamp values. If any of the migrations fails, the command will quit without applying the rest of the migrations." msgstr "" #. type: Plain text #: ../src/guide/databases/db-migrations.md -msgid "Sometimes it may happen that you want to apply *some* of the migrations to one database, while some others to another database. To achieve this goal, when implementing a migration class you should explicitly specify the DB component ID that the migration would use, like the following:" +msgid "For each migration that has been successfully applied, the command will insert a row into a database table named `migration` to record the successful application of the migration. This will allow the migration tool to identify which migrations have been applied and which have not." msgstr "" -#. type: Fenced code block (php) +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +msgid "Sometimes, you may only want to apply one or a few new migrations, instead of all available migrations. You can do so by specifying the number of migrations that you want to apply when running the command. For example, the following command will try to apply the next three available migrations:" +msgstr "" + +#. type: Fenced code block #: ../src/guide/databases/db-migrations.md #, no-wrap -msgid "" -"db = 'db2';\n" -" parent::init();\n" -" }\n" -"}\n" +msgid "./yii migrate:up --limit=3\n" msgstr "" +#. type: Title ## +#: ../src/guide/databases/db-migrations.md +#, fuzzy, no-wrap +#| msgid "Resolving aliases " +msgid "Reverting Migrations " +msgstr "Resolución de Alias " + #. type: Plain text #: ../src/guide/databases/db-migrations.md -msgid "The above migration will be applied to `db2`, even if you specify a different database through the `db` command-line option. Note that the migration history will still be recorded in the database specified by the `db` command-line option." +msgid "To revert (undo) one or multiple migrations that have been applied before, you can run the following command:" msgstr "" -#. type: Plain text +#. type: Fenced code block #: ../src/guide/databases/db-migrations.md -msgid "If you have multiple migrations that use the same database, it is recommended that you create a base migration class with the above `init()` code. Then each migration class can extend from this base class." +#, no-wrap +msgid "" +"./yii migrate:down # revert the most recently applied migration\n" +"./yii migrate:down --limit=3 # revert the most 3 recently applied migrations\n" +"./yii migrate:down --all # revert all migrations\n" msgstr "" #. type: Plain text #: ../src/guide/databases/db-migrations.md #, no-wrap msgid "" -"> Tip: Besides setting the [[yii\\db\\Migration::db|db]] property, you can also operate on different databases\n" -"by creating new database connections to them in your migration classes. You then use the [DAO methods](db-dao.md)\n" -"with these connections to manipulate different databases.\n" +"> Note: Not all migrations are reversible. Trying to revert such migrations will cause an error and stop the\n" +"entire reverting process.\n" msgstr "" +#. type: Title ## +#: ../src/guide/databases/db-migrations.md +#, fuzzy, no-wrap +#| msgid "Resolving aliases " +msgid "Redoing Migrations " +msgstr "Resolución de Alias " + #. type: Plain text #: ../src/guide/databases/db-migrations.md -msgid "Another strategy that you can take to migrate multiple databases is to keep migrations for different databases in different migration paths. Then you can migrate these databases in separate commands like the following:" +msgid "Redoing migrations means first reverting the specified migrations and then applying again. This can be done as follows:" msgstr "" #. type: Fenced code block #: ../src/guide/databases/db-migrations.md #, no-wrap msgid "" -"yii migrate --migrationPath=@app/migrations/db1 --db=db1\n" -"yii migrate --migrationPath=@app/migrations/db2 --db=db2\n" -"...\n" +"./yii migrate:redo # redo the last applied migration\n" +"./yii migrate:redo --limit=3 # redo the last 3 applied migrations\n" +"./yii migrate:redo --all # redo all migrations\n" msgstr "" #. type: Plain text #: ../src/guide/databases/db-migrations.md -msgid "The first command will apply migrations in `@app/migrations/db1` to the `db1` database, the second command will apply migrations in `@app/migrations/db2` to `db2`, and so on." +#, no-wrap +msgid "> Note: If a migration is not reversible, you will not be able to redo it.\n" +msgstr "" + +#. type: Title ## +#: ../src/guide/databases/db-migrations.md +#, fuzzy, no-wrap +#| msgid "Raising events " +msgid "Listing Migrations " +msgstr "Lanzamiento de Eventos " + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +msgid "To list which migrations have been applied and which are not, you may use the following commands:" +msgstr "" + +#. type: Fenced code block +#: ../src/guide/databases/db-migrations.md +#, no-wrap +msgid "" +"./yii migrate/history # showing the last 10 applied migrations\n" +"./yii migrate:history --limit=5 # showing the last 5 applied migrations\n" +"./yii migrate:history --all # showing all applied migrations\n" +"\n" +"./yii migrate:new # showing the first 10 new migrations\n" +"./yii migrate:new --limit=5 # showing the first 5 new migrations\n" +"./yii migrate:new --all # showing all new migrations\n" msgstr "" #. type: Title ### @@ -977,5 +895,10 @@ msgstr "" #. type: Plain text #: ../src/guide/databases/db-migrations.md -msgid "Migrations in Yii 2.0 and the [yiisoft/db-migration](https://github.com/yiisoft/db-migration/) package are not compatible, and the `migration` table is also not compatible. A probable solution is to use structure dumps and rename the old `migration` table. Upon the initial execution of migrations, a new `migration` table with new fields will be created. All further changes in the database schema are applied using the new `migration` component and recorded in the new migration table." +msgid "Migrations in Yii 2.0 and the [yiisoft/db-migration](https://github.com/yiisoft/db-migration/) package are not compatible, and the `migration` table is also not compatible." +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +msgid "A probable solution is to use structure dumps and rename the old `migration` table. Upon the initial execution of migrations, a new `migration` table with new fields will be created. All further changes in the database schema are applied using the new `migration` component and recorded in the new migration table." msgstr "" diff --git a/_translations/po/es/internals_010-code-style.md.po b/_translations/po/es/internals_010-code-style.md.po index 642bbf83..36a528b7 100644 --- a/_translations/po/es/internals_010-code-style.md.po +++ b/_translations/po/es/internals_010-code-style.md.po @@ -6,7 +6,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" -"POT-Creation-Date: 2025-12-24 08:02+0000\n" +"POT-Creation-Date: 2025-12-27 10:28+0000\n" "PO-Revision-Date: 2025-12-24 08:02+0000\n" "Last-Translator: Automatically generated\n" "Language-Team: none\n" @@ -16,117 +16,123 @@ msgstr "" "Content-Transfer-Encoding: 8bit\n" "Plural-Forms: nplurals=2; plural=(n != 1);\n" +#. type: Title ## +#: ../src/guide/databases/db-migrations.md ../src/internals/010-code-style.md +#, no-wrap +msgid "Strings" +msgstr "" + #. type: Title # -#: ../src/en/internals/010-code-style.md +#: ../src/internals/010-code-style.md #, no-wrap msgid "010 — Code style" msgstr "" #. type: Plain text -#: ../src/en/internals/010-code-style.md +#: ../src/internals/010-code-style.md msgid "Code formatting used in Yii 3 packages is based on [PSR-1](https://www.php-fig.org/psr/psr-1/) and [PSR-12](https://www.php-fig.org/psr/psr-12/) with extra rules added on top of it." msgstr "" #. type: Title ### -#: ../src/en/internals/010-code-style.md ../src/en/internals/017-tags.md -#: ../src/en/internals/018-widgets.md +#: ../src/internals/010-code-style.md ../src/internals/017-tags.md +#: ../src/internals/018-widgets.md #, no-wrap msgid "Names" msgstr "" #. type: Bullet: '- ' -#: ../src/en/internals/010-code-style.md +#: ../src/internals/010-code-style.md msgid "Use English only." msgstr "" #. type: Bullet: '- ' -#: ../src/en/internals/010-code-style.md +#: ../src/internals/010-code-style.md msgid "Use camelCase notation, including abbreviations (e.g., `enableIdn`)." msgstr "" #. type: Bullet: '- ' -#: ../src/en/internals/010-code-style.md +#: ../src/internals/010-code-style.md msgid "Use the shortest possible, but an explanatory name." msgstr "" #. type: Bullet: '- ' -#: ../src/en/internals/010-code-style.md +#: ../src/internals/010-code-style.md msgid "Never trim or abbreviate a name." msgstr "" #. type: Bullet: '- ' -#: ../src/en/internals/010-code-style.md +#: ../src/internals/010-code-style.md msgid "Postfix classes, interfaces, traits and variables, which is a [collection](https://en.wikipedia.org/wiki/Collection_(abstract_data_type)), with `Collection`." msgstr "" #. type: Title ## -#: ../src/en/internals/010-code-style.md +#: ../src/internals/010-code-style.md #, no-wrap msgid "Types" msgstr "" #. type: Bullet: '- ' -#: ../src/en/internals/010-code-style.md +#: ../src/internals/010-code-style.md msgid "Declare [argument and return types](https://www.php.net/manual/en/migration70.new-features.php) where possible." msgstr "" #. type: Bullet: '- ' -#: ../src/en/internals/010-code-style.md +#: ../src/internals/010-code-style.md msgid "[Use types for properties](https://wiki.php.net/rfc/typed_properties_v2)." msgstr "" #. type: Bullet: '- ' -#: ../src/en/internals/010-code-style.md +#: ../src/internals/010-code-style.md msgid "Use strict typing. Avoid mixed and union types where possible except compatible types such as `string|Stringable`." msgstr "" #. type: Title ## -#: ../src/en/internals/010-code-style.md +#: ../src/internals/010-code-style.md #, no-wrap msgid "Comments" msgstr "" #. type: Plain text -#: ../src/en/internals/010-code-style.md +#: ../src/internals/010-code-style.md msgid "Inline comments are to be avoided unless code couldn't be understood without them. A good example is a workaround for a bug in a certain PHP version." msgstr "" #. type: Plain text -#: ../src/en/internals/010-code-style.md +#: ../src/internals/010-code-style.md msgid "Method comment is necessary except it adds nothing to what method name and signature already has." msgstr "" #. type: Plain text -#: ../src/en/internals/010-code-style.md +#: ../src/internals/010-code-style.md msgid "Class comment should describe the purpose of the class." msgstr "" #. type: Plain text -#: ../src/en/internals/010-code-style.md +#: ../src/internals/010-code-style.md #, fuzzy #| msgid "[Validating input](https://github.com/yiisoft/validator/blob/master/docs/guide/en/README.md) +" msgid "[See PHPDoc](https://github.com/yiisoft/docs/blob/master/014-docs.md#phpdoc)." msgstr "[Validar Datos](https://github.com/yiisoft/validator/blob/master/docs/guide/en/README.md)" #. type: Title ## -#: ../src/en/internals/010-code-style.md +#: ../src/internals/010-code-style.md #, no-wrap msgid "Formatting" msgstr "" #. type: Title ### -#: ../src/en/internals/010-code-style.md +#: ../src/internals/010-code-style.md #, no-wrap msgid "No alignment" msgstr "" #. type: Plain text -#: ../src/en/internals/010-code-style.md +#: ../src/internals/010-code-style.md msgid "Property, variable and constant value assignments shouldn't be aligned. The same applies to phpdoc tags. The reason is that aligned statements often cause larger diff and even conflicts." msgstr "" #. type: Fenced code block (php) -#: ../src/en/internals/010-code-style.md +#: ../src/internals/010-code-style.md #, no-wrap msgid "" "final class X\n" @@ -150,18 +156,18 @@ msgid "" msgstr "" #. type: Title ### -#: ../src/en/internals/010-code-style.md +#: ../src/internals/010-code-style.md #, no-wrap msgid "Chain calls" msgstr "" #. type: Plain text -#: ../src/en/internals/010-code-style.md +#: ../src/internals/010-code-style.md msgid "Chained calls should be formatted for better readability. If it's a long chain that doesn't fit the line length of 120 characters, then each call should on a new line:" msgstr "" #. type: Fenced code block (php) -#: ../src/en/internals/010-code-style.md +#: ../src/internals/010-code-style.md #, no-wrap msgid "" "$object\n" @@ -173,149 +179,143 @@ msgid "" msgstr "" #. type: Plain text -#: ../src/en/internals/010-code-style.md +#: ../src/internals/010-code-style.md msgid "If it's a short chain, it's alright for it to be on a single line:" msgstr "" #. type: Fenced code block (php) -#: ../src/en/internals/010-code-style.md +#: ../src/internals/010-code-style.md #, no-wrap msgid "$object = $object->withName('test');\n" msgstr "" -#. type: Title ## -#: ../src/en/internals/010-code-style.md -#, no-wrap -msgid "Strings" -msgstr "" - #. type: Bullet: '- ' -#: ../src/en/internals/010-code-style.md +#: ../src/internals/010-code-style.md msgid "When no variables involved, use `'Hello!'`" msgstr "" #. type: Bullet: '- ' -#: ../src/en/internals/010-code-style.md +#: ../src/internals/010-code-style.md msgid "To get variables into string prefer `\"Hello, $username!\"`" msgstr "" #. type: Title ## -#: ../src/en/internals/010-code-style.md +#: ../src/internals/010-code-style.md #, no-wrap msgid "Classes and interfaces" msgstr "" #. type: Title ### -#: ../src/en/internals/010-code-style.md +#: ../src/internals/010-code-style.md #, no-wrap msgid "Final by default" msgstr "" #. type: Plain text -#: ../src/en/internals/010-code-style.md +#: ../src/internals/010-code-style.md msgid "Classes should be `final` by default." msgstr "" #. type: Title ### -#: ../src/en/internals/010-code-style.md +#: ../src/internals/010-code-style.md #, no-wrap msgid "Private by default" msgstr "" #. type: Plain text -#: ../src/en/internals/010-code-style.md +#: ../src/internals/010-code-style.md msgid "Constants, properties and methods should be private by default." msgstr "" #. type: Title ### -#: ../src/en/internals/010-code-style.md +#: ../src/internals/010-code-style.md #, no-wrap msgid "Composition over inheritance" msgstr "" #. type: Plain text -#: ../src/en/internals/010-code-style.md +#: ../src/internals/010-code-style.md #, fuzzy #| msgid "[Dependency injection container](concept/di-container.md) +" msgid "Prefer [composition to inheritance](guide/en/concept/di-container.md)." msgstr "[Contenedor de Inyección de Dependencia](concept/di-container.md)" #. type: Title ### -#: ../src/en/internals/010-code-style.md +#: ../src/internals/010-code-style.md #, no-wrap msgid "Property, constant and method order" msgstr "" #. type: Plain text -#: ../src/en/internals/010-code-style.md +#: ../src/internals/010-code-style.md #, fuzzy #| msgid "The event class itself may look like the following:" msgid "Order should be the following:" msgstr "La clase del evento en sí se podría ver como esto:" #. type: Bullet: '- ' -#: ../src/en/internals/010-code-style.md +#: ../src/internals/010-code-style.md msgid "Constants" msgstr "" #. type: Bullet: '- ' -#: ../src/en/internals/010-code-style.md +#: ../src/internals/010-code-style.md msgid "Properties" msgstr "" #. type: Title ## -#: ../src/en/internals/010-code-style.md ../src/en/internals/017-tags.md -#: ../src/en/internals/018-widgets.md +#: ../src/internals/010-code-style.md ../src/internals/017-tags.md +#: ../src/internals/018-widgets.md #, no-wrap msgid "Methods" msgstr "" #. type: Plain text -#: ../src/en/internals/010-code-style.md +#: ../src/internals/010-code-style.md msgid "Within each category, items should be sorted by visibility:" msgstr "" #. type: Bullet: '- ' -#: ../src/en/internals/010-code-style.md +#: ../src/internals/010-code-style.md msgid "public" msgstr "" #. type: Bullet: '- ' -#: ../src/en/internals/010-code-style.md +#: ../src/internals/010-code-style.md msgid "protected" msgstr "" #. type: Bullet: '- ' -#: ../src/en/internals/010-code-style.md +#: ../src/internals/010-code-style.md msgid "private" msgstr "" #. type: Title ### -#: ../src/en/internals/010-code-style.md +#: ../src/internals/010-code-style.md #, no-wrap msgid "Abstract classes" msgstr "" #. type: Plain text -#: ../src/en/internals/010-code-style.md +#: ../src/internals/010-code-style.md msgid "Abstract classes *shouldn't* be prefixed or postfixed with `Abstract`." msgstr "" #. type: Title #### -#: ../src/en/internals/010-code-style.md +#: ../src/internals/010-code-style.md #, no-wrap msgid "Immutable methods" msgstr "" #. type: Plain text -#: ../src/en/internals/010-code-style.md +#: ../src/internals/010-code-style.md #, fuzzy #| msgid "You can attach a handler to an event like the following:" msgid "Immutable method convention is the following:" msgstr "Puedes acoplar un gestor a un evento como se demuestra a continuación:" #. type: Fenced code block (php) -#: ../src/en/internals/010-code-style.md +#: ../src/internals/010-code-style.md #, no-wrap msgid "" "public function withName(string $name): self\n" @@ -327,28 +327,28 @@ msgid "" msgstr "" #. type: Bullet: '1. ' -#: ../src/en/internals/010-code-style.md +#: ../src/internals/010-code-style.md msgid "Cloned object name is `$new`." msgstr "" #. type: Bullet: '2. ' -#: ../src/en/internals/010-code-style.md +#: ../src/internals/010-code-style.md msgid "Return type is `self`." msgstr "" #. type: Title #### -#: ../src/en/internals/010-code-style.md +#: ../src/internals/010-code-style.md #, no-wrap msgid "Boolean check methods" msgstr "" #. type: Plain text -#: ../src/en/internals/010-code-style.md +#: ../src/internals/010-code-style.md msgid "Methods that are there to check if something is true should be named like the following:" msgstr "" #. type: Fenced code block (php) -#: ../src/en/internals/010-code-style.md +#: ../src/internals/010-code-style.md #, no-wrap msgid "" "public function isDeleted(): bool;\n" @@ -357,29 +357,29 @@ msgid "" msgstr "" #. type: Title #### -#: ../src/en/internals/010-code-style.md +#: ../src/internals/010-code-style.md #, no-wrap msgid "Flags in methods " msgstr "" #. type: Plain text -#: ../src/en/internals/010-code-style.md +#: ../src/internals/010-code-style.md msgid "Boolean flags in methods are better to be avoided. It's a sign the method may be doing too much, and there should be two methods instead of one." msgstr "" #. type: Fenced code block (php) -#: ../src/en/internals/010-code-style.md +#: ../src/internals/010-code-style.md #, no-wrap msgid "public function login(bool $refreshPage = true): void;\n" msgstr "" #. type: Plain text -#: ../src/en/internals/010-code-style.md +#: ../src/internals/010-code-style.md msgid "It is better to be two methods:" msgstr "" #. type: Fenced code block (php) -#: ../src/en/internals/010-code-style.md +#: ../src/internals/010-code-style.md #, no-wrap msgid "" "public function login(): void;\n" @@ -387,18 +387,18 @@ msgid "" msgstr "" #. type: Title ## -#: ../src/en/internals/010-code-style.md +#: ../src/internals/010-code-style.md #, no-wrap msgid "Variables" msgstr "" #. type: Plain text -#: ../src/en/internals/010-code-style.md +#: ../src/internals/010-code-style.md msgid "Add an underscore (`_`) prefix for unused variables. For example:" msgstr "" #. type: Fenced code block (php) -#: ../src/en/internals/010-code-style.md +#: ../src/internals/010-code-style.md #, no-wrap msgid "" "foreach ($items as $key => $_value) {\n" @@ -407,18 +407,18 @@ msgid "" msgstr "" #. type: Title ## -#: ../src/en/internals/010-code-style.md +#: ../src/internals/010-code-style.md #, no-wrap msgid "Imports" msgstr "" #. type: Plain text -#: ../src/en/internals/010-code-style.md +#: ../src/internals/010-code-style.md msgid "Prefer importing classes and functions to using fully qualified names:" msgstr "" #. type: Fenced code block (php) -#: ../src/en/internals/010-code-style.md +#: ../src/internals/010-code-style.md #, no-wrap msgid "" "use Yiisoft\\Arrays\\ArrayHelper;\n" @@ -430,24 +430,24 @@ msgid "" msgstr "" #. type: Title ## -#: ../src/en/internals/010-code-style.md +#: ../src/internals/010-code-style.md #, no-wrap msgid "Additional conventions" msgstr "" #. type: Bullet: '- ' -#: ../src/en/internals/010-code-style.md +#: ../src/internals/010-code-style.md msgid "[Namespaces](004-namespaces.md)" msgstr "" #. type: Bullet: '- ' -#: ../src/en/internals/010-code-style.md +#: ../src/internals/010-code-style.md #, fuzzy #| msgid "[Actions](structure/action.md) +" msgid "[Exceptions](007-exceptions.md)" msgstr "[Acciones](structure/action.md)" #. type: Bullet: '- ' -#: ../src/en/internals/010-code-style.md +#: ../src/internals/010-code-style.md msgid "[Interfaces](008-interfaces.md)" msgstr "" diff --git a/_translations/po/id/guide_databases_db-migrations.md.po b/_translations/po/id/guide_databases_db-migrations.md.po index c4817764..bb6bd071 100644 --- a/_translations/po/id/guide_databases_db-migrations.md.po +++ b/_translations/po/id/guide_databases_db-migrations.md.po @@ -6,7 +6,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" -"POT-Creation-Date: 2025-12-27 08:43+0000\n" +"POT-Creation-Date: 2025-12-27 10:28+0000\n" "PO-Revision-Date: 2025-09-04 11:19+0500\n" "Last-Translator: Automatically generated\n" "Language-Team: none\n" @@ -166,12 +166,17 @@ msgid "" "],\n" msgstr "" +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +msgid "If you want to place migrations elsewhere, you can define the path in `newMigrationPath`. If your migrations to be applied are from multiple sources, such as external modules, `sourcePaths` could be used to define these." +msgstr "" + #. type: Plain text #: ../src/guide/databases/db-migrations.md msgid "You need a database connection configured as well. See [Working with databases](../start/databases.md) for an example of configuring it for PostgreSQL." msgstr "" -#. type: Title ### +#. type: Title ## #: ../src/guide/databases/db-migrations.md #, no-wrap msgid "Creating a migration" @@ -185,7 +190,9 @@ msgstr "" #. type: Fenced code block (sh) #: ../src/guide/databases/db-migrations.md #, no-wrap -msgid "make yii migrate:create \n" +msgid "" +"make shell\n" +"./yii migrate:create \n" msgstr "" #. type: Plain text @@ -196,7 +203,9 @@ msgstr "" #. type: Fenced code block #: ../src/guide/databases/db-migrations.md #, no-wrap -msgid "make yii migrate:create create_news_table\n" +msgid "" +"make shell\n" +"./yii migrate:create create_news_table\n" msgstr "" #. type: Plain text @@ -280,691 +289,600 @@ msgstr "" #. type: Plain text #: ../src/guide/databases/db-migrations.md -#, no-wrap -msgid "" -"TODO: explain $b and $qb\n" -"Below is the list of all these database accessing methods:\n" -msgstr "" - -#. type: Title ### -#: ../src/guide/databases/db-migrations.md -#, no-wrap -msgid "Irreversible migrations" +msgid "Migration builder `$b` in the above manages database schema while the column builder `$cb` manages column types. Both allow using *abstract types*. When a migration is applied to a particular database, the abstract types will be translated into the corresponding database physical types and corresponding SQL to define them." msgstr "" #. type: Plain text #: ../src/guide/databases/db-migrations.md -msgid "Not all migrations are reversible. For example, if the `up()` method deletes a row of a table, you may not be able to recover this row in the `down()` method. Sometimes, you may be just too lazy to implement the `down()`, because it is not very common to revert database migrations. In this case, you should implement `Yiisoft\\Db\\Migration\\MigrationInterface` that has `up()` only." +msgid "Methods available in migration builder belong to the following types:" msgstr "" -#. type: Title ### +#. type: Bullet: '- ' #: ../src/guide/databases/db-migrations.md -#, no-wrap -msgid "Transactional migrations (TODO: update!!!)" +msgid "Raw queries" msgstr "" -#. type: Plain text +#. type: Bullet: ' - ' #: ../src/guide/databases/db-migrations.md -msgid "While performing complex DB migrations, it is important to ensure each migration to either succeed or fail as a whole so that the database can maintain integrity and consistency. To achieve this goal, it is recommended that you enclose the DB operations of each migration in a [transaction](db-dao.md#performing-transactions)." +msgid "getDb — to get database connection instance." msgstr "" -#. type: Plain text +#. type: Bullet: ' - ' #: ../src/guide/databases/db-migrations.md -msgid "An even easier way of implementing transactional migrations is to put migration code in the `safeUp()` and `safeDown()` methods. These two methods differ from `up()` and `down()` in that they are enclosed implicitly in a transaction. As a result, if any operation in these methods fails, all prior operations will be rolled back automatically." +msgid "execute — to execute raw SQL query." msgstr "" -#. type: Plain text +#. type: Bullet: '- ' #: ../src/guide/databases/db-migrations.md -msgid "In the following example, besides creating the `news` table we also insert an initial row into this table." +msgid "Data" msgstr "" -#. type: Fenced code block (php) +#. type: Bullet: ' - ' #: ../src/guide/databases/db-migrations.md -#, no-wrap -msgid "" -"createTable('news', [\n" -" 'id' => $this->primaryKey(),\n" -" 'title' => $this->string()->notNull(),\n" -" 'content' => $this->text(),\n" -" ]);\n" -"\n" -" $this->insert('news', [\n" -" 'title' => 'test 1',\n" -" 'content' => 'content 1',\n" -" ]);\n" -" }\n" -"\n" -" public function safeDown()\n" -" {\n" -" $this->delete('news', ['id' => 1]);\n" -" $this->dropTable('news');\n" -" }\n" -"}\n" +msgid "insert / update / delete" msgstr "" -#. type: Plain text +#. type: Bullet: ' - ' #: ../src/guide/databases/db-migrations.md -msgid "Note that usually when you perform multiple DB operations in `safeUp()`, you should reverse their execution order in `safeDown()`. In the above example we first create the table and then insert a row in `safeUp()`; while in `safeDown()` we first delete the row and then drop the table." +msgid "batchInsert" msgstr "" -#. type: Plain text +#. type: Bullet: ' - ' #: ../src/guide/databases/db-migrations.md -#, no-wrap -msgid "" -"> Note: Not all DBMS support transactions. And some DB queries cannot be put into a transaction. For some examples,\n" -"please refer to [implicit commit](https://dev.mysql.com/doc/refman/5.7/en/implicit-commit.html). If this is the case,\n" -"you should still implement `up()` and `down()`, instead.\n" +msgid "upsert" msgstr "" -#. type: Plain text +#. type: Bullet: '- ' #: ../src/guide/databases/db-migrations.md -#, no-wrap -msgid "TODO: TransactionalMigrationInterface\n" +msgid "Tables and views" msgstr "" -#. type: Title ## +#. type: Bullet: ' - ' #: ../src/guide/databases/db-migrations.md -#, no-wrap -msgid "TODO: update" +msgid "createTable / renameTable / dropTable" msgstr "" -#. type: Plain text +#. type: Bullet: ' - ' #: ../src/guide/databases/db-migrations.md -msgid "The base migration class [[yii\\db\\Migration]] exposes a database connection via the [[yii\\db\\Migration::db|db]] property. You can use it to manipulate the database schema using the methods as described in [Working with Database Schema](db-dao.md#database-schema)." +msgid "truncateTable" msgstr "" -#. type: Plain text +#. type: Bullet: ' - ' #: ../src/guide/databases/db-migrations.md -#, no-wrap -msgid "" -"Rather than using physical types, when creating a table or column you should use *abstract types*\n" -"so that your migrations are independent of specific DBMS. The [[yii\\db\\Schema]] class defines\n" -"a set of constants to represent the supported abstract types. These constants are named in the format\n" -"of `TYPE_`. For example, `TYPE_PK` refers to auto-incremental primary key type; `TYPE_STRING`\n" -"refers to a string type. When a migration is applied to a particular database, the abstract types\n" -"will be translated into the corresponding physical types. In the case of MySQL, `TYPE_PK` will be turned\n" -"into `int(11) NOT NULL AUTO_INCREMENT PRIMARY KEY`, while `TYPE_STRING` becomes `varchar(255)`.\n" +msgid "addCommentOnTable / dropCommentFromTable" msgstr "" -#. type: Plain text +#. type: Bullet: ' - ' #: ../src/guide/databases/db-migrations.md -msgid "You can append additional constraints when using abstract types. In the above example, ` NOT NULL` is appended to `Schema::TYPE_STRING` to specify that the column cannot be `null`." +msgid "createView / dropView" msgstr "" -#. type: Plain text +#. type: Bullet: '- ' #: ../src/guide/databases/db-migrations.md -#, no-wrap -msgid "" -"> Info: The mapping between abstract types and physical types is specified by\n" -"the [[yii\\db\\QueryBuilder::$typeMap|$typeMap]] property in each concrete `QueryBuilder` class.\n" +msgid "Columns" msgstr "" -#. type: Plain text +#. type: Bullet: ' - ' #: ../src/guide/databases/db-migrations.md -msgid "Since version 2.0.6, you can make use of the newly introduced schema builder which provides more convenient way of defining column schema. So the migration above could be written like the following:" +msgid "addColumn / renameColumn / alterColumn / dropColumn" msgstr "" -#. type: Fenced code block (php) +#. type: Bullet: ' - ' #: ../src/guide/databases/db-migrations.md -#, no-wrap -msgid "" -"createTable('news', [\n" -" 'id' => $this->primaryKey(),\n" -" 'title' => $this->string()->notNull(),\n" -" 'content' => $this->text(),\n" -" ]);\n" -" }\n" -"\n" -" public function down()\n" -" {\n" -" $this->dropTable('news');\n" -" }\n" -"}\n" +msgid "addCommentOnColumn / dropCommentFromColumn" msgstr "" -#. type: Plain text +#. type: Bullet: '- ' #: ../src/guide/databases/db-migrations.md -msgid "A list of all available methods for defining the column types is available in the API documentation of [[yii\\db\\SchemaBuilderTrait]]." +msgid "Keys and indexes" msgstr "" -#. type: Plain text +#. type: Bullet: ' - ' #: ../src/guide/databases/db-migrations.md -#, no-wrap -msgid "" -"> Info: The generated file permissions and ownership will be determined by the current environment. This might lead to\n" -"inaccessible files. This could, for example, happen when the migration is created within a docker container\n" -"and the files are edited on the host. In this case the `newFileMode` and/or `newFileOwnership` of the MigrateController\n" -"can be changed. E.g. in the application config:\n" +msgid "addPrimaryKey / dropPrimaryKey" msgstr "" -#. type: Fenced code block (php) +#. type: Bullet: ' - ' #: ../src/guide/databases/db-migrations.md -#, no-wrap -msgid "" -" [\n" -" 'migrate' => [\n" -" 'class' => 'yii\\console\\controllers\\MigrateController',\n" -" 'newFileOwnership' => '1000:1000', # Default WSL user id\n" -" 'newFileMode' => 0660,\n" -" ],\n" -" ],\n" -" ];\n" +msgid "addForeignKey / dropForeignKey" msgstr "" -#. type: Title ## +#. type: Bullet: ' - ' #: ../src/guide/databases/db-migrations.md -#, no-wrap -msgid "Generating Migrations (TODO: likely is OK but...)" +msgid "createIndex / dropIndex" msgstr "" #. type: Plain text #: ../src/guide/databases/db-migrations.md -msgid "The command provides a convenient way to create migrations using the provided [view](https://github.com/yiisoft/db-migration/tree/master/resources/views):" +msgid "Additionally, there's a `columnBuilder()` which is used to obtain a column builder as in example above. The builder has static methods that define various column types:" msgstr "" -#. type: Fenced code block (shell) +#. type: Bullet: '- ' #: ../src/guide/databases/db-migrations.md -#, no-wrap -msgid "make yii migrate:create my_first_table --command=table --fields=name,example --table-comment=my_first_table\n" +msgid "Keys" msgstr "" -#. type: Plain text +#. type: Bullet: ' - ' #: ../src/guide/databases/db-migrations.md -msgid "That would generate the following:" +msgid "primaryKey" msgstr "" -#. type: Fenced code block (php) +#. type: Bullet: ' - ' #: ../src/guide/databases/db-migrations.md -#, no-wrap -msgid "" -"createTable('my_first_table', [\n" -" 'id' => $b->primaryKey(),\n" -" 'name',\n" -" 'example',\n" -" ]);\n" -" \n" -" $b->addCommentOnTable('my_first_table', 'dest');\n" -" }\n" -"\n" -" public function down(MigrationBuilder $b): void\n" -" {\n" -" $b->dropTable('my_first_table');\n" -" }\n" -"}\n" +msgid "smallPrimaryKey" msgstr "" -#. type: Plain text +#. type: Bullet: ' - ' #: ../src/guide/databases/db-migrations.md -msgid "For more information [see](https://github.com/yiisoft/db-migration/tree/master/docs/guide/en)" +msgid "bigPrimaryKey" msgstr "" -#. type: Title ## +#. type: Bullet: ' - ' #: ../src/guide/databases/db-migrations.md -#, fuzzy, no-wrap -#| msgid "Configuration" -msgid "Applying Migrations" -msgstr "Konfigurasi" +msgid "uuidPrimaryKey" +msgstr "" -#. type: Plain text +#. type: Bullet: '- ' #: ../src/guide/databases/db-migrations.md -msgid "To upgrade a database to its latest structure, you should apply all available new migrations using the following command:" +msgid "Boolean" msgstr "" -#. type: Fenced code block +#. type: Bullet: ' - ' #: ../src/guide/databases/db-migrations.md -#, no-wrap -msgid "yii migrate\n" +msgid "boolean" msgstr "" -#. type: Plain text +#. type: Bullet: '- ' #: ../src/guide/databases/db-migrations.md -msgid "This command will list all migrations that have not been applied so far. If you confirm that you want to apply these migrations, it will run the `up()` or `safeUp()` method in every new migration class, one after another, in the order of their timestamp values. If any of the migrations fails, the command will quit without applying the rest of the migrations." +msgid "Numbers" msgstr "" -#. type: Plain text +#. type: Bullet: ' - ' #: ../src/guide/databases/db-migrations.md -#, no-wrap -msgid "" -"> Tip: In case you don't have command line at your server you may try [web shell](https://github.com/samdark/yii2-webshell)\n" -"> extension.\n" +msgid "bit" msgstr "" -#. type: Plain text +#. type: Bullet: ' - ' #: ../src/guide/databases/db-migrations.md -msgid "For each migration that has been successfully applied, the command will insert a row into a database table named `migration` to record the successful application of the migration. This will allow the migration tool to identify which migrations have been applied and which have not." +msgid "tinyint" msgstr "" -#. type: Plain text +#. type: Bullet: ' - ' #: ../src/guide/databases/db-migrations.md -#, no-wrap -msgid "" -"> Info: The migration tool will automatically create the `migration` table in the database specified by\n" -"the [[yii\\console\\controllers\\MigrateController::db|db]] option of the command. By default, the database\n" -"is specified by the `db` [application component](structure-application-components.md).\n" +msgid "smallint" msgstr "" -#. type: Plain text +#. type: Bullet: ' - ' #: ../src/guide/databases/db-migrations.md -msgid "Sometimes, you may only want to apply one or a few new migrations, instead of all available migrations. You can do so by specifying the number of migrations that you want to apply when running the command. For example, the following command will try to apply the next three available migrations:" +msgid "integer" msgstr "" -#. type: Fenced code block +#. type: Bullet: ' - ' #: ../src/guide/databases/db-migrations.md -#, no-wrap -msgid "yii migrate 3\n" +msgid "bigint" msgstr "" -#. type: Plain text +#. type: Bullet: ' - ' #: ../src/guide/databases/db-migrations.md -msgid "You can also explicitly specify a particular migration to which the database should be migrated by using the `migrate/to` command in one of the following formats:" +msgid "flat" msgstr "" -#. type: Fenced code block +#. type: Bullet: ' - ' #: ../src/guide/databases/db-migrations.md -#, no-wrap -msgid "" -"yii migrate/to 150101_185401 # using timestamp to specify the migration\n" -"yii migrate/to \"2015-01-01 18:54:01\" # using a string that can be parsed by strtotime()\n" -"yii migrate/to m150101_185401_create_news_table # using full name\n" -"yii migrate/to 1392853618 # using UNIX timestamp\n" +msgid "double" msgstr "" -#. type: Plain text +#. type: Bullet: ' - ' #: ../src/guide/databases/db-migrations.md -msgid "If there are any unapplied migrations earlier than the specified one, they will all be applied before the specified migration is applied." +msgid "decimal" msgstr "" -#. type: Plain text +#. type: Title ## +#: ../src/guide/databases/db-migrations.md ../src/internals/010-code-style.md +#, no-wrap +msgid "Strings" +msgstr "" + +#. type: Bullet: ' - ' #: ../src/guide/databases/db-migrations.md -msgid "If the specified migration has already been applied before, any later applied migrations will be reverted." +msgid "char" msgstr "" -#. type: Title ## +#. type: Bullet: ' - ' #: ../src/guide/databases/db-migrations.md -#, fuzzy, no-wrap -#| msgid "Resolving aliases " -msgid "Reverting Migrations " -msgstr "Me-resolve alias " +msgid "string" +msgstr "" -#. type: Plain text +#. type: Bullet: ' - ' #: ../src/guide/databases/db-migrations.md -msgid "To revert (undo) one or multiple migrations that have been applied before, you can run the following command:" +msgid "text" msgstr "" -#. type: Fenced code block +#. type: Bullet: '- ' #: ../src/guide/databases/db-migrations.md -#, no-wrap -msgid "" -"yii migrate/down # revert the most recently applied migration\n" -"yii migrate/down 3 # revert the most 3 recently applied migrations\n" +msgid "Date and time" msgstr "" -#. type: Plain text +#. type: Bullet: ' - ' #: ../src/guide/databases/db-migrations.md -#, no-wrap -msgid "" -"> Note: Not all migrations are reversible. Trying to revert such migrations will cause an error and stop the\n" -"entire reverting process.\n" +msgid "timestamp" msgstr "" -#. type: Title ## +#. type: Bullet: ' - ' #: ../src/guide/databases/db-migrations.md -#, fuzzy, no-wrap -#| msgid "Resolving aliases " -msgid "Redoing Migrations " -msgstr "Me-resolve alias " +msgid "datetime" +msgstr "" -#. type: Plain text +#. type: Bullet: ' - ' #: ../src/guide/databases/db-migrations.md -msgid "Redoing migrations means first reverting the specified migrations and then applying again. This can be done as follows:" +msgid "datetimeWithTimezone" msgstr "" -#. type: Fenced code block +#. type: Bullet: ' - ' #: ../src/guide/databases/db-migrations.md -#, no-wrap -msgid "" -"yii migrate/redo # redo the last applied migration\n" -"yii migrate/redo 3 # redo the last 3 applied migrations\n" +msgid "time" msgstr "" -#. type: Plain text +#. type: Bullet: ' - ' #: ../src/guide/databases/db-migrations.md -#, no-wrap -msgid "> Note: If a migration is not reversible, you will not be able to redo it.\n" +msgid "timeWithTimezone" msgstr "" -#. type: Title ## +#. type: Bullet: ' - ' #: ../src/guide/databases/db-migrations.md -#, fuzzy, no-wrap -#| msgid "Resolving aliases " -msgid "Refreshing Migrations " -msgstr "Me-resolve alias " +msgid "date" +msgstr "" -#. type: Plain text +#. type: Bullet: '- ' #: ../src/guide/databases/db-migrations.md -msgid "Since Yii 2.0.13 you can delete all tables and foreign keys from the database and apply all migrations from the beginning." +msgid "Special types" msgstr "" -#. type: Fenced code block +#. type: Bullet: ' - ' #: ../src/guide/databases/db-migrations.md -#, no-wrap -msgid "yii migrate/fresh # truncate the database and apply all migrations from the beginning\n" +msgid "money" msgstr "" -#. type: Title ## +#. type: Bullet: ' - ' #: ../src/guide/databases/db-migrations.md -#, fuzzy, no-wrap -#| msgid "Using aliases in configuration " -msgid "Listing Migrations " -msgstr "Menggunakan aliases di konfigurasi " +msgid "binary" +msgstr "" -#. type: Plain text +#. type: Bullet: ' - ' #: ../src/guide/databases/db-migrations.md -msgid "To list which migrations have been applied and which are not, you may use the following commands:" +msgid "uuid" msgstr "" -#. type: Fenced code block +#. type: Bullet: ' - ' #: ../src/guide/databases/db-migrations.md -#, no-wrap -msgid "" -"yii migrate/history # showing the last 10 applied migrations\n" -"yii migrate/history 5 # showing the last 5 applied migrations\n" -"yii migrate/history all # showing all applied migrations\n" -"\n" -"yii migrate/new # showing the first 10 new migrations\n" -"yii migrate/new 5 # showing the first 5 new migrations\n" -"yii migrate/new all # showing all new migrations\n" +msgid "array" msgstr "" -#. type: Title ## +#. type: Bullet: ' - ' #: ../src/guide/databases/db-migrations.md -#, no-wrap -msgid "Modifying Migration History " +msgid "structured" msgstr "" -#. type: Plain text +#. type: Bullet: ' - ' #: ../src/guide/databases/db-migrations.md -msgid "Instead of actually applying or reverting migrations, sometimes you may simply want to mark that your database has been upgraded to a particular migration. This often happens when you manually change the database to a particular state and you do not want the migration(s) for that change to be re-applied later. You can achieve this goal with the following command:" +msgid "json" msgstr "" -#. type: Fenced code block +#. type: Bullet: '- ' #: ../src/guide/databases/db-migrations.md -#, no-wrap -msgid "" -"yii migrate/mark 150101_185401 # using timestamp to specify the migration\n" -"yii migrate/mark \"2015-01-01 18:54:01\" # using a string that can be parsed by strtotime()\n" -"yii migrate/mark m150101_185401_create_news_table # using full name\n" -"yii migrate/mark 1392853618 # using UNIX timestamp\n" +msgid "enum" msgstr "" #. type: Plain text #: ../src/guide/databases/db-migrations.md -msgid "The command will modify the `migration` table by adding or deleting certain rows to indicate that the database has been applied migrations to the specified one. No migrations will be applied or reverted by this command." +msgid "All the above methods create a base type which could be adjusted with additional methods:" msgstr "" -#. type: Title ## +#. type: Bullet: '- ' #: ../src/guide/databases/db-migrations.md -#, fuzzy, no-wrap -#| msgid "Using aliases in configuration " -msgid "Customizing Migrations " -msgstr "Menggunakan aliases di konfigurasi " +msgid "null / notNull" +msgstr "" -#. type: Plain text +#. type: Bullet: '- ' #: ../src/guide/databases/db-migrations.md -msgid "There are several ways to customize the migration command." +msgid "defaultValue" msgstr "" -#. type: Title ### +#. type: Bullet: '- ' #: ../src/guide/databases/db-migrations.md -#, fuzzy, no-wrap -#| msgid "Using aliases in configuration " -msgid "Using Command Line Options " -msgstr "Menggunakan aliases di konfigurasi " +msgid "unique" +msgstr "" -#. type: Plain text +#. type: Bullet: '- ' #: ../src/guide/databases/db-migrations.md -msgid "The migration command comes with a few command-line options that can be used to customize its behaviors:" +msgid "scale / size / unsigned" msgstr "" -#. type: Bullet: '* ' +#. type: Bullet: '- ' #: ../src/guide/databases/db-migrations.md -msgid "`interactive`: boolean (defaults to `true`), specifies whether to perform migrations in an interactive mode. When this is `true`, the user will be prompted before the command performs certain actions. You may want to set this to `false` if the command is being used in a background process." +msgid "primaryKey / autoIncrement" msgstr "" -#. type: Bullet: '* ' +#. type: Bullet: '- ' #: ../src/guide/databases/db-migrations.md -msgid "`migrationPath`: string|array (defaults to `@app/migrations`), specifies the directory storing all migration class files. This can be specified as either a directory path or a path [alias](concept-aliases.md). Note that the directory must exist, or the command may trigger an error. Since version 2.0.12 an array can be specified for loading migrations from multiple sources." +msgid "check" msgstr "" -#. type: Bullet: '* ' +#. type: Bullet: '- ' #: ../src/guide/databases/db-migrations.md -msgid "`migrationTable`: string (defaults to `migration`), specifies the name of the database table for storing migration history information. The table will be automatically created by the command if it does not exist. You may also manually create it using the structure `version varchar(255) primary key, apply_time integer`." +msgid "comment" msgstr "" -#. type: Bullet: '* ' +#. type: Bullet: '- ' #: ../src/guide/databases/db-migrations.md -msgid "`db`: string (defaults to `db`), specifies the ID of the database [application component](structure-application-components.md). It represents the database that will be migrated using this command." +msgid "computed" msgstr "" -#. type: Bullet: '* ' +#. type: Bullet: '- ' #: ../src/guide/databases/db-migrations.md -msgid "`templateFile`: string (defaults to `@yii/views/migration.php`), specifies the path of the template file that is used for generating skeleton migration class files. This can be specified as either a file path or a path [alias](concept-aliases.md). The template file is a PHP script in which you can use a predefined variable named `$className` to get the migration class name." +msgid "extra" msgstr "" -#. type: Plain text +#. type: Bullet: '- ' +#: ../src/guide/databases/db-migrations.md +#, fuzzy +#| msgid "References" +msgid "reference" +msgstr "Referensi" + +#. type: Title ### #: ../src/guide/databases/db-migrations.md #, no-wrap -msgid "" -"* `generatorTemplateFiles`: array (defaults to `[\n" -" 'create_table' => '@yii/views/createTableMigration.php',\n" -" 'drop_table' => '@yii/views/dropTableMigration.php',\n" -" 'add_column' => '@yii/views/addColumnMigration.php',\n" -" 'drop_column' => '@yii/views/dropColumnMigration.php',\n" -" 'create_junction' => '@yii/views/createTableMigration.php'\n" -" ]`), specifies template files for generating migration code. See \"[Generating Migrations](#generating-migrations)\"\n" -" for more details.\n" +msgid "Irreversible migrations" msgstr "" -#. type: Bullet: '* ' +#. type: Plain text #: ../src/guide/databases/db-migrations.md -msgid "`fields`: array of column definition strings used for creating migration code. Defaults to `[]`. The format of each definition is `COLUMN_NAME:COLUMN_TYPE:COLUMN_DECORATOR`. For example, `--fields=name:string(12):notNull` produces a string column of size 12 which is not `null`." +msgid "Not all migrations are reversible. For example, if the `up()` method deletes a row of a table, you may not be able to recover this row in the `down()` method. Sometimes, you may be just too lazy to implement the `down()`, because it is not very common to revert database migrations. In this case, you should implement `Yiisoft\\Db\\Migration\\MigrationInterface` that has `up()` only." msgstr "" +#. type: Title ### +#: ../src/guide/databases/db-migrations.md +#, fuzzy, no-wrap +#| msgid "Container configuration" +msgid "Transactional migrations" +msgstr "Konfigurasi container" + #. type: Plain text #: ../src/guide/databases/db-migrations.md -msgid "The following example shows how you can use these options." +msgid "While performing complex DB migrations, it is important to ensure each migration to either succeed or fail as a whole so that the database can maintain integrity and consistency. To achieve this goal, it is recommended that you may enclose the DB operations of each migration in a transaction automatically by adding `TransactionalMigrationInterface` to `implements` of your migration." msgstr "" #. type: Plain text #: ../src/guide/databases/db-migrations.md -msgid "For example, if we want to migrate a `forum` module whose migration files are located within the module's `migrations` directory, we can use the following command:" +msgid "As a result, if any operation in the `up()` or `down()` method fails, all prior operations will be rolled back automatically." msgstr "" -#. type: Fenced code block +#. type: Plain text #: ../src/guide/databases/db-migrations.md #, no-wrap msgid "" -"# migrate the migrations in a forum module non-interactively\n" -"yii migrate --migrationPath=@app/modules/forum/migrations --interactive=0\n" +"> Note: Not all DBMS support transactions. And some DB queries cannot be put into a transaction. For some examples,\n" +"please refer to [implicit commit](https://dev.mysql.com/doc/refman/5.7/en/implicit-commit.html).\n" msgstr "" -#. type: Title ### +#. type: Title ## #: ../src/guide/databases/db-migrations.md -#, no-wrap -msgid "Separated Migrations" -msgstr "" +#, fuzzy, no-wrap +#| msgid "Generating API documentation" +msgid "Generating a migration" +msgstr "Membuat Dokumentasi API" #. type: Plain text #: ../src/guide/databases/db-migrations.md -msgid "Sometimes using single migration history for all project migrations is not desirable. For example: you may install some 'blog' extension, which contains fully separated functionality and contain its own migrations, which should not affect the ones dedicated to main project functionality." +msgid "Instead of writing migrations by hand, the command provides a convenient way generate some of the code." +msgstr "" + +#. type: Fenced code block (shell) +#: ../src/guide/databases/db-migrations.md +#, no-wrap +msgid "" +"make shell\n" +"./yii migrate:create -- my_first_table --command=table --fields=name,example --table-comment=my_first_table\n" msgstr "" #. type: Plain text #: ../src/guide/databases/db-migrations.md -msgid "If you want several migrations to be applied and tracked down completely separated from each other, you can configure multiple migration commands which will use different namespaces and migration history tables:" +msgid "That would generate the following:" msgstr "" #. type: Fenced code block (php) #: ../src/guide/databases/db-migrations.md #, no-wrap msgid "" -"return [\n" -" 'controllerMap' => [\n" -" // Common migrations for the whole application\n" -" 'migrate-app' => [\n" -" 'class' => 'yii\\console\\controllers\\MigrateController',\n" -" 'migrationNamespaces' => ['app\\migrations'],\n" -" 'migrationTable' => 'migration_app',\n" -" 'migrationPath' => null,\n" -" ],\n" -" // Migrations for the specific project's module\n" -" 'migrate-module' => [\n" -" 'class' => 'yii\\console\\controllers\\MigrateController',\n" -" 'migrationNamespaces' => ['module\\migrations'],\n" -" 'migrationTable' => 'migration_module',\n" -" 'migrationPath' => null,\n" -" ],\n" -" // Migrations for the specific extension\n" -" 'migrate-rbac' => [\n" -" 'class' => 'yii\\console\\controllers\\MigrateController',\n" -" 'migrationPath' => '@yii/rbac/migrations',\n" -" 'migrationTable' => 'migration_rbac',\n" -" ],\n" -" ],\n" -"];\n" -msgstr "" - -#. type: Plain text -#: ../src/guide/databases/db-migrations.md -msgid "Note that to synchronize database you now need to run multiple commands instead of one:" +"columnBuilder();\n" +"\n" +" $b->createTable('my_first_table', [\n" +" 'id' => $columnBuilder::primaryKey(),\n" +" 'name',\n" +" 'example',\n" +" ]);\n" +"\n" +" $b->addCommentOnTable('my_first_table', 'my_first_table');\n" +" }\n" +"\n" +" public function down(MigrationBuilder $b): void\n" +" {\n" +" $b->dropTable('my_first_table');\n" +" }\n" +"}\n" msgstr "" -#. type: Fenced code block +#. type: Plain text #: ../src/guide/databases/db-migrations.md -#, no-wrap -msgid "" -"yii migrate-app\n" -"yii migrate-module\n" -"yii migrate-rbac\n" +msgid "Commands available are:" +msgstr "" + +#. type: Bullet: '- ' +#: ../src/guide/databases/db-migrations.md +msgid "create - empty migration." +msgstr "" + +#. type: Bullet: '- ' +#: ../src/guide/databases/db-migrations.md +msgid "table - creating a table. Use `--fields` specify a list of fields to use. Types could be specified as well such as `id:primaryKey,name:string:defaultValue(\"Alex\"),user_id:integer:foreignKey,category_id2:integer:foreignKey(category id2)`." +msgstr "" + +#. type: Bullet: '- ' +#: ../src/guide/databases/db-migrations.md +msgid "dropTable - dropping a table." +msgstr "" + +#. type: Bullet: '- ' +#: ../src/guide/databases/db-migrations.md +msgid "addColumn - adding a column." +msgstr "" + +#. type: Bullet: '- ' +#: ../src/guide/databases/db-migrations.md +msgid "dropColumn - dropping a column." +msgstr "" + +#. type: Bullet: '- ' +#: ../src/guide/databases/db-migrations.md +msgid "junction - creating a junction table. Use `--and` specify a second table." msgstr "" #. type: Title ## #: ../src/guide/databases/db-migrations.md #, fuzzy, no-wrap -#| msgid "Defining aliases " -msgid "Migrating Multiple Databases " -msgstr "Defining aliases " +#| msgid "Configuration" +msgid "Applying Migrations" +msgstr "Konfigurasi" #. type: Plain text #: ../src/guide/databases/db-migrations.md -msgid "By default, migrations are applied to the same database specified by the `db` [application component](structure-application-components.md). If you want them to be applied to a different database, you may specify the `db` command-line option like shown below," +msgid "To upgrade a database to its latest structure, you should apply all available new migrations using the following command:" msgstr "" #. type: Fenced code block #: ../src/guide/databases/db-migrations.md #, no-wrap -msgid "yii migrate --db=db2\n" +msgid "./yii migrate:up\n" msgstr "" #. type: Plain text #: ../src/guide/databases/db-migrations.md -msgid "The above command will apply migrations to the `db2` database." +msgid "This command will list all migrations that have not been applied so far. If you confirm that you want to apply these migrations, it will run the `up()` method in every new migration class, one after another, in the order of their timestamp values. If any of the migrations fails, the command will quit without applying the rest of the migrations." msgstr "" #. type: Plain text #: ../src/guide/databases/db-migrations.md -msgid "Sometimes it may happen that you want to apply *some* of the migrations to one database, while some others to another database. To achieve this goal, when implementing a migration class you should explicitly specify the DB component ID that the migration would use, like the following:" +msgid "For each migration that has been successfully applied, the command will insert a row into a database table named `migration` to record the successful application of the migration. This will allow the migration tool to identify which migrations have been applied and which have not." msgstr "" -#. type: Fenced code block (php) +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +msgid "Sometimes, you may only want to apply one or a few new migrations, instead of all available migrations. You can do so by specifying the number of migrations that you want to apply when running the command. For example, the following command will try to apply the next three available migrations:" +msgstr "" + +#. type: Fenced code block #: ../src/guide/databases/db-migrations.md #, no-wrap -msgid "" -"db = 'db2';\n" -" parent::init();\n" -" }\n" -"}\n" +msgid "./yii migrate:up --limit=3\n" msgstr "" +#. type: Title ## +#: ../src/guide/databases/db-migrations.md +#, fuzzy, no-wrap +#| msgid "Resolving aliases " +msgid "Reverting Migrations " +msgstr "Me-resolve alias " + #. type: Plain text #: ../src/guide/databases/db-migrations.md -msgid "The above migration will be applied to `db2`, even if you specify a different database through the `db` command-line option. Note that the migration history will still be recorded in the database specified by the `db` command-line option." +msgid "To revert (undo) one or multiple migrations that have been applied before, you can run the following command:" msgstr "" -#. type: Plain text +#. type: Fenced code block #: ../src/guide/databases/db-migrations.md -msgid "If you have multiple migrations that use the same database, it is recommended that you create a base migration class with the above `init()` code. Then each migration class can extend from this base class." +#, no-wrap +msgid "" +"./yii migrate:down # revert the most recently applied migration\n" +"./yii migrate:down --limit=3 # revert the most 3 recently applied migrations\n" +"./yii migrate:down --all # revert all migrations\n" msgstr "" #. type: Plain text #: ../src/guide/databases/db-migrations.md #, no-wrap msgid "" -"> Tip: Besides setting the [[yii\\db\\Migration::db|db]] property, you can also operate on different databases\n" -"by creating new database connections to them in your migration classes. You then use the [DAO methods](db-dao.md)\n" -"with these connections to manipulate different databases.\n" +"> Note: Not all migrations are reversible. Trying to revert such migrations will cause an error and stop the\n" +"entire reverting process.\n" msgstr "" +#. type: Title ## +#: ../src/guide/databases/db-migrations.md +#, fuzzy, no-wrap +#| msgid "Resolving aliases " +msgid "Redoing Migrations " +msgstr "Me-resolve alias " + #. type: Plain text #: ../src/guide/databases/db-migrations.md -msgid "Another strategy that you can take to migrate multiple databases is to keep migrations for different databases in different migration paths. Then you can migrate these databases in separate commands like the following:" +msgid "Redoing migrations means first reverting the specified migrations and then applying again. This can be done as follows:" msgstr "" #. type: Fenced code block #: ../src/guide/databases/db-migrations.md #, no-wrap msgid "" -"yii migrate --migrationPath=@app/migrations/db1 --db=db1\n" -"yii migrate --migrationPath=@app/migrations/db2 --db=db2\n" -"...\n" +"./yii migrate:redo # redo the last applied migration\n" +"./yii migrate:redo --limit=3 # redo the last 3 applied migrations\n" +"./yii migrate:redo --all # redo all migrations\n" msgstr "" #. type: Plain text #: ../src/guide/databases/db-migrations.md -msgid "The first command will apply migrations in `@app/migrations/db1` to the `db1` database, the second command will apply migrations in `@app/migrations/db2` to `db2`, and so on." +#, no-wrap +msgid "> Note: If a migration is not reversible, you will not be able to redo it.\n" +msgstr "" + +#. type: Title ## +#: ../src/guide/databases/db-migrations.md +#, fuzzy, no-wrap +#| msgid "Using aliases in configuration " +msgid "Listing Migrations " +msgstr "Menggunakan aliases di konfigurasi " + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +msgid "To list which migrations have been applied and which are not, you may use the following commands:" +msgstr "" + +#. type: Fenced code block +#: ../src/guide/databases/db-migrations.md +#, no-wrap +msgid "" +"./yii migrate/history # showing the last 10 applied migrations\n" +"./yii migrate:history --limit=5 # showing the last 5 applied migrations\n" +"./yii migrate:history --all # showing all applied migrations\n" +"\n" +"./yii migrate:new # showing the first 10 new migrations\n" +"./yii migrate:new --limit=5 # showing the first 5 new migrations\n" +"./yii migrate:new --all # showing all new migrations\n" msgstr "" #. type: Title ### @@ -975,5 +893,10 @@ msgstr "" #. type: Plain text #: ../src/guide/databases/db-migrations.md -msgid "Migrations in Yii 2.0 and the [yiisoft/db-migration](https://github.com/yiisoft/db-migration/) package are not compatible, and the `migration` table is also not compatible. A probable solution is to use structure dumps and rename the old `migration` table. Upon the initial execution of migrations, a new `migration` table with new fields will be created. All further changes in the database schema are applied using the new `migration` component and recorded in the new migration table." +msgid "Migrations in Yii 2.0 and the [yiisoft/db-migration](https://github.com/yiisoft/db-migration/) package are not compatible, and the `migration` table is also not compatible." +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +msgid "A probable solution is to use structure dumps and rename the old `migration` table. Upon the initial execution of migrations, a new `migration` table with new fields will be created. All further changes in the database schema are applied using the new `migration` component and recorded in the new migration table." msgstr "" diff --git a/_translations/po/id/internals_010-code-style.md.po b/_translations/po/id/internals_010-code-style.md.po index e5879f64..983b9757 100644 --- a/_translations/po/id/internals_010-code-style.md.po +++ b/_translations/po/id/internals_010-code-style.md.po @@ -6,7 +6,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" -"POT-Creation-Date: 2025-12-24 08:02+0000\n" +"POT-Creation-Date: 2025-12-27 10:28+0000\n" "PO-Revision-Date: 2025-12-24 08:02+0000\n" "Last-Translator: Automatically generated\n" "Language-Team: none\n" @@ -15,117 +15,123 @@ msgstr "" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: 8bit\n" +#. type: Title ## +#: ../src/guide/databases/db-migrations.md ../src/internals/010-code-style.md +#, no-wrap +msgid "Strings" +msgstr "" + #. type: Title # -#: ../src/en/internals/010-code-style.md +#: ../src/internals/010-code-style.md #, no-wrap msgid "010 — Code style" msgstr "" #. type: Plain text -#: ../src/en/internals/010-code-style.md +#: ../src/internals/010-code-style.md msgid "Code formatting used in Yii 3 packages is based on [PSR-1](https://www.php-fig.org/psr/psr-1/) and [PSR-12](https://www.php-fig.org/psr/psr-12/) with extra rules added on top of it." msgstr "" #. type: Title ### -#: ../src/en/internals/010-code-style.md ../src/en/internals/017-tags.md -#: ../src/en/internals/018-widgets.md +#: ../src/internals/010-code-style.md ../src/internals/017-tags.md +#: ../src/internals/018-widgets.md #, no-wrap msgid "Names" msgstr "" #. type: Bullet: '- ' -#: ../src/en/internals/010-code-style.md +#: ../src/internals/010-code-style.md msgid "Use English only." msgstr "" #. type: Bullet: '- ' -#: ../src/en/internals/010-code-style.md +#: ../src/internals/010-code-style.md msgid "Use camelCase notation, including abbreviations (e.g., `enableIdn`)." msgstr "" #. type: Bullet: '- ' -#: ../src/en/internals/010-code-style.md +#: ../src/internals/010-code-style.md msgid "Use the shortest possible, but an explanatory name." msgstr "" #. type: Bullet: '- ' -#: ../src/en/internals/010-code-style.md +#: ../src/internals/010-code-style.md msgid "Never trim or abbreviate a name." msgstr "" #. type: Bullet: '- ' -#: ../src/en/internals/010-code-style.md +#: ../src/internals/010-code-style.md msgid "Postfix classes, interfaces, traits and variables, which is a [collection](https://en.wikipedia.org/wiki/Collection_(abstract_data_type)), with `Collection`." msgstr "" #. type: Title ## -#: ../src/en/internals/010-code-style.md +#: ../src/internals/010-code-style.md #, no-wrap msgid "Types" msgstr "" #. type: Bullet: '- ' -#: ../src/en/internals/010-code-style.md +#: ../src/internals/010-code-style.md msgid "Declare [argument and return types](https://www.php.net/manual/en/migration70.new-features.php) where possible." msgstr "" #. type: Bullet: '- ' -#: ../src/en/internals/010-code-style.md +#: ../src/internals/010-code-style.md msgid "[Use types for properties](https://wiki.php.net/rfc/typed_properties_v2)." msgstr "" #. type: Bullet: '- ' -#: ../src/en/internals/010-code-style.md +#: ../src/internals/010-code-style.md msgid "Use strict typing. Avoid mixed and union types where possible except compatible types such as `string|Stringable`." msgstr "" #. type: Title ## -#: ../src/en/internals/010-code-style.md +#: ../src/internals/010-code-style.md #, no-wrap msgid "Comments" msgstr "" #. type: Plain text -#: ../src/en/internals/010-code-style.md +#: ../src/internals/010-code-style.md msgid "Inline comments are to be avoided unless code couldn't be understood without them. A good example is a workaround for a bug in a certain PHP version." msgstr "" #. type: Plain text -#: ../src/en/internals/010-code-style.md +#: ../src/internals/010-code-style.md msgid "Method comment is necessary except it adds nothing to what method name and signature already has." msgstr "" #. type: Plain text -#: ../src/en/internals/010-code-style.md +#: ../src/internals/010-code-style.md msgid "Class comment should describe the purpose of the class." msgstr "" #. type: Plain text -#: ../src/en/internals/010-code-style.md +#: ../src/internals/010-code-style.md #, fuzzy #| msgid "[Validating input](https://github.com/yiisoft/validator/blob/master/docs/guide/en/README.md) +" msgid "[See PHPDoc](https://github.com/yiisoft/docs/blob/master/014-docs.md#phpdoc)." msgstr "[Memvalidasi Input](https://github.com/yiisoft/validator/blob/master/docs/guide/en/README.md) +" #. type: Title ## -#: ../src/en/internals/010-code-style.md +#: ../src/internals/010-code-style.md #, no-wrap msgid "Formatting" msgstr "" #. type: Title ### -#: ../src/en/internals/010-code-style.md +#: ../src/internals/010-code-style.md #, no-wrap msgid "No alignment" msgstr "" #. type: Plain text -#: ../src/en/internals/010-code-style.md +#: ../src/internals/010-code-style.md msgid "Property, variable and constant value assignments shouldn't be aligned. The same applies to phpdoc tags. The reason is that aligned statements often cause larger diff and even conflicts." msgstr "" #. type: Fenced code block (php) -#: ../src/en/internals/010-code-style.md +#: ../src/internals/010-code-style.md #, no-wrap msgid "" "final class X\n" @@ -149,18 +155,18 @@ msgid "" msgstr "" #. type: Title ### -#: ../src/en/internals/010-code-style.md +#: ../src/internals/010-code-style.md #, no-wrap msgid "Chain calls" msgstr "" #. type: Plain text -#: ../src/en/internals/010-code-style.md +#: ../src/internals/010-code-style.md msgid "Chained calls should be formatted for better readability. If it's a long chain that doesn't fit the line length of 120 characters, then each call should on a new line:" msgstr "" #. type: Fenced code block (php) -#: ../src/en/internals/010-code-style.md +#: ../src/internals/010-code-style.md #, no-wrap msgid "" "$object\n" @@ -172,145 +178,139 @@ msgid "" msgstr "" #. type: Plain text -#: ../src/en/internals/010-code-style.md +#: ../src/internals/010-code-style.md msgid "If it's a short chain, it's alright for it to be on a single line:" msgstr "" #. type: Fenced code block (php) -#: ../src/en/internals/010-code-style.md +#: ../src/internals/010-code-style.md #, no-wrap msgid "$object = $object->withName('test');\n" msgstr "" -#. type: Title ## -#: ../src/en/internals/010-code-style.md -#, no-wrap -msgid "Strings" -msgstr "" - #. type: Bullet: '- ' -#: ../src/en/internals/010-code-style.md +#: ../src/internals/010-code-style.md msgid "When no variables involved, use `'Hello!'`" msgstr "" #. type: Bullet: '- ' -#: ../src/en/internals/010-code-style.md +#: ../src/internals/010-code-style.md msgid "To get variables into string prefer `\"Hello, $username!\"`" msgstr "" #. type: Title ## -#: ../src/en/internals/010-code-style.md +#: ../src/internals/010-code-style.md #, no-wrap msgid "Classes and interfaces" msgstr "" #. type: Title ### -#: ../src/en/internals/010-code-style.md +#: ../src/internals/010-code-style.md #, no-wrap msgid "Final by default" msgstr "" #. type: Plain text -#: ../src/en/internals/010-code-style.md +#: ../src/internals/010-code-style.md msgid "Classes should be `final` by default." msgstr "" #. type: Title ### -#: ../src/en/internals/010-code-style.md +#: ../src/internals/010-code-style.md #, no-wrap msgid "Private by default" msgstr "" #. type: Plain text -#: ../src/en/internals/010-code-style.md +#: ../src/internals/010-code-style.md msgid "Constants, properties and methods should be private by default." msgstr "" #. type: Title ### -#: ../src/en/internals/010-code-style.md +#: ../src/internals/010-code-style.md #, no-wrap msgid "Composition over inheritance" msgstr "" #. type: Plain text -#: ../src/en/internals/010-code-style.md +#: ../src/internals/010-code-style.md #, fuzzy #| msgid "[Dependency injection container](concept/di-container.md) +" msgid "Prefer [composition to inheritance](guide/en/concept/di-container.md)." msgstr "[Dependency Injection Container](concept/di-container.md) +" #. type: Title ### -#: ../src/en/internals/010-code-style.md +#: ../src/internals/010-code-style.md #, no-wrap msgid "Property, constant and method order" msgstr "" #. type: Plain text -#: ../src/en/internals/010-code-style.md +#: ../src/internals/010-code-style.md msgid "Order should be the following:" msgstr "" #. type: Bullet: '- ' -#: ../src/en/internals/010-code-style.md +#: ../src/internals/010-code-style.md msgid "Constants" msgstr "" #. type: Bullet: '- ' -#: ../src/en/internals/010-code-style.md +#: ../src/internals/010-code-style.md msgid "Properties" msgstr "" #. type: Title ## -#: ../src/en/internals/010-code-style.md ../src/en/internals/017-tags.md -#: ../src/en/internals/018-widgets.md +#: ../src/internals/010-code-style.md ../src/internals/017-tags.md +#: ../src/internals/018-widgets.md #, no-wrap msgid "Methods" msgstr "" #. type: Plain text -#: ../src/en/internals/010-code-style.md +#: ../src/internals/010-code-style.md msgid "Within each category, items should be sorted by visibility:" msgstr "" #. type: Bullet: '- ' -#: ../src/en/internals/010-code-style.md +#: ../src/internals/010-code-style.md msgid "public" msgstr "" #. type: Bullet: '- ' -#: ../src/en/internals/010-code-style.md +#: ../src/internals/010-code-style.md msgid "protected" msgstr "" #. type: Bullet: '- ' -#: ../src/en/internals/010-code-style.md +#: ../src/internals/010-code-style.md msgid "private" msgstr "" #. type: Title ### -#: ../src/en/internals/010-code-style.md +#: ../src/internals/010-code-style.md #, no-wrap msgid "Abstract classes" msgstr "" #. type: Plain text -#: ../src/en/internals/010-code-style.md +#: ../src/internals/010-code-style.md msgid "Abstract classes *shouldn't* be prefixed or postfixed with `Abstract`." msgstr "" #. type: Title #### -#: ../src/en/internals/010-code-style.md +#: ../src/internals/010-code-style.md #, no-wrap msgid "Immutable methods" msgstr "" #. type: Plain text -#: ../src/en/internals/010-code-style.md +#: ../src/internals/010-code-style.md msgid "Immutable method convention is the following:" msgstr "" #. type: Fenced code block (php) -#: ../src/en/internals/010-code-style.md +#: ../src/internals/010-code-style.md #, no-wrap msgid "" "public function withName(string $name): self\n" @@ -322,28 +322,28 @@ msgid "" msgstr "" #. type: Bullet: '1. ' -#: ../src/en/internals/010-code-style.md +#: ../src/internals/010-code-style.md msgid "Cloned object name is `$new`." msgstr "" #. type: Bullet: '2. ' -#: ../src/en/internals/010-code-style.md +#: ../src/internals/010-code-style.md msgid "Return type is `self`." msgstr "" #. type: Title #### -#: ../src/en/internals/010-code-style.md +#: ../src/internals/010-code-style.md #, no-wrap msgid "Boolean check methods" msgstr "" #. type: Plain text -#: ../src/en/internals/010-code-style.md +#: ../src/internals/010-code-style.md msgid "Methods that are there to check if something is true should be named like the following:" msgstr "" #. type: Fenced code block (php) -#: ../src/en/internals/010-code-style.md +#: ../src/internals/010-code-style.md #, no-wrap msgid "" "public function isDeleted(): bool;\n" @@ -352,29 +352,29 @@ msgid "" msgstr "" #. type: Title #### -#: ../src/en/internals/010-code-style.md +#: ../src/internals/010-code-style.md #, no-wrap msgid "Flags in methods " msgstr "" #. type: Plain text -#: ../src/en/internals/010-code-style.md +#: ../src/internals/010-code-style.md msgid "Boolean flags in methods are better to be avoided. It's a sign the method may be doing too much, and there should be two methods instead of one." msgstr "" #. type: Fenced code block (php) -#: ../src/en/internals/010-code-style.md +#: ../src/internals/010-code-style.md #, no-wrap msgid "public function login(bool $refreshPage = true): void;\n" msgstr "" #. type: Plain text -#: ../src/en/internals/010-code-style.md +#: ../src/internals/010-code-style.md msgid "It is better to be two methods:" msgstr "" #. type: Fenced code block (php) -#: ../src/en/internals/010-code-style.md +#: ../src/internals/010-code-style.md #, no-wrap msgid "" "public function login(): void;\n" @@ -382,18 +382,18 @@ msgid "" msgstr "" #. type: Title ## -#: ../src/en/internals/010-code-style.md +#: ../src/internals/010-code-style.md #, no-wrap msgid "Variables" msgstr "" #. type: Plain text -#: ../src/en/internals/010-code-style.md +#: ../src/internals/010-code-style.md msgid "Add an underscore (`_`) prefix for unused variables. For example:" msgstr "" #. type: Fenced code block (php) -#: ../src/en/internals/010-code-style.md +#: ../src/internals/010-code-style.md #, no-wrap msgid "" "foreach ($items as $key => $_value) {\n" @@ -402,18 +402,18 @@ msgid "" msgstr "" #. type: Title ## -#: ../src/en/internals/010-code-style.md +#: ../src/internals/010-code-style.md #, no-wrap msgid "Imports" msgstr "" #. type: Plain text -#: ../src/en/internals/010-code-style.md +#: ../src/internals/010-code-style.md msgid "Prefer importing classes and functions to using fully qualified names:" msgstr "" #. type: Fenced code block (php) -#: ../src/en/internals/010-code-style.md +#: ../src/internals/010-code-style.md #, no-wrap msgid "" "use Yiisoft\\Arrays\\ArrayHelper;\n" @@ -425,24 +425,24 @@ msgid "" msgstr "" #. type: Title ## -#: ../src/en/internals/010-code-style.md +#: ../src/internals/010-code-style.md #, no-wrap msgid "Additional conventions" msgstr "" #. type: Bullet: '- ' -#: ../src/en/internals/010-code-style.md +#: ../src/internals/010-code-style.md msgid "[Namespaces](004-namespaces.md)" msgstr "" #. type: Bullet: '- ' -#: ../src/en/internals/010-code-style.md +#: ../src/internals/010-code-style.md #, fuzzy #| msgid "[Actions](structure/action.md) +" msgid "[Exceptions](007-exceptions.md)" msgstr "[Actions](structure/action.md) +" #. type: Bullet: '- ' -#: ../src/en/internals/010-code-style.md +#: ../src/internals/010-code-style.md msgid "[Interfaces](008-interfaces.md)" msgstr "" diff --git a/_translations/po/ru/guide_databases_db-migrations.md.po b/_translations/po/ru/guide_databases_db-migrations.md.po index 4f785d49..81290951 100644 --- a/_translations/po/ru/guide_databases_db-migrations.md.po +++ b/_translations/po/ru/guide_databases_db-migrations.md.po @@ -6,7 +6,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" -"POT-Creation-Date: 2025-12-27 08:43+0000\n" +"POT-Creation-Date: 2025-12-27 10:28+0000\n" "PO-Revision-Date: 2025-09-04 11:19+0500\n" "Last-Translator: Automatically generated\n" "Language-Team: none\n" @@ -172,12 +172,17 @@ msgid "" "],\n" msgstr "" +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +msgid "If you want to place migrations elsewhere, you can define the path in `newMigrationPath`. If your migrations to be applied are from multiple sources, such as external modules, `sourcePaths` could be used to define these." +msgstr "" + #. type: Plain text #: ../src/guide/databases/db-migrations.md msgid "You need a database connection configured as well. See [Working with databases](../start/databases.md) for an example of configuring it for PostgreSQL." msgstr "" -#. type: Title ### +#. type: Title ## #: ../src/guide/databases/db-migrations.md #, no-wrap msgid "Creating a migration" @@ -193,7 +198,9 @@ msgstr "Для установки пакетов выполните в конс #. type: Fenced code block (sh) #: ../src/guide/databases/db-migrations.md #, no-wrap -msgid "make yii migrate:create \n" +msgid "" +"make shell\n" +"./yii migrate:create \n" msgstr "" #. type: Plain text @@ -204,7 +211,9 @@ msgstr "" #. type: Fenced code block #: ../src/guide/databases/db-migrations.md #, no-wrap -msgid "make yii migrate:create create_news_table\n" +msgid "" +"make shell\n" +"./yii migrate:create create_news_table\n" msgstr "" #. type: Plain text @@ -288,695 +297,604 @@ msgstr "" #. type: Plain text #: ../src/guide/databases/db-migrations.md -#, no-wrap -msgid "" -"TODO: explain $b and $qb\n" -"Below is the list of all these database accessing methods:\n" -msgstr "" - -#. type: Title ### -#: ../src/guide/databases/db-migrations.md -#, no-wrap -msgid "Irreversible migrations" +msgid "Migration builder `$b` in the above manages database schema while the column builder `$cb` manages column types. Both allow using *abstract types*. When a migration is applied to a particular database, the abstract types will be translated into the corresponding database physical types and corresponding SQL to define them." msgstr "" #. type: Plain text #: ../src/guide/databases/db-migrations.md -msgid "Not all migrations are reversible. For example, if the `up()` method deletes a row of a table, you may not be able to recover this row in the `down()` method. Sometimes, you may be just too lazy to implement the `down()`, because it is not very common to revert database migrations. In this case, you should implement `Yiisoft\\Db\\Migration\\MigrationInterface` that has `up()` only." +msgid "Methods available in migration builder belong to the following types:" msgstr "" -#. type: Title ### +#. type: Bullet: '- ' #: ../src/guide/databases/db-migrations.md -#, no-wrap -msgid "Transactional migrations (TODO: update!!!)" +msgid "Raw queries" msgstr "" -#. type: Plain text +#. type: Bullet: ' - ' #: ../src/guide/databases/db-migrations.md -msgid "While performing complex DB migrations, it is important to ensure each migration to either succeed or fail as a whole so that the database can maintain integrity and consistency. To achieve this goal, it is recommended that you enclose the DB operations of each migration in a [transaction](db-dao.md#performing-transactions)." +msgid "getDb — to get database connection instance." msgstr "" -#. type: Plain text +#. type: Bullet: ' - ' #: ../src/guide/databases/db-migrations.md -msgid "An even easier way of implementing transactional migrations is to put migration code in the `safeUp()` and `safeDown()` methods. These two methods differ from `up()` and `down()` in that they are enclosed implicitly in a transaction. As a result, if any operation in these methods fails, all prior operations will be rolled back automatically." +msgid "execute — to execute raw SQL query." msgstr "" -#. type: Plain text +#. type: Bullet: '- ' #: ../src/guide/databases/db-migrations.md -msgid "In the following example, besides creating the `news` table we also insert an initial row into this table." +msgid "Data" msgstr "" -#. type: Fenced code block (php) +#. type: Bullet: ' - ' #: ../src/guide/databases/db-migrations.md -#, no-wrap -msgid "" -"createTable('news', [\n" -" 'id' => $this->primaryKey(),\n" -" 'title' => $this->string()->notNull(),\n" -" 'content' => $this->text(),\n" -" ]);\n" -"\n" -" $this->insert('news', [\n" -" 'title' => 'test 1',\n" -" 'content' => 'content 1',\n" -" ]);\n" -" }\n" -"\n" -" public function safeDown()\n" -" {\n" -" $this->delete('news', ['id' => 1]);\n" -" $this->dropTable('news');\n" -" }\n" -"}\n" +msgid "insert / update / delete" msgstr "" -#. type: Plain text +#. type: Bullet: ' - ' #: ../src/guide/databases/db-migrations.md -msgid "Note that usually when you perform multiple DB operations in `safeUp()`, you should reverse their execution order in `safeDown()`. In the above example we first create the table and then insert a row in `safeUp()`; while in `safeDown()` we first delete the row and then drop the table." +msgid "batchInsert" msgstr "" -#. type: Plain text +#. type: Bullet: ' - ' #: ../src/guide/databases/db-migrations.md -#, no-wrap -msgid "" -"> Note: Not all DBMS support transactions. And some DB queries cannot be put into a transaction. For some examples,\n" -"please refer to [implicit commit](https://dev.mysql.com/doc/refman/5.7/en/implicit-commit.html). If this is the case,\n" -"you should still implement `up()` and `down()`, instead.\n" +msgid "upsert" msgstr "" -#. type: Plain text +#. type: Bullet: '- ' #: ../src/guide/databases/db-migrations.md -#, no-wrap -msgid "TODO: TransactionalMigrationInterface\n" +msgid "Tables and views" msgstr "" -#. type: Title ## +#. type: Bullet: ' - ' #: ../src/guide/databases/db-migrations.md -#, no-wrap -msgid "TODO: update" +msgid "createTable / renameTable / dropTable" msgstr "" -#. type: Plain text +#. type: Bullet: ' - ' #: ../src/guide/databases/db-migrations.md -msgid "The base migration class [[yii\\db\\Migration]] exposes a database connection via the [[yii\\db\\Migration::db|db]] property. You can use it to manipulate the database schema using the methods as described in [Working with Database Schema](db-dao.md#database-schema)." +msgid "truncateTable" msgstr "" -#. type: Plain text +#. type: Bullet: ' - ' #: ../src/guide/databases/db-migrations.md -#, no-wrap -msgid "" -"Rather than using physical types, when creating a table or column you should use *abstract types*\n" -"so that your migrations are independent of specific DBMS. The [[yii\\db\\Schema]] class defines\n" -"a set of constants to represent the supported abstract types. These constants are named in the format\n" -"of `TYPE_`. For example, `TYPE_PK` refers to auto-incremental primary key type; `TYPE_STRING`\n" -"refers to a string type. When a migration is applied to a particular database, the abstract types\n" -"will be translated into the corresponding physical types. In the case of MySQL, `TYPE_PK` will be turned\n" -"into `int(11) NOT NULL AUTO_INCREMENT PRIMARY KEY`, while `TYPE_STRING` becomes `varchar(255)`.\n" +msgid "addCommentOnTable / dropCommentFromTable" msgstr "" -#. type: Plain text +#. type: Bullet: ' - ' #: ../src/guide/databases/db-migrations.md -msgid "You can append additional constraints when using abstract types. In the above example, ` NOT NULL` is appended to `Schema::TYPE_STRING` to specify that the column cannot be `null`." +msgid "createView / dropView" msgstr "" -#. type: Plain text +#. type: Bullet: '- ' #: ../src/guide/databases/db-migrations.md -#, no-wrap -msgid "" -"> Info: The mapping between abstract types and physical types is specified by\n" -"the [[yii\\db\\QueryBuilder::$typeMap|$typeMap]] property in each concrete `QueryBuilder` class.\n" +msgid "Columns" msgstr "" -#. type: Plain text +#. type: Bullet: ' - ' #: ../src/guide/databases/db-migrations.md -msgid "Since version 2.0.6, you can make use of the newly introduced schema builder which provides more convenient way of defining column schema. So the migration above could be written like the following:" +msgid "addColumn / renameColumn / alterColumn / dropColumn" msgstr "" -#. type: Fenced code block (php) +#. type: Bullet: ' - ' #: ../src/guide/databases/db-migrations.md -#, no-wrap -msgid "" -"createTable('news', [\n" -" 'id' => $this->primaryKey(),\n" -" 'title' => $this->string()->notNull(),\n" -" 'content' => $this->text(),\n" -" ]);\n" -" }\n" -"\n" -" public function down()\n" -" {\n" -" $this->dropTable('news');\n" -" }\n" -"}\n" +msgid "addCommentOnColumn / dropCommentFromColumn" msgstr "" -#. type: Plain text +#. type: Bullet: '- ' #: ../src/guide/databases/db-migrations.md -msgid "A list of all available methods for defining the column types is available in the API documentation of [[yii\\db\\SchemaBuilderTrait]]." +msgid "Keys and indexes" msgstr "" -#. type: Plain text +#. type: Bullet: ' - ' #: ../src/guide/databases/db-migrations.md -#, no-wrap -msgid "" -"> Info: The generated file permissions and ownership will be determined by the current environment. This might lead to\n" -"inaccessible files. This could, for example, happen when the migration is created within a docker container\n" -"and the files are edited on the host. In this case the `newFileMode` and/or `newFileOwnership` of the MigrateController\n" -"can be changed. E.g. in the application config:\n" +msgid "addPrimaryKey / dropPrimaryKey" msgstr "" -#. type: Fenced code block (php) +#. type: Bullet: ' - ' #: ../src/guide/databases/db-migrations.md -#, no-wrap -msgid "" -" [\n" -" 'migrate' => [\n" -" 'class' => 'yii\\console\\controllers\\MigrateController',\n" -" 'newFileOwnership' => '1000:1000', # Default WSL user id\n" -" 'newFileMode' => 0660,\n" -" ],\n" -" ],\n" -" ];\n" +msgid "addForeignKey / dropForeignKey" msgstr "" -#. type: Title ## +#. type: Bullet: ' - ' #: ../src/guide/databases/db-migrations.md -#, no-wrap -msgid "Generating Migrations (TODO: likely is OK but...)" +msgid "createIndex / dropIndex" msgstr "" #. type: Plain text #: ../src/guide/databases/db-migrations.md -msgid "The command provides a convenient way to create migrations using the provided [view](https://github.com/yiisoft/db-migration/tree/master/resources/views):" +msgid "Additionally, there's a `columnBuilder()` which is used to obtain a column builder as in example above. The builder has static methods that define various column types:" msgstr "" -#. type: Fenced code block (shell) +#. type: Bullet: '- ' #: ../src/guide/databases/db-migrations.md -#, no-wrap -msgid "make yii migrate:create my_first_table --command=table --fields=name,example --table-comment=my_first_table\n" +msgid "Keys" msgstr "" -#. type: Plain text +#. type: Bullet: ' - ' #: ../src/guide/databases/db-migrations.md -#, fuzzy -#| msgid "That's equal to the following:" -msgid "That would generate the following:" -msgstr "Это соответствует:" +msgid "primaryKey" +msgstr "" -#. type: Fenced code block (php) +#. type: Bullet: ' - ' #: ../src/guide/databases/db-migrations.md -#, no-wrap -msgid "" -"createTable('my_first_table', [\n" -" 'id' => $b->primaryKey(),\n" -" 'name',\n" -" 'example',\n" -" ]);\n" -" \n" -" $b->addCommentOnTable('my_first_table', 'dest');\n" -" }\n" -"\n" -" public function down(MigrationBuilder $b): void\n" -" {\n" -" $b->dropTable('my_first_table');\n" -" }\n" -"}\n" +msgid "smallPrimaryKey" msgstr "" -#. type: Plain text +#. type: Bullet: ' - ' #: ../src/guide/databases/db-migrations.md -msgid "For more information [see](https://github.com/yiisoft/db-migration/tree/master/docs/guide/en)" +msgid "bigPrimaryKey" msgstr "" -#. type: Title ## +#. type: Bullet: ' - ' #: ../src/guide/databases/db-migrations.md -#, fuzzy, no-wrap -#| msgid "Configuration" -msgid "Applying Migrations" -msgstr "Настройка" +msgid "uuidPrimaryKey" +msgstr "" -#. type: Plain text +#. type: Bullet: '- ' #: ../src/guide/databases/db-migrations.md -msgid "To upgrade a database to its latest structure, you should apply all available new migrations using the following command:" +msgid "Boolean" msgstr "" -#. type: Fenced code block +#. type: Bullet: ' - ' #: ../src/guide/databases/db-migrations.md -#, no-wrap -msgid "yii migrate\n" +msgid "boolean" msgstr "" -#. type: Plain text +#. type: Bullet: '- ' #: ../src/guide/databases/db-migrations.md -msgid "This command will list all migrations that have not been applied so far. If you confirm that you want to apply these migrations, it will run the `up()` or `safeUp()` method in every new migration class, one after another, in the order of their timestamp values. If any of the migrations fails, the command will quit without applying the rest of the migrations." +msgid "Numbers" msgstr "" -#. type: Plain text +#. type: Bullet: ' - ' #: ../src/guide/databases/db-migrations.md -#, no-wrap -msgid "" -"> Tip: In case you don't have command line at your server you may try [web shell](https://github.com/samdark/yii2-webshell)\n" -"> extension.\n" +msgid "bit" msgstr "" -#. type: Plain text +#. type: Bullet: ' - ' #: ../src/guide/databases/db-migrations.md -msgid "For each migration that has been successfully applied, the command will insert a row into a database table named `migration` to record the successful application of the migration. This will allow the migration tool to identify which migrations have been applied and which have not." +msgid "tinyint" msgstr "" -#. type: Plain text +#. type: Bullet: ' - ' #: ../src/guide/databases/db-migrations.md -#, no-wrap -msgid "" -"> Info: The migration tool will automatically create the `migration` table in the database specified by\n" -"the [[yii\\console\\controllers\\MigrateController::db|db]] option of the command. By default, the database\n" -"is specified by the `db` [application component](structure-application-components.md).\n" +msgid "smallint" msgstr "" -#. type: Plain text +#. type: Bullet: ' - ' #: ../src/guide/databases/db-migrations.md -msgid "Sometimes, you may only want to apply one or a few new migrations, instead of all available migrations. You can do so by specifying the number of migrations that you want to apply when running the command. For example, the following command will try to apply the next three available migrations:" +msgid "integer" msgstr "" -#. type: Fenced code block +#. type: Bullet: ' - ' #: ../src/guide/databases/db-migrations.md -#, no-wrap -msgid "yii migrate 3\n" +msgid "bigint" msgstr "" -#. type: Plain text +#. type: Bullet: ' - ' #: ../src/guide/databases/db-migrations.md -msgid "You can also explicitly specify a particular migration to which the database should be migrated by using the `migrate/to` command in one of the following formats:" +msgid "flat" msgstr "" -#. type: Fenced code block +#. type: Bullet: ' - ' #: ../src/guide/databases/db-migrations.md -#, no-wrap -msgid "" -"yii migrate/to 150101_185401 # using timestamp to specify the migration\n" -"yii migrate/to \"2015-01-01 18:54:01\" # using a string that can be parsed by strtotime()\n" -"yii migrate/to m150101_185401_create_news_table # using full name\n" -"yii migrate/to 1392853618 # using UNIX timestamp\n" +msgid "double" msgstr "" -#. type: Plain text +#. type: Bullet: ' - ' #: ../src/guide/databases/db-migrations.md -msgid "If there are any unapplied migrations earlier than the specified one, they will all be applied before the specified migration is applied." +msgid "decimal" msgstr "" -#. type: Plain text +#. type: Title ## +#: ../src/guide/databases/db-migrations.md ../src/internals/010-code-style.md +#, no-wrap +msgid "Strings" +msgstr "" + +#. type: Bullet: ' - ' #: ../src/guide/databases/db-migrations.md -msgid "If the specified migration has already been applied before, any later applied migrations will be reverted." +msgid "char" msgstr "" -#. type: Title ## +#. type: Bullet: ' - ' #: ../src/guide/databases/db-migrations.md -#, fuzzy, no-wrap -#| msgid "Defining aliases " -msgid "Reverting Migrations " -msgstr "Определение псевдонимов " +msgid "string" +msgstr "" -#. type: Plain text +#. type: Bullet: ' - ' #: ../src/guide/databases/db-migrations.md -msgid "To revert (undo) one or multiple migrations that have been applied before, you can run the following command:" +msgid "text" msgstr "" -#. type: Fenced code block +#. type: Bullet: '- ' #: ../src/guide/databases/db-migrations.md -#, no-wrap -msgid "" -"yii migrate/down # revert the most recently applied migration\n" -"yii migrate/down 3 # revert the most 3 recently applied migrations\n" +msgid "Date and time" msgstr "" -#. type: Plain text +#. type: Bullet: ' - ' #: ../src/guide/databases/db-migrations.md -#, no-wrap -msgid "" -"> Note: Not all migrations are reversible. Trying to revert such migrations will cause an error and stop the\n" -"entire reverting process.\n" +msgid "timestamp" msgstr "" -#. type: Title ## +#. type: Bullet: ' - ' #: ../src/guide/databases/db-migrations.md -#, fuzzy, no-wrap -#| msgid "Resolving aliases " -msgid "Redoing Migrations " -msgstr "Разрешение псевдонимов " +msgid "datetime" +msgstr "" -#. type: Plain text +#. type: Bullet: ' - ' #: ../src/guide/databases/db-migrations.md -msgid "Redoing migrations means first reverting the specified migrations and then applying again. This can be done as follows:" +msgid "datetimeWithTimezone" msgstr "" -#. type: Fenced code block +#. type: Bullet: ' - ' #: ../src/guide/databases/db-migrations.md -#, no-wrap -msgid "" -"yii migrate/redo # redo the last applied migration\n" -"yii migrate/redo 3 # redo the last 3 applied migrations\n" +msgid "time" msgstr "" -#. type: Plain text +#. type: Bullet: ' - ' #: ../src/guide/databases/db-migrations.md -#, no-wrap -msgid "> Note: If a migration is not reversible, you will not be able to redo it.\n" +msgid "timeWithTimezone" msgstr "" -#. type: Title ## +#. type: Bullet: ' - ' #: ../src/guide/databases/db-migrations.md -#, fuzzy, no-wrap -#| msgid "Resolving aliases " -msgid "Refreshing Migrations " -msgstr "Разрешение псевдонимов " +msgid "date" +msgstr "" -#. type: Plain text +#. type: Bullet: '- ' #: ../src/guide/databases/db-migrations.md -msgid "Since Yii 2.0.13 you can delete all tables and foreign keys from the database and apply all migrations from the beginning." +msgid "Special types" msgstr "" -#. type: Fenced code block +#. type: Bullet: ' - ' #: ../src/guide/databases/db-migrations.md -#, no-wrap -msgid "yii migrate/fresh # truncate the database and apply all migrations from the beginning\n" +msgid "money" msgstr "" -#. type: Title ## +#. type: Bullet: ' - ' #: ../src/guide/databases/db-migrations.md -#, fuzzy, no-wrap -#| msgid "Resolving aliases " -msgid "Listing Migrations " -msgstr "Разрешение псевдонимов " +msgid "binary" +msgstr "" -#. type: Plain text +#. type: Bullet: ' - ' #: ../src/guide/databases/db-migrations.md -msgid "To list which migrations have been applied and which are not, you may use the following commands:" +msgid "uuid" msgstr "" -#. type: Fenced code block +#. type: Bullet: ' - ' #: ../src/guide/databases/db-migrations.md -#, no-wrap -msgid "" -"yii migrate/history # showing the last 10 applied migrations\n" -"yii migrate/history 5 # showing the last 5 applied migrations\n" -"yii migrate/history all # showing all applied migrations\n" -"\n" -"yii migrate/new # showing the first 10 new migrations\n" -"yii migrate/new 5 # showing the first 5 new migrations\n" -"yii migrate/new all # showing all new migrations\n" +msgid "array" msgstr "" -#. type: Title ## +#. type: Bullet: ' - ' #: ../src/guide/databases/db-migrations.md -#, fuzzy, no-wrap -#| msgid "Resolving aliases " -msgid "Modifying Migration History " -msgstr "Разрешение псевдонимов " +msgid "structured" +msgstr "" -#. type: Plain text +#. type: Bullet: ' - ' #: ../src/guide/databases/db-migrations.md -msgid "Instead of actually applying or reverting migrations, sometimes you may simply want to mark that your database has been upgraded to a particular migration. This often happens when you manually change the database to a particular state and you do not want the migration(s) for that change to be re-applied later. You can achieve this goal with the following command:" +msgid "json" msgstr "" -#. type: Fenced code block +#. type: Bullet: '- ' #: ../src/guide/databases/db-migrations.md -#, no-wrap -msgid "" -"yii migrate/mark 150101_185401 # using timestamp to specify the migration\n" -"yii migrate/mark \"2015-01-01 18:54:01\" # using a string that can be parsed by strtotime()\n" -"yii migrate/mark m150101_185401_create_news_table # using full name\n" -"yii migrate/mark 1392853618 # using UNIX timestamp\n" +msgid "enum" msgstr "" #. type: Plain text #: ../src/guide/databases/db-migrations.md -msgid "The command will modify the `migration` table by adding or deleting certain rows to indicate that the database has been applied migrations to the specified one. No migrations will be applied or reverted by this command." +msgid "All the above methods create a base type which could be adjusted with additional methods:" msgstr "" -#. type: Title ## +#. type: Bullet: '- ' #: ../src/guide/databases/db-migrations.md -#, fuzzy, no-wrap -#| msgid "Resolving aliases " -msgid "Customizing Migrations " -msgstr "Разрешение псевдонимов " +msgid "null / notNull" +msgstr "" -#. type: Plain text +#. type: Bullet: '- ' #: ../src/guide/databases/db-migrations.md -msgid "There are several ways to customize the migration command." +msgid "defaultValue" msgstr "" -#. type: Title ### +#. type: Bullet: '- ' #: ../src/guide/databases/db-migrations.md -#, fuzzy, no-wrap -#| msgid "Resolving aliases " -msgid "Using Command Line Options " -msgstr "Разрешение псевдонимов " +msgid "unique" +msgstr "" -#. type: Plain text +#. type: Bullet: '- ' #: ../src/guide/databases/db-migrations.md -msgid "The migration command comes with a few command-line options that can be used to customize its behaviors:" +msgid "scale / size / unsigned" msgstr "" -#. type: Bullet: '* ' +#. type: Bullet: '- ' #: ../src/guide/databases/db-migrations.md -msgid "`interactive`: boolean (defaults to `true`), specifies whether to perform migrations in an interactive mode. When this is `true`, the user will be prompted before the command performs certain actions. You may want to set this to `false` if the command is being used in a background process." +msgid "primaryKey / autoIncrement" msgstr "" -#. type: Bullet: '* ' +#. type: Bullet: '- ' #: ../src/guide/databases/db-migrations.md -msgid "`migrationPath`: string|array (defaults to `@app/migrations`), specifies the directory storing all migration class files. This can be specified as either a directory path or a path [alias](concept-aliases.md). Note that the directory must exist, or the command may trigger an error. Since version 2.0.12 an array can be specified for loading migrations from multiple sources." +msgid "check" msgstr "" -#. type: Bullet: '* ' +#. type: Bullet: '- ' #: ../src/guide/databases/db-migrations.md -msgid "`migrationTable`: string (defaults to `migration`), specifies the name of the database table for storing migration history information. The table will be automatically created by the command if it does not exist. You may also manually create it using the structure `version varchar(255) primary key, apply_time integer`." +msgid "comment" msgstr "" -#. type: Bullet: '* ' +#. type: Bullet: '- ' #: ../src/guide/databases/db-migrations.md -msgid "`db`: string (defaults to `db`), specifies the ID of the database [application component](structure-application-components.md). It represents the database that will be migrated using this command." +msgid "computed" msgstr "" -#. type: Bullet: '* ' +#. type: Bullet: '- ' #: ../src/guide/databases/db-migrations.md -msgid "`templateFile`: string (defaults to `@yii/views/migration.php`), specifies the path of the template file that is used for generating skeleton migration class files. This can be specified as either a file path or a path [alias](concept-aliases.md). The template file is a PHP script in which you can use a predefined variable named `$className` to get the migration class name." +msgid "extra" msgstr "" -#. type: Plain text +#. type: Bullet: '- ' +#: ../src/guide/databases/db-migrations.md +#, fuzzy +#| msgid "References" +msgid "reference" +msgstr "Ссылки" + +#. type: Title ### #: ../src/guide/databases/db-migrations.md #, no-wrap -msgid "" -"* `generatorTemplateFiles`: array (defaults to `[\n" -" 'create_table' => '@yii/views/createTableMigration.php',\n" -" 'drop_table' => '@yii/views/dropTableMigration.php',\n" -" 'add_column' => '@yii/views/addColumnMigration.php',\n" -" 'drop_column' => '@yii/views/dropColumnMigration.php',\n" -" 'create_junction' => '@yii/views/createTableMigration.php'\n" -" ]`), specifies template files for generating migration code. See \"[Generating Migrations](#generating-migrations)\"\n" -" for more details.\n" +msgid "Irreversible migrations" msgstr "" -#. type: Bullet: '* ' +#. type: Plain text #: ../src/guide/databases/db-migrations.md -msgid "`fields`: array of column definition strings used for creating migration code. Defaults to `[]`. The format of each definition is `COLUMN_NAME:COLUMN_TYPE:COLUMN_DECORATOR`. For example, `--fields=name:string(12):notNull` produces a string column of size 12 which is not `null`." +msgid "Not all migrations are reversible. For example, if the `up()` method deletes a row of a table, you may not be able to recover this row in the `down()` method. Sometimes, you may be just too lazy to implement the `down()`, because it is not very common to revert database migrations. In this case, you should implement `Yiisoft\\Db\\Migration\\MigrationInterface` that has `up()` only." msgstr "" +#. type: Title ### +#: ../src/guide/databases/db-migrations.md +#, fuzzy, no-wrap +#| msgid "Sentry integration" +msgid "Transactional migrations" +msgstr "Интеграция с Sentry" + #. type: Plain text #: ../src/guide/databases/db-migrations.md -msgid "The following example shows how you can use these options." +msgid "While performing complex DB migrations, it is important to ensure each migration to either succeed or fail as a whole so that the database can maintain integrity and consistency. To achieve this goal, it is recommended that you may enclose the DB operations of each migration in a transaction automatically by adding `TransactionalMigrationInterface` to `implements` of your migration." msgstr "" #. type: Plain text #: ../src/guide/databases/db-migrations.md -msgid "For example, if we want to migrate a `forum` module whose migration files are located within the module's `migrations` directory, we can use the following command:" +msgid "As a result, if any operation in the `up()` or `down()` method fails, all prior operations will be rolled back automatically." msgstr "" -#. type: Fenced code block +#. type: Plain text #: ../src/guide/databases/db-migrations.md #, no-wrap msgid "" -"# migrate the migrations in a forum module non-interactively\n" -"yii migrate --migrationPath=@app/modules/forum/migrations --interactive=0\n" +"> Note: Not all DBMS support transactions. And some DB queries cannot be put into a transaction. For some examples,\n" +"please refer to [implicit commit](https://dev.mysql.com/doc/refman/5.7/en/implicit-commit.html).\n" msgstr "" -#. type: Title ### +#. type: Title ## #: ../src/guide/databases/db-migrations.md #, fuzzy, no-wrap -#| msgid "Sentry integration" -msgid "Separated Migrations" -msgstr "Интеграция с Sentry" +#| msgid "Practice-orientation." +msgid "Generating a migration" +msgstr "Практикоориентированность." #. type: Plain text #: ../src/guide/databases/db-migrations.md -msgid "Sometimes using single migration history for all project migrations is not desirable. For example: you may install some 'blog' extension, which contains fully separated functionality and contain its own migrations, which should not affect the ones dedicated to main project functionality." +msgid "Instead of writing migrations by hand, the command provides a convenient way generate some of the code." msgstr "" -#. type: Plain text +#. type: Fenced code block (shell) #: ../src/guide/databases/db-migrations.md -msgid "If you want several migrations to be applied and tracked down completely separated from each other, you can configure multiple migration commands which will use different namespaces and migration history tables:" +#, no-wrap +msgid "" +"make shell\n" +"./yii migrate:create -- my_first_table --command=table --fields=name,example --table-comment=my_first_table\n" msgstr "" +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +#, fuzzy +#| msgid "That's equal to the following:" +msgid "That would generate the following:" +msgstr "Это соответствует:" + #. type: Fenced code block (php) #: ../src/guide/databases/db-migrations.md #, no-wrap msgid "" -"return [\n" -" 'controllerMap' => [\n" -" // Common migrations for the whole application\n" -" 'migrate-app' => [\n" -" 'class' => 'yii\\console\\controllers\\MigrateController',\n" -" 'migrationNamespaces' => ['app\\migrations'],\n" -" 'migrationTable' => 'migration_app',\n" -" 'migrationPath' => null,\n" -" ],\n" -" // Migrations for the specific project's module\n" -" 'migrate-module' => [\n" -" 'class' => 'yii\\console\\controllers\\MigrateController',\n" -" 'migrationNamespaces' => ['module\\migrations'],\n" -" 'migrationTable' => 'migration_module',\n" -" 'migrationPath' => null,\n" -" ],\n" -" // Migrations for the specific extension\n" -" 'migrate-rbac' => [\n" -" 'class' => 'yii\\console\\controllers\\MigrateController',\n" -" 'migrationPath' => '@yii/rbac/migrations',\n" -" 'migrationTable' => 'migration_rbac',\n" -" ],\n" -" ],\n" -"];\n" -msgstr "" - -#. type: Plain text -#: ../src/guide/databases/db-migrations.md -msgid "Note that to synchronize database you now need to run multiple commands instead of one:" +"columnBuilder();\n" +"\n" +" $b->createTable('my_first_table', [\n" +" 'id' => $columnBuilder::primaryKey(),\n" +" 'name',\n" +" 'example',\n" +" ]);\n" +"\n" +" $b->addCommentOnTable('my_first_table', 'my_first_table');\n" +" }\n" +"\n" +" public function down(MigrationBuilder $b): void\n" +" {\n" +" $b->dropTable('my_first_table');\n" +" }\n" +"}\n" msgstr "" -#. type: Fenced code block +#. type: Plain text #: ../src/guide/databases/db-migrations.md -#, no-wrap -msgid "" -"yii migrate-app\n" -"yii migrate-module\n" -"yii migrate-rbac\n" +msgid "Commands available are:" +msgstr "" + +#. type: Bullet: '- ' +#: ../src/guide/databases/db-migrations.md +#, fuzzy +#| msgid "Sentry integration" +msgid "create - empty migration." +msgstr "Интеграция с Sentry" + +#. type: Bullet: '- ' +#: ../src/guide/databases/db-migrations.md +msgid "table - creating a table. Use `--fields` specify a list of fields to use. Types could be specified as well such as `id:primaryKey,name:string:defaultValue(\"Alex\"),user_id:integer:foreignKey,category_id2:integer:foreignKey(category id2)`." +msgstr "" + +#. type: Bullet: '- ' +#: ../src/guide/databases/db-migrations.md +msgid "dropTable - dropping a table." +msgstr "" + +#. type: Bullet: '- ' +#: ../src/guide/databases/db-migrations.md +msgid "addColumn - adding a column." +msgstr "" + +#. type: Bullet: '- ' +#: ../src/guide/databases/db-migrations.md +msgid "dropColumn - dropping a column." +msgstr "" + +#. type: Bullet: '- ' +#: ../src/guide/databases/db-migrations.md +msgid "junction - creating a junction table. Use `--and` specify a second table." msgstr "" #. type: Title ## #: ../src/guide/databases/db-migrations.md #, fuzzy, no-wrap -#| msgid "Defining aliases " -msgid "Migrating Multiple Databases " -msgstr "Определение псевдонимов " +#| msgid "Configuration" +msgid "Applying Migrations" +msgstr "Настройка" #. type: Plain text #: ../src/guide/databases/db-migrations.md -msgid "By default, migrations are applied to the same database specified by the `db` [application component](structure-application-components.md). If you want them to be applied to a different database, you may specify the `db` command-line option like shown below," +msgid "To upgrade a database to its latest structure, you should apply all available new migrations using the following command:" msgstr "" #. type: Fenced code block #: ../src/guide/databases/db-migrations.md #, no-wrap -msgid "yii migrate --db=db2\n" +msgid "./yii migrate:up\n" msgstr "" #. type: Plain text #: ../src/guide/databases/db-migrations.md -msgid "The above command will apply migrations to the `db2` database." +msgid "This command will list all migrations that have not been applied so far. If you confirm that you want to apply these migrations, it will run the `up()` method in every new migration class, one after another, in the order of their timestamp values. If any of the migrations fails, the command will quit without applying the rest of the migrations." msgstr "" #. type: Plain text #: ../src/guide/databases/db-migrations.md -msgid "Sometimes it may happen that you want to apply *some* of the migrations to one database, while some others to another database. To achieve this goal, when implementing a migration class you should explicitly specify the DB component ID that the migration would use, like the following:" +msgid "For each migration that has been successfully applied, the command will insert a row into a database table named `migration` to record the successful application of the migration. This will allow the migration tool to identify which migrations have been applied and which have not." msgstr "" -#. type: Fenced code block (php) +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +msgid "Sometimes, you may only want to apply one or a few new migrations, instead of all available migrations. You can do so by specifying the number of migrations that you want to apply when running the command. For example, the following command will try to apply the next three available migrations:" +msgstr "" + +#. type: Fenced code block #: ../src/guide/databases/db-migrations.md #, no-wrap -msgid "" -"db = 'db2';\n" -" parent::init();\n" -" }\n" -"}\n" +msgid "./yii migrate:up --limit=3\n" msgstr "" +#. type: Title ## +#: ../src/guide/databases/db-migrations.md +#, fuzzy, no-wrap +#| msgid "Defining aliases " +msgid "Reverting Migrations " +msgstr "Определение псевдонимов " + #. type: Plain text #: ../src/guide/databases/db-migrations.md -msgid "The above migration will be applied to `db2`, even if you specify a different database through the `db` command-line option. Note that the migration history will still be recorded in the database specified by the `db` command-line option." +msgid "To revert (undo) one or multiple migrations that have been applied before, you can run the following command:" msgstr "" -#. type: Plain text +#. type: Fenced code block #: ../src/guide/databases/db-migrations.md -msgid "If you have multiple migrations that use the same database, it is recommended that you create a base migration class with the above `init()` code. Then each migration class can extend from this base class." +#, no-wrap +msgid "" +"./yii migrate:down # revert the most recently applied migration\n" +"./yii migrate:down --limit=3 # revert the most 3 recently applied migrations\n" +"./yii migrate:down --all # revert all migrations\n" msgstr "" #. type: Plain text #: ../src/guide/databases/db-migrations.md #, no-wrap msgid "" -"> Tip: Besides setting the [[yii\\db\\Migration::db|db]] property, you can also operate on different databases\n" -"by creating new database connections to them in your migration classes. You then use the [DAO methods](db-dao.md)\n" -"with these connections to manipulate different databases.\n" +"> Note: Not all migrations are reversible. Trying to revert such migrations will cause an error and stop the\n" +"entire reverting process.\n" msgstr "" +#. type: Title ## +#: ../src/guide/databases/db-migrations.md +#, fuzzy, no-wrap +#| msgid "Resolving aliases " +msgid "Redoing Migrations " +msgstr "Разрешение псевдонимов " + #. type: Plain text #: ../src/guide/databases/db-migrations.md -msgid "Another strategy that you can take to migrate multiple databases is to keep migrations for different databases in different migration paths. Then you can migrate these databases in separate commands like the following:" +msgid "Redoing migrations means first reverting the specified migrations and then applying again. This can be done as follows:" msgstr "" #. type: Fenced code block #: ../src/guide/databases/db-migrations.md #, no-wrap msgid "" -"yii migrate --migrationPath=@app/migrations/db1 --db=db1\n" -"yii migrate --migrationPath=@app/migrations/db2 --db=db2\n" -"...\n" +"./yii migrate:redo # redo the last applied migration\n" +"./yii migrate:redo --limit=3 # redo the last 3 applied migrations\n" +"./yii migrate:redo --all # redo all migrations\n" msgstr "" #. type: Plain text #: ../src/guide/databases/db-migrations.md -msgid "The first command will apply migrations in `@app/migrations/db1` to the `db1` database, the second command will apply migrations in `@app/migrations/db2` to `db2`, and so on." +#, no-wrap +msgid "> Note: If a migration is not reversible, you will not be able to redo it.\n" +msgstr "" + +#. type: Title ## +#: ../src/guide/databases/db-migrations.md +#, fuzzy, no-wrap +#| msgid "Resolving aliases " +msgid "Listing Migrations " +msgstr "Разрешение псевдонимов " + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +msgid "To list which migrations have been applied and which are not, you may use the following commands:" +msgstr "" + +#. type: Fenced code block +#: ../src/guide/databases/db-migrations.md +#, no-wrap +msgid "" +"./yii migrate/history # showing the last 10 applied migrations\n" +"./yii migrate:history --limit=5 # showing the last 5 applied migrations\n" +"./yii migrate:history --all # showing all applied migrations\n" +"\n" +"./yii migrate:new # showing the first 10 new migrations\n" +"./yii migrate:new --limit=5 # showing the first 5 new migrations\n" +"./yii migrate:new --all # showing all new migrations\n" msgstr "" #. type: Title ### @@ -987,5 +905,10 @@ msgstr "" #. type: Plain text #: ../src/guide/databases/db-migrations.md -msgid "Migrations in Yii 2.0 and the [yiisoft/db-migration](https://github.com/yiisoft/db-migration/) package are not compatible, and the `migration` table is also not compatible. A probable solution is to use structure dumps and rename the old `migration` table. Upon the initial execution of migrations, a new `migration` table with new fields will be created. All further changes in the database schema are applied using the new `migration` component and recorded in the new migration table." +msgid "Migrations in Yii 2.0 and the [yiisoft/db-migration](https://github.com/yiisoft/db-migration/) package are not compatible, and the `migration` table is also not compatible." +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +msgid "A probable solution is to use structure dumps and rename the old `migration` table. Upon the initial execution of migrations, a new `migration` table with new fields will be created. All further changes in the database schema are applied using the new `migration` component and recorded in the new migration table." msgstr "" diff --git a/_translations/po/ru/internals_010-code-style.md.po b/_translations/po/ru/internals_010-code-style.md.po index fdc7cb46..676db98c 100644 --- a/_translations/po/ru/internals_010-code-style.md.po +++ b/_translations/po/ru/internals_010-code-style.md.po @@ -6,7 +6,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" -"POT-Creation-Date: 2025-12-24 08:02+0000\n" +"POT-Creation-Date: 2025-12-27 10:28+0000\n" "PO-Revision-Date: 2025-12-24 08:02+0000\n" "Last-Translator: Automatically generated\n" "Language-Team: none\n" @@ -16,115 +16,121 @@ msgstr "" "Content-Transfer-Encoding: 8bit\n" "Plural-Forms: nplurals=3; plural=(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2);\n" +#. type: Title ## +#: ../src/guide/databases/db-migrations.md ../src/internals/010-code-style.md +#, no-wrap +msgid "Strings" +msgstr "" + #. type: Title # -#: ../src/en/internals/010-code-style.md +#: ../src/internals/010-code-style.md #, no-wrap msgid "010 — Code style" msgstr "" #. type: Plain text -#: ../src/en/internals/010-code-style.md +#: ../src/internals/010-code-style.md msgid "Code formatting used in Yii 3 packages is based on [PSR-1](https://www.php-fig.org/psr/psr-1/) and [PSR-12](https://www.php-fig.org/psr/psr-12/) with extra rules added on top of it." msgstr "" #. type: Title ### -#: ../src/en/internals/010-code-style.md ../src/en/internals/017-tags.md -#: ../src/en/internals/018-widgets.md +#: ../src/internals/010-code-style.md ../src/internals/017-tags.md +#: ../src/internals/018-widgets.md #, no-wrap msgid "Names" msgstr "" #. type: Bullet: '- ' -#: ../src/en/internals/010-code-style.md +#: ../src/internals/010-code-style.md msgid "Use English only." msgstr "" #. type: Bullet: '- ' -#: ../src/en/internals/010-code-style.md +#: ../src/internals/010-code-style.md msgid "Use camelCase notation, including abbreviations (e.g., `enableIdn`)." msgstr "" #. type: Bullet: '- ' -#: ../src/en/internals/010-code-style.md +#: ../src/internals/010-code-style.md msgid "Use the shortest possible, but an explanatory name." msgstr "" #. type: Bullet: '- ' -#: ../src/en/internals/010-code-style.md +#: ../src/internals/010-code-style.md msgid "Never trim or abbreviate a name." msgstr "" #. type: Bullet: '- ' -#: ../src/en/internals/010-code-style.md +#: ../src/internals/010-code-style.md msgid "Postfix classes, interfaces, traits and variables, which is a [collection](https://en.wikipedia.org/wiki/Collection_(abstract_data_type)), with `Collection`." msgstr "" #. type: Title ## -#: ../src/en/internals/010-code-style.md +#: ../src/internals/010-code-style.md #, no-wrap msgid "Types" msgstr "" #. type: Bullet: '- ' -#: ../src/en/internals/010-code-style.md +#: ../src/internals/010-code-style.md msgid "Declare [argument and return types](https://www.php.net/manual/en/migration70.new-features.php) where possible." msgstr "" #. type: Bullet: '- ' -#: ../src/en/internals/010-code-style.md +#: ../src/internals/010-code-style.md msgid "[Use types for properties](https://wiki.php.net/rfc/typed_properties_v2)." msgstr "" #. type: Bullet: '- ' -#: ../src/en/internals/010-code-style.md +#: ../src/internals/010-code-style.md msgid "Use strict typing. Avoid mixed and union types where possible except compatible types such as `string|Stringable`." msgstr "" #. type: Title ## -#: ../src/en/internals/010-code-style.md +#: ../src/internals/010-code-style.md #, no-wrap msgid "Comments" msgstr "" #. type: Plain text -#: ../src/en/internals/010-code-style.md +#: ../src/internals/010-code-style.md msgid "Inline comments are to be avoided unless code couldn't be understood without them. A good example is a workaround for a bug in a certain PHP version." msgstr "" #. type: Plain text -#: ../src/en/internals/010-code-style.md +#: ../src/internals/010-code-style.md msgid "Method comment is necessary except it adds nothing to what method name and signature already has." msgstr "" #. type: Plain text -#: ../src/en/internals/010-code-style.md +#: ../src/internals/010-code-style.md msgid "Class comment should describe the purpose of the class." msgstr "" #. type: Plain text -#: ../src/en/internals/010-code-style.md +#: ../src/internals/010-code-style.md msgid "[See PHPDoc](https://github.com/yiisoft/docs/blob/master/014-docs.md#phpdoc)." msgstr "" #. type: Title ## -#: ../src/en/internals/010-code-style.md +#: ../src/internals/010-code-style.md #, no-wrap msgid "Formatting" msgstr "" #. type: Title ### -#: ../src/en/internals/010-code-style.md +#: ../src/internals/010-code-style.md #, no-wrap msgid "No alignment" msgstr "" #. type: Plain text -#: ../src/en/internals/010-code-style.md +#: ../src/internals/010-code-style.md msgid "Property, variable and constant value assignments shouldn't be aligned. The same applies to phpdoc tags. The reason is that aligned statements often cause larger diff and even conflicts." msgstr "" #. type: Fenced code block (php) -#: ../src/en/internals/010-code-style.md +#: ../src/internals/010-code-style.md #, no-wrap msgid "" "final class X\n" @@ -148,18 +154,18 @@ msgid "" msgstr "" #. type: Title ### -#: ../src/en/internals/010-code-style.md +#: ../src/internals/010-code-style.md #, no-wrap msgid "Chain calls" msgstr "" #. type: Plain text -#: ../src/en/internals/010-code-style.md +#: ../src/internals/010-code-style.md msgid "Chained calls should be formatted for better readability. If it's a long chain that doesn't fit the line length of 120 characters, then each call should on a new line:" msgstr "" #. type: Fenced code block (php) -#: ../src/en/internals/010-code-style.md +#: ../src/internals/010-code-style.md #, no-wrap msgid "" "$object\n" @@ -171,149 +177,143 @@ msgid "" msgstr "" #. type: Plain text -#: ../src/en/internals/010-code-style.md +#: ../src/internals/010-code-style.md msgid "If it's a short chain, it's alright for it to be on a single line:" msgstr "" #. type: Fenced code block (php) -#: ../src/en/internals/010-code-style.md +#: ../src/internals/010-code-style.md #, no-wrap msgid "$object = $object->withName('test');\n" msgstr "" -#. type: Title ## -#: ../src/en/internals/010-code-style.md -#, no-wrap -msgid "Strings" -msgstr "" - #. type: Bullet: '- ' -#: ../src/en/internals/010-code-style.md +#: ../src/internals/010-code-style.md msgid "When no variables involved, use `'Hello!'`" msgstr "" #. type: Bullet: '- ' -#: ../src/en/internals/010-code-style.md +#: ../src/internals/010-code-style.md msgid "To get variables into string prefer `\"Hello, $username!\"`" msgstr "" #. type: Title ## -#: ../src/en/internals/010-code-style.md +#: ../src/internals/010-code-style.md #, no-wrap msgid "Classes and interfaces" msgstr "" #. type: Title ### -#: ../src/en/internals/010-code-style.md +#: ../src/internals/010-code-style.md #, no-wrap msgid "Final by default" msgstr "" #. type: Plain text -#: ../src/en/internals/010-code-style.md +#: ../src/internals/010-code-style.md msgid "Classes should be `final` by default." msgstr "" #. type: Title ### -#: ../src/en/internals/010-code-style.md +#: ../src/internals/010-code-style.md #, no-wrap msgid "Private by default" msgstr "" #. type: Plain text -#: ../src/en/internals/010-code-style.md +#: ../src/internals/010-code-style.md msgid "Constants, properties and methods should be private by default." msgstr "" #. type: Title ### -#: ../src/en/internals/010-code-style.md +#: ../src/internals/010-code-style.md #, no-wrap msgid "Composition over inheritance" msgstr "" #. type: Plain text -#: ../src/en/internals/010-code-style.md +#: ../src/internals/010-code-style.md #, fuzzy #| msgid "Dependency injection and container" msgid "Prefer [composition to inheritance](guide/en/concept/di-container.md)." msgstr "Внедрение зависимостей и контейнер внедрения зависимостей" #. type: Title ### -#: ../src/en/internals/010-code-style.md +#: ../src/internals/010-code-style.md #, no-wrap msgid "Property, constant and method order" msgstr "" #. type: Plain text -#: ../src/en/internals/010-code-style.md +#: ../src/internals/010-code-style.md #, fuzzy #| msgid "That's equal to the following:" msgid "Order should be the following:" msgstr "Это соответствует:" #. type: Bullet: '- ' -#: ../src/en/internals/010-code-style.md +#: ../src/internals/010-code-style.md msgid "Constants" msgstr "" #. type: Bullet: '- ' -#: ../src/en/internals/010-code-style.md +#: ../src/internals/010-code-style.md msgid "Properties" msgstr "" #. type: Title ## -#: ../src/en/internals/010-code-style.md ../src/en/internals/017-tags.md -#: ../src/en/internals/018-widgets.md +#: ../src/internals/010-code-style.md ../src/internals/017-tags.md +#: ../src/internals/018-widgets.md #, no-wrap msgid "Methods" msgstr "" #. type: Plain text -#: ../src/en/internals/010-code-style.md +#: ../src/internals/010-code-style.md msgid "Within each category, items should be sorted by visibility:" msgstr "" #. type: Bullet: '- ' -#: ../src/en/internals/010-code-style.md +#: ../src/internals/010-code-style.md msgid "public" msgstr "" #. type: Bullet: '- ' -#: ../src/en/internals/010-code-style.md +#: ../src/internals/010-code-style.md msgid "protected" msgstr "" #. type: Bullet: '- ' -#: ../src/en/internals/010-code-style.md +#: ../src/internals/010-code-style.md msgid "private" msgstr "" #. type: Title ### -#: ../src/en/internals/010-code-style.md +#: ../src/internals/010-code-style.md #, no-wrap msgid "Abstract classes" msgstr "" #. type: Plain text -#: ../src/en/internals/010-code-style.md +#: ../src/internals/010-code-style.md msgid "Abstract classes *shouldn't* be prefixed or postfixed with `Abstract`." msgstr "" #. type: Title #### -#: ../src/en/internals/010-code-style.md +#: ../src/internals/010-code-style.md #, no-wrap msgid "Immutable methods" msgstr "" #. type: Plain text -#: ../src/en/internals/010-code-style.md +#: ../src/internals/010-code-style.md #, fuzzy #| msgid "That's equal to the following:" msgid "Immutable method convention is the following:" msgstr "Это соответствует:" #. type: Fenced code block (php) -#: ../src/en/internals/010-code-style.md +#: ../src/internals/010-code-style.md #, no-wrap msgid "" "public function withName(string $name): self\n" @@ -325,28 +325,28 @@ msgid "" msgstr "" #. type: Bullet: '1. ' -#: ../src/en/internals/010-code-style.md +#: ../src/internals/010-code-style.md msgid "Cloned object name is `$new`." msgstr "" #. type: Bullet: '2. ' -#: ../src/en/internals/010-code-style.md +#: ../src/internals/010-code-style.md msgid "Return type is `self`." msgstr "" #. type: Title #### -#: ../src/en/internals/010-code-style.md +#: ../src/internals/010-code-style.md #, no-wrap msgid "Boolean check methods" msgstr "" #. type: Plain text -#: ../src/en/internals/010-code-style.md +#: ../src/internals/010-code-style.md msgid "Methods that are there to check if something is true should be named like the following:" msgstr "" #. type: Fenced code block (php) -#: ../src/en/internals/010-code-style.md +#: ../src/internals/010-code-style.md #, no-wrap msgid "" "public function isDeleted(): bool;\n" @@ -355,29 +355,29 @@ msgid "" msgstr "" #. type: Title #### -#: ../src/en/internals/010-code-style.md +#: ../src/internals/010-code-style.md #, no-wrap msgid "Flags in methods " msgstr "" #. type: Plain text -#: ../src/en/internals/010-code-style.md +#: ../src/internals/010-code-style.md msgid "Boolean flags in methods are better to be avoided. It's a sign the method may be doing too much, and there should be two methods instead of one." msgstr "" #. type: Fenced code block (php) -#: ../src/en/internals/010-code-style.md +#: ../src/internals/010-code-style.md #, no-wrap msgid "public function login(bool $refreshPage = true): void;\n" msgstr "" #. type: Plain text -#: ../src/en/internals/010-code-style.md +#: ../src/internals/010-code-style.md msgid "It is better to be two methods:" msgstr "" #. type: Fenced code block (php) -#: ../src/en/internals/010-code-style.md +#: ../src/internals/010-code-style.md #, no-wrap msgid "" "public function login(): void;\n" @@ -385,18 +385,18 @@ msgid "" msgstr "" #. type: Title ## -#: ../src/en/internals/010-code-style.md +#: ../src/internals/010-code-style.md #, no-wrap msgid "Variables" msgstr "" #. type: Plain text -#: ../src/en/internals/010-code-style.md +#: ../src/internals/010-code-style.md msgid "Add an underscore (`_`) prefix for unused variables. For example:" msgstr "" #. type: Fenced code block (php) -#: ../src/en/internals/010-code-style.md +#: ../src/internals/010-code-style.md #, no-wrap msgid "" "foreach ($items as $key => $_value) {\n" @@ -405,18 +405,18 @@ msgid "" msgstr "" #. type: Title ## -#: ../src/en/internals/010-code-style.md +#: ../src/internals/010-code-style.md #, no-wrap msgid "Imports" msgstr "" #. type: Plain text -#: ../src/en/internals/010-code-style.md +#: ../src/internals/010-code-style.md msgid "Prefer importing classes and functions to using fully qualified names:" msgstr "" #. type: Fenced code block (php) -#: ../src/en/internals/010-code-style.md +#: ../src/internals/010-code-style.md #, no-wrap msgid "" "use Yiisoft\\Arrays\\ArrayHelper;\n" @@ -428,23 +428,23 @@ msgid "" msgstr "" #. type: Title ## -#: ../src/en/internals/010-code-style.md +#: ../src/internals/010-code-style.md #, no-wrap msgid "Additional conventions" msgstr "" #. type: Bullet: '- ' -#: ../src/en/internals/010-code-style.md +#: ../src/internals/010-code-style.md msgid "[Namespaces](004-namespaces.md)" msgstr "" #. type: Bullet: '- ' -#: ../src/en/internals/010-code-style.md +#: ../src/internals/010-code-style.md msgid "[Exceptions](007-exceptions.md)" msgstr "" #. type: Bullet: '- ' -#: ../src/en/internals/010-code-style.md +#: ../src/internals/010-code-style.md #, fuzzy #| msgid "[Preface](preface.md)" msgid "[Interfaces](008-interfaces.md)" diff --git a/_translations/pot/guide_databases_db-migrations.md.pot b/_translations/pot/guide_databases_db-migrations.md.pot index afa70e6a..54f45105 100644 --- a/_translations/pot/guide_databases_db-migrations.md.pot +++ b/_translations/pot/guide_databases_db-migrations.md.pot @@ -7,7 +7,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" -"POT-Creation-Date: 2025-12-27 08:43+0000\n" +"POT-Creation-Date: 2025-12-27 10:28+0000\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -199,6 +199,15 @@ msgid "" "],\n" msgstr "" +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +msgid "" +"If you want to place migrations elsewhere, you can define the path in " +"`newMigrationPath`. If your migrations to be applied are from multiple " +"sources, such as external modules, `sourcePaths` could be used to define " +"these." +msgstr "" + #. type: Plain text #: ../src/guide/databases/db-migrations.md msgid "" @@ -207,7 +216,7 @@ msgid "" "PostgreSQL." msgstr "" -#. type: Title ### +#. type: Title ## #: ../src/guide/databases/db-migrations.md #, no-wrap msgid "Creating a migration" @@ -221,7 +230,9 @@ msgstr "" #. type: Fenced code block (sh) #: ../src/guide/databases/db-migrations.md #, no-wrap -msgid "make yii migrate:create \n" +msgid "" +"make shell\n" +"./yii migrate:create \n" msgstr "" #. type: Plain text @@ -236,7 +247,9 @@ msgstr "" #. type: Fenced code block #: ../src/guide/databases/db-migrations.md #, no-wrap -msgid "make yii migrate:create create_news_table\n" +msgid "" +"make shell\n" +"./yii migrate:create create_news_table\n" msgstr "" #. type: Plain text @@ -330,822 +343,644 @@ msgstr "" #. type: Plain text #: ../src/guide/databases/db-migrations.md -#, no-wrap msgid "" -"TODO: explain $b and $qb\n" -"Below is the list of all these database accessing methods:\n" +"Migration builder `$b` in the above manages database schema while the column " +"builder `$cb` manages column types. Both allow using *abstract types*. When " +"a migration is applied to a particular database, the abstract types will be " +"translated into the corresponding database physical types and corresponding " +"SQL to define them." msgstr "" -#. type: Title ### +#. type: Plain text #: ../src/guide/databases/db-migrations.md -#, no-wrap -msgid "Irreversible migrations" +msgid "Methods available in migration builder belong to the following types:" msgstr "" -#. type: Plain text +#. type: Bullet: '- ' #: ../src/guide/databases/db-migrations.md -msgid "" -"Not all migrations are reversible. For example, if the `up()` method deletes " -"a row of a table, you may not be able to recover this row in the `down()` " -"method. Sometimes, you may be just too lazy to implement the `down()`, " -"because it is not very common to revert database migrations. In this case, " -"you should implement `Yiisoft\\Db\\Migration\\MigrationInterface` that has " -"`up()` only." +msgid "Raw queries" msgstr "" -#. type: Title ### +#. type: Bullet: ' - ' #: ../src/guide/databases/db-migrations.md -#, no-wrap -msgid "Transactional migrations (TODO: update!!!)" +msgid "getDb — to get database connection instance." msgstr "" -#. type: Plain text +#. type: Bullet: ' - ' #: ../src/guide/databases/db-migrations.md -msgid "" -"While performing complex DB migrations, it is important to ensure each " -"migration to either succeed or fail as a whole so that the database can " -"maintain integrity and consistency. To achieve this goal, it is recommended " -"that you enclose the DB operations of each migration in a [transaction](db-" -"dao.md#performing-transactions)." +msgid "execute — to execute raw SQL query." msgstr "" -#. type: Plain text +#. type: Bullet: '- ' #: ../src/guide/databases/db-migrations.md -msgid "" -"An even easier way of implementing transactional migrations is to put " -"migration code in the `safeUp()` and `safeDown()` methods. These two methods " -"differ from `up()` and `down()` in that they are enclosed implicitly in a " -"transaction. As a result, if any operation in these methods fails, all " -"prior operations will be rolled back automatically." +msgid "Data" msgstr "" -#. type: Plain text +#. type: Bullet: ' - ' #: ../src/guide/databases/db-migrations.md -msgid "" -"In the following example, besides creating the `news` table we also insert " -"an initial row into this table." +msgid "insert / update / delete" msgstr "" -#. type: Fenced code block (php) +#. type: Bullet: ' - ' #: ../src/guide/databases/db-migrations.md -#, no-wrap -msgid "" -"createTable('news', [\n" -" 'id' => $this->primaryKey(),\n" -" 'title' => $this->string()->notNull(),\n" -" 'content' => $this->text(),\n" -" ]);\n" -"\n" -" $this->insert('news', [\n" -" 'title' => 'test 1',\n" -" 'content' => 'content 1',\n" -" ]);\n" -" }\n" -"\n" -" public function safeDown()\n" -" {\n" -" $this->delete('news', ['id' => 1]);\n" -" $this->dropTable('news');\n" -" }\n" -"}\n" +msgid "batchInsert" msgstr "" -#. type: Plain text +#. type: Bullet: ' - ' #: ../src/guide/databases/db-migrations.md -msgid "" -"Note that usually when you perform multiple DB operations in `safeUp()`, you " -"should reverse their execution order in `safeDown()`. In the above example " -"we first create the table and then insert a row in `safeUp()`; while in " -"`safeDown()` we first delete the row and then drop the table." +msgid "upsert" msgstr "" -#. type: Plain text +#. type: Bullet: '- ' #: ../src/guide/databases/db-migrations.md -#, no-wrap -msgid "" -"> Note: Not all DBMS support transactions. And some DB queries cannot be put into a transaction. For some examples,\n" -"please refer to [implicit commit](https://dev.mysql.com/doc/refman/5.7/en/implicit-commit.html). If this is the case,\n" -"you should still implement `up()` and `down()`, instead.\n" +msgid "Tables and views" msgstr "" -#. type: Plain text +#. type: Bullet: ' - ' #: ../src/guide/databases/db-migrations.md -#, no-wrap -msgid "TODO: TransactionalMigrationInterface\n" +msgid "createTable / renameTable / dropTable" msgstr "" -#. type: Title ## +#. type: Bullet: ' - ' #: ../src/guide/databases/db-migrations.md -#, no-wrap -msgid "TODO: update" +msgid "truncateTable" msgstr "" -#. type: Plain text +#. type: Bullet: ' - ' #: ../src/guide/databases/db-migrations.md -msgid "" -"The base migration class [[yii\\db\\Migration]] exposes a database " -"connection via the [[yii\\db\\Migration::db|db]] property. You can use it to " -"manipulate the database schema using the methods as described in [Working " -"with Database Schema](db-dao.md#database-schema)." +msgid "addCommentOnTable / dropCommentFromTable" msgstr "" -#. type: Plain text +#. type: Bullet: ' - ' #: ../src/guide/databases/db-migrations.md -#, no-wrap -msgid "" -"Rather than using physical types, when creating a table or column you should use *abstract types*\n" -"so that your migrations are independent of specific DBMS. The [[yii\\db\\Schema]] class defines\n" -"a set of constants to represent the supported abstract types. These constants are named in the format\n" -"of `TYPE_`. For example, `TYPE_PK` refers to auto-incremental primary key type; `TYPE_STRING`\n" -"refers to a string type. When a migration is applied to a particular database, the abstract types\n" -"will be translated into the corresponding physical types. In the case of MySQL, `TYPE_PK` will be turned\n" -"into `int(11) NOT NULL AUTO_INCREMENT PRIMARY KEY`, while `TYPE_STRING` becomes `varchar(255)`.\n" +msgid "createView / dropView" msgstr "" -#. type: Plain text +#. type: Bullet: '- ' #: ../src/guide/databases/db-migrations.md -msgid "" -"You can append additional constraints when using abstract types. In the " -"above example, ` NOT NULL` is appended to `Schema::TYPE_STRING` to specify " -"that the column cannot be `null`." +msgid "Columns" msgstr "" -#. type: Plain text +#. type: Bullet: ' - ' #: ../src/guide/databases/db-migrations.md -#, no-wrap -msgid "" -"> Info: The mapping between abstract types and physical types is specified by\n" -"the [[yii\\db\\QueryBuilder::$typeMap|$typeMap]] property in each concrete `QueryBuilder` class.\n" +msgid "addColumn / renameColumn / alterColumn / dropColumn" msgstr "" -#. type: Plain text +#. type: Bullet: ' - ' #: ../src/guide/databases/db-migrations.md -msgid "" -"Since version 2.0.6, you can make use of the newly introduced schema builder " -"which provides more convenient way of defining column schema. So the " -"migration above could be written like the following:" +msgid "addCommentOnColumn / dropCommentFromColumn" msgstr "" -#. type: Fenced code block (php) +#. type: Bullet: '- ' #: ../src/guide/databases/db-migrations.md -#, no-wrap -msgid "" -"createTable('news', [\n" -" 'id' => $this->primaryKey(),\n" -" 'title' => $this->string()->notNull(),\n" -" 'content' => $this->text(),\n" -" ]);\n" -" }\n" -"\n" -" public function down()\n" -" {\n" -" $this->dropTable('news');\n" -" }\n" -"}\n" +msgid "Keys and indexes" msgstr "" -#. type: Plain text +#. type: Bullet: ' - ' #: ../src/guide/databases/db-migrations.md -msgid "" -"A list of all available methods for defining the column types is available " -"in the API documentation of [[yii\\db\\SchemaBuilderTrait]]." +msgid "addPrimaryKey / dropPrimaryKey" +msgstr "" + +#. type: Bullet: ' - ' +#: ../src/guide/databases/db-migrations.md +msgid "addForeignKey / dropForeignKey" +msgstr "" + +#. type: Bullet: ' - ' +#: ../src/guide/databases/db-migrations.md +msgid "createIndex / dropIndex" msgstr "" #. type: Plain text #: ../src/guide/databases/db-migrations.md -#, no-wrap msgid "" -"> Info: The generated file permissions and ownership will be determined by the current environment. This might lead to\n" -"inaccessible files. This could, for example, happen when the migration is created within a docker container\n" -"and the files are edited on the host. In this case the `newFileMode` and/or `newFileOwnership` of the MigrateController\n" -"can be changed. E.g. in the application config:\n" +"Additionally, there's a `columnBuilder()` which is used to obtain a column " +"builder as in example above. The builder has static methods that define " +"various column types:" msgstr "" -#. type: Fenced code block (php) +#. type: Bullet: '- ' #: ../src/guide/databases/db-migrations.md -#, no-wrap -msgid "" -" [\n" -" 'migrate' => [\n" -" 'class' => 'yii\\console\\controllers\\MigrateController',\n" -" 'newFileOwnership' => '1000:1000', # Default WSL user id\n" -" 'newFileMode' => 0660,\n" -" ],\n" -" ],\n" -" ];\n" +msgid "Keys" msgstr "" -#. type: Title ## +#. type: Bullet: ' - ' #: ../src/guide/databases/db-migrations.md -#, no-wrap -msgid "Generating Migrations (TODO: likely is OK but...)" +msgid "primaryKey" msgstr "" -#. type: Plain text +#. type: Bullet: ' - ' #: ../src/guide/databases/db-migrations.md -msgid "" -"The command provides a convenient way to create migrations using the " -"provided [view](https://github.com/yiisoft/db-migration/tree/master/" -"resources/views):" +msgid "smallPrimaryKey" msgstr "" -#. type: Fenced code block (shell) +#. type: Bullet: ' - ' #: ../src/guide/databases/db-migrations.md -#, no-wrap -msgid "make yii migrate:create my_first_table --command=table --fields=name,example --table-comment=my_first_table\n" +msgid "bigPrimaryKey" msgstr "" -#. type: Plain text +#. type: Bullet: ' - ' #: ../src/guide/databases/db-migrations.md -msgid "That would generate the following:" +msgid "uuidPrimaryKey" msgstr "" -#. type: Fenced code block (php) +#. type: Bullet: '- ' #: ../src/guide/databases/db-migrations.md -#, no-wrap -msgid "" -"createTable('my_first_table', [\n" -" 'id' => $b->primaryKey(),\n" -" 'name',\n" -" 'example',\n" -" ]);\n" -" \n" -" $b->addCommentOnTable('my_first_table', 'dest');\n" -" }\n" -"\n" -" public function down(MigrationBuilder $b): void\n" -" {\n" -" $b->dropTable('my_first_table');\n" -" }\n" -"}\n" +msgid "Boolean" msgstr "" -#. type: Plain text +#. type: Bullet: ' - ' #: ../src/guide/databases/db-migrations.md -msgid "" -"For more information [see](https://github.com/yiisoft/db-migration/tree/" -"master/docs/guide/en)" +msgid "boolean" msgstr "" -#. type: Title ## +#. type: Bullet: '- ' #: ../src/guide/databases/db-migrations.md -#, no-wrap -msgid "Applying Migrations" +msgid "Numbers" msgstr "" -#. type: Plain text +#. type: Bullet: ' - ' #: ../src/guide/databases/db-migrations.md -msgid "" -"To upgrade a database to its latest structure, you should apply all " -"available new migrations using the following command:" +msgid "bit" msgstr "" -#. type: Fenced code block +#. type: Bullet: ' - ' #: ../src/guide/databases/db-migrations.md -#, no-wrap -msgid "yii migrate\n" +msgid "tinyint" msgstr "" -#. type: Plain text +#. type: Bullet: ' - ' #: ../src/guide/databases/db-migrations.md -msgid "" -"This command will list all migrations that have not been applied so far. If " -"you confirm that you want to apply these migrations, it will run the `up()` " -"or `safeUp()` method in every new migration class, one after another, in the " -"order of their timestamp values. If any of the migrations fails, the command " -"will quit without applying the rest of the migrations." +msgid "smallint" msgstr "" -#. type: Plain text +#. type: Bullet: ' - ' #: ../src/guide/databases/db-migrations.md -#, no-wrap -msgid "" -"> Tip: In case you don't have command line at your server you may try [web shell](https://github.com/samdark/yii2-webshell)\n" -"> extension.\n" +msgid "integer" msgstr "" -#. type: Plain text +#. type: Bullet: ' - ' #: ../src/guide/databases/db-migrations.md -msgid "" -"For each migration that has been successfully applied, the command will " -"insert a row into a database table named `migration` to record the " -"successful application of the migration. This will allow the migration tool " -"to identify which migrations have been applied and which have not." +msgid "bigint" msgstr "" -#. type: Plain text +#. type: Bullet: ' - ' #: ../src/guide/databases/db-migrations.md -#, no-wrap -msgid "" -"> Info: The migration tool will automatically create the `migration` table in the database specified by\n" -"the [[yii\\console\\controllers\\MigrateController::db|db]] option of the command. By default, the database\n" -"is specified by the `db` [application component](structure-application-components.md).\n" +msgid "flat" msgstr "" -#. type: Plain text +#. type: Bullet: ' - ' #: ../src/guide/databases/db-migrations.md -msgid "" -"Sometimes, you may only want to apply one or a few new migrations, instead " -"of all available migrations. You can do so by specifying the number of " -"migrations that you want to apply when running the command. For example, " -"the following command will try to apply the next three available migrations:" +msgid "double" msgstr "" -#. type: Fenced code block +#. type: Bullet: ' - ' #: ../src/guide/databases/db-migrations.md +msgid "decimal" +msgstr "" + +#. type: Title ## +#: ../src/guide/databases/db-migrations.md ../src/internals/010-code-style.md #, no-wrap -msgid "yii migrate 3\n" +msgid "Strings" msgstr "" -#. type: Plain text +#. type: Bullet: ' - ' #: ../src/guide/databases/db-migrations.md -msgid "" -"You can also explicitly specify a particular migration to which the database " -"should be migrated by using the `migrate/to` command in one of the following " -"formats:" +msgid "char" msgstr "" -#. type: Fenced code block +#. type: Bullet: ' - ' #: ../src/guide/databases/db-migrations.md -#, no-wrap -msgid "" -"yii migrate/to 150101_185401 # using timestamp to specify the migration\n" -"yii migrate/to \"2015-01-01 18:54:01\" # using a string that can be parsed by strtotime()\n" -"yii migrate/to m150101_185401_create_news_table # using full name\n" -"yii migrate/to 1392853618 # using UNIX timestamp\n" +msgid "string" msgstr "" -#. type: Plain text +#. type: Bullet: ' - ' #: ../src/guide/databases/db-migrations.md -msgid "" -"If there are any unapplied migrations earlier than the specified one, they " -"will all be applied before the specified migration is applied." +msgid "text" msgstr "" -#. type: Plain text +#. type: Bullet: '- ' #: ../src/guide/databases/db-migrations.md -msgid "" -"If the specified migration has already been applied before, any later " -"applied migrations will be reverted." +msgid "Date and time" msgstr "" -#. type: Title ## +#. type: Bullet: ' - ' #: ../src/guide/databases/db-migrations.md -#, no-wrap -msgid "Reverting Migrations " +msgid "timestamp" msgstr "" -#. type: Plain text +#. type: Bullet: ' - ' #: ../src/guide/databases/db-migrations.md -msgid "" -"To revert (undo) one or multiple migrations that have been applied before, " -"you can run the following command:" +msgid "datetime" msgstr "" -#. type: Fenced code block +#. type: Bullet: ' - ' #: ../src/guide/databases/db-migrations.md -#, no-wrap -msgid "" -"yii migrate/down # revert the most recently applied migration\n" -"yii migrate/down 3 # revert the most 3 recently applied migrations\n" +msgid "datetimeWithTimezone" msgstr "" -#. type: Plain text +#. type: Bullet: ' - ' #: ../src/guide/databases/db-migrations.md -#, no-wrap -msgid "" -"> Note: Not all migrations are reversible. Trying to revert such migrations will cause an error and stop the\n" -"entire reverting process.\n" +msgid "time" msgstr "" -#. type: Title ## +#. type: Bullet: ' - ' #: ../src/guide/databases/db-migrations.md -#, no-wrap -msgid "Redoing Migrations " +msgid "timeWithTimezone" msgstr "" -#. type: Plain text +#. type: Bullet: ' - ' #: ../src/guide/databases/db-migrations.md -msgid "" -"Redoing migrations means first reverting the specified migrations and then " -"applying again. This can be done as follows:" +msgid "date" msgstr "" -#. type: Fenced code block +#. type: Bullet: '- ' #: ../src/guide/databases/db-migrations.md -#, no-wrap -msgid "" -"yii migrate/redo # redo the last applied migration\n" -"yii migrate/redo 3 # redo the last 3 applied migrations\n" +msgid "Special types" msgstr "" -#. type: Plain text +#. type: Bullet: ' - ' #: ../src/guide/databases/db-migrations.md -#, no-wrap -msgid "> Note: If a migration is not reversible, you will not be able to redo it.\n" +msgid "money" msgstr "" -#. type: Title ## +#. type: Bullet: ' - ' #: ../src/guide/databases/db-migrations.md -#, no-wrap -msgid "Refreshing Migrations " +msgid "binary" msgstr "" -#. type: Plain text +#. type: Bullet: ' - ' #: ../src/guide/databases/db-migrations.md -msgid "" -"Since Yii 2.0.13 you can delete all tables and foreign keys from the " -"database and apply all migrations from the beginning." +msgid "uuid" msgstr "" -#. type: Fenced code block +#. type: Bullet: ' - ' #: ../src/guide/databases/db-migrations.md -#, no-wrap -msgid "yii migrate/fresh # truncate the database and apply all migrations from the beginning\n" +msgid "array" msgstr "" -#. type: Title ## +#. type: Bullet: ' - ' #: ../src/guide/databases/db-migrations.md -#, no-wrap -msgid "Listing Migrations " +msgid "structured" +msgstr "" + +#. type: Bullet: ' - ' +#: ../src/guide/databases/db-migrations.md +msgid "json" +msgstr "" + +#. type: Bullet: '- ' +#: ../src/guide/databases/db-migrations.md +msgid "enum" msgstr "" #. type: Plain text #: ../src/guide/databases/db-migrations.md msgid "" -"To list which migrations have been applied and which are not, you may use " -"the following commands:" +"All the above methods create a base type which could be adjusted with " +"additional methods:" msgstr "" -#. type: Fenced code block +#. type: Bullet: '- ' #: ../src/guide/databases/db-migrations.md -#, no-wrap -msgid "" -"yii migrate/history # showing the last 10 applied migrations\n" -"yii migrate/history 5 # showing the last 5 applied migrations\n" -"yii migrate/history all # showing all applied migrations\n" -"\n" -"yii migrate/new # showing the first 10 new migrations\n" -"yii migrate/new 5 # showing the first 5 new migrations\n" -"yii migrate/new all # showing all new migrations\n" +msgid "null / notNull" msgstr "" -#. type: Title ## +#. type: Bullet: '- ' #: ../src/guide/databases/db-migrations.md -#, no-wrap -msgid "Modifying Migration History " +msgid "defaultValue" msgstr "" -#. type: Plain text +#. type: Bullet: '- ' #: ../src/guide/databases/db-migrations.md -msgid "" -"Instead of actually applying or reverting migrations, sometimes you may " -"simply want to mark that your database has been upgraded to a particular " -"migration. This often happens when you manually change the database to a " -"particular state and you do not want the migration(s) for that change to be " -"re-applied later. You can achieve this goal with the following command:" +msgid "unique" msgstr "" -#. type: Fenced code block +#. type: Bullet: '- ' #: ../src/guide/databases/db-migrations.md -#, no-wrap -msgid "" -"yii migrate/mark 150101_185401 # using timestamp to specify the migration\n" -"yii migrate/mark \"2015-01-01 18:54:01\" # using a string that can be parsed by strtotime()\n" -"yii migrate/mark m150101_185401_create_news_table # using full name\n" -"yii migrate/mark 1392853618 # using UNIX timestamp\n" +msgid "scale / size / unsigned" msgstr "" -#. type: Plain text +#. type: Bullet: '- ' #: ../src/guide/databases/db-migrations.md -msgid "" -"The command will modify the `migration` table by adding or deleting certain " -"rows to indicate that the database has been applied migrations to the " -"specified one. No migrations will be applied or reverted by this command." +msgid "primaryKey / autoIncrement" msgstr "" -#. type: Title ## +#. type: Bullet: '- ' +#: ../src/guide/databases/db-migrations.md +msgid "check" +msgstr "" + +#. type: Bullet: '- ' +#: ../src/guide/databases/db-migrations.md +msgid "comment" +msgstr "" + +#. type: Bullet: '- ' +#: ../src/guide/databases/db-migrations.md +msgid "computed" +msgstr "" + +#. type: Bullet: '- ' +#: ../src/guide/databases/db-migrations.md +msgid "extra" +msgstr "" + +#. type: Bullet: '- ' +#: ../src/guide/databases/db-migrations.md +msgid "reference" +msgstr "" + +#. type: Title ### #: ../src/guide/databases/db-migrations.md #, no-wrap -msgid "Customizing Migrations " +msgid "Irreversible migrations" msgstr "" #. type: Plain text #: ../src/guide/databases/db-migrations.md -msgid "There are several ways to customize the migration command." +msgid "" +"Not all migrations are reversible. For example, if the `up()` method deletes " +"a row of a table, you may not be able to recover this row in the `down()` " +"method. Sometimes, you may be just too lazy to implement the `down()`, " +"because it is not very common to revert database migrations. In this case, " +"you should implement `Yiisoft\\Db\\Migration\\MigrationInterface` that has " +"`up()` only." msgstr "" #. type: Title ### #: ../src/guide/databases/db-migrations.md #, no-wrap -msgid "Using Command Line Options " +msgid "Transactional migrations" msgstr "" #. type: Plain text #: ../src/guide/databases/db-migrations.md msgid "" -"The migration command comes with a few command-line options that can be used " -"to customize its behaviors:" +"While performing complex DB migrations, it is important to ensure each " +"migration to either succeed or fail as a whole so that the database can " +"maintain integrity and consistency. To achieve this goal, it is recommended " +"that you may enclose the DB operations of each migration in a transaction " +"automatically by adding `TransactionalMigrationInterface` to `implements` of " +"your migration." msgstr "" -#. type: Bullet: '* ' +#. type: Plain text #: ../src/guide/databases/db-migrations.md msgid "" -"`interactive`: boolean (defaults to `true`), specifies whether to perform " -"migrations in an interactive mode. When this is `true`, the user will be " -"prompted before the command performs certain actions. You may want to set " -"this to `false` if the command is being used in a background process." +"As a result, if any operation in the `up()` or `down()` method fails, all " +"prior operations will be rolled back automatically." msgstr "" -#. type: Bullet: '* ' +#. type: Plain text #: ../src/guide/databases/db-migrations.md +#, no-wrap msgid "" -"`migrationPath`: string|array (defaults to `@app/migrations`), specifies the " -"directory storing all migration class files. This can be specified as either " -"a directory path or a path [alias](concept-aliases.md). Note that the " -"directory must exist, or the command may trigger an error. Since version " -"2.0.12 an array can be specified for loading migrations from multiple " -"sources." +"> Note: Not all DBMS support transactions. And some DB queries cannot be put into a transaction. For some examples,\n" +"please refer to [implicit commit](https://dev.mysql.com/doc/refman/5.7/en/implicit-commit.html).\n" msgstr "" -#. type: Bullet: '* ' +#. type: Title ## #: ../src/guide/databases/db-migrations.md -msgid "" -"`migrationTable`: string (defaults to `migration`), specifies the name of " -"the database table for storing migration history information. The table will " -"be automatically created by the command if it does not exist. You may also " -"manually create it using the structure `version varchar(255) primary key, " -"apply_time integer`." +#, no-wrap +msgid "Generating a migration" msgstr "" -#. type: Bullet: '* ' +#. type: Plain text #: ../src/guide/databases/db-migrations.md msgid "" -"`db`: string (defaults to `db`), specifies the ID of the database " -"[application component](structure-application-components.md). It represents " -"the database that will be migrated using this command." +"Instead of writing migrations by hand, the command provides a convenient way " +"generate some of the code." msgstr "" -#. type: Bullet: '* ' +#. type: Fenced code block (shell) #: ../src/guide/databases/db-migrations.md +#, no-wrap msgid "" -"`templateFile`: string (defaults to `@yii/views/migration.php`), specifies " -"the path of the template file that is used for generating skeleton migration " -"class files. This can be specified as either a file path or a path [alias]" -"(concept-aliases.md). The template file is a PHP script in which you can use " -"a predefined variable named `$className` to get the migration class name." +"make shell\n" +"./yii migrate:create -- my_first_table --command=table --fields=name,example --table-comment=my_first_table\n" msgstr "" #. type: Plain text #: ../src/guide/databases/db-migrations.md -#, no-wrap -msgid "" -"* `generatorTemplateFiles`: array (defaults to `[\n" -" 'create_table' => '@yii/views/createTableMigration.php',\n" -" 'drop_table' => '@yii/views/dropTableMigration.php',\n" -" 'add_column' => '@yii/views/addColumnMigration.php',\n" -" 'drop_column' => '@yii/views/dropColumnMigration.php',\n" -" 'create_junction' => '@yii/views/createTableMigration.php'\n" -" ]`), specifies template files for generating migration code. See \"[Generating Migrations](#generating-migrations)\"\n" -" for more details.\n" +msgid "That would generate the following:" msgstr "" -#. type: Bullet: '* ' +#. type: Fenced code block (php) #: ../src/guide/databases/db-migrations.md +#, no-wrap msgid "" -"`fields`: array of column definition strings used for creating migration " -"code. Defaults to `[]`. The format of each definition is `COLUMN_NAME:" -"COLUMN_TYPE:COLUMN_DECORATOR`. For example, `--fields=name:string(12):" -"notNull` produces a string column of size 12 which is not `null`." +"columnBuilder();\n" +"\n" +" $b->createTable('my_first_table', [\n" +" 'id' => $columnBuilder::primaryKey(),\n" +" 'name',\n" +" 'example',\n" +" ]);\n" +"\n" +" $b->addCommentOnTable('my_first_table', 'my_first_table');\n" +" }\n" +"\n" +" public function down(MigrationBuilder $b): void\n" +" {\n" +" $b->dropTable('my_first_table');\n" +" }\n" +"}\n" msgstr "" #. type: Plain text #: ../src/guide/databases/db-migrations.md -msgid "The following example shows how you can use these options." +msgid "Commands available are:" msgstr "" -#. type: Plain text +#. type: Bullet: '- ' #: ../src/guide/databases/db-migrations.md -msgid "" -"For example, if we want to migrate a `forum` module whose migration files " -"are located within the module's `migrations` directory, we can use the " -"following command:" +msgid "create - empty migration." msgstr "" -#. type: Fenced code block +#. type: Bullet: '- ' #: ../src/guide/databases/db-migrations.md -#, no-wrap msgid "" -"# migrate the migrations in a forum module non-interactively\n" -"yii migrate --migrationPath=@app/modules/forum/migrations --interactive=0\n" +"table - creating a table. Use `--fields` specify a list of fields to use. " +"Types could be specified as well such as `id:primaryKey,name:string:" +"defaultValue(\"Alex\"),user_id:integer:foreignKey,category_id2:integer:" +"foreignKey(category id2)`." msgstr "" -#. type: Title ### +#. type: Bullet: '- ' #: ../src/guide/databases/db-migrations.md -#, no-wrap -msgid "Separated Migrations" +msgid "dropTable - dropping a table." msgstr "" -#. type: Plain text +#. type: Bullet: '- ' #: ../src/guide/databases/db-migrations.md -msgid "" -"Sometimes using single migration history for all project migrations is not " -"desirable. For example: you may install some 'blog' extension, which " -"contains fully separated functionality and contain its own migrations, which " -"should not affect the ones dedicated to main project functionality." +msgid "addColumn - adding a column." msgstr "" -#. type: Plain text +#. type: Bullet: '- ' +#: ../src/guide/databases/db-migrations.md +msgid "dropColumn - dropping a column." +msgstr "" + +#. type: Bullet: '- ' #: ../src/guide/databases/db-migrations.md msgid "" -"If you want several migrations to be applied and tracked down completely " -"separated from each other, you can configure multiple migration commands " -"which will use different namespaces and migration history tables:" +"junction - creating a junction table. Use `--and` specify a second table." msgstr "" -#. type: Fenced code block (php) +#. type: Title ## #: ../src/guide/databases/db-migrations.md #, no-wrap -msgid "" -"return [\n" -" 'controllerMap' => [\n" -" // Common migrations for the whole application\n" -" 'migrate-app' => [\n" -" 'class' => 'yii\\console\\controllers\\MigrateController',\n" -" 'migrationNamespaces' => ['app\\migrations'],\n" -" 'migrationTable' => 'migration_app',\n" -" 'migrationPath' => null,\n" -" ],\n" -" // Migrations for the specific project's module\n" -" 'migrate-module' => [\n" -" 'class' => 'yii\\console\\controllers\\MigrateController',\n" -" 'migrationNamespaces' => ['module\\migrations'],\n" -" 'migrationTable' => 'migration_module',\n" -" 'migrationPath' => null,\n" -" ],\n" -" // Migrations for the specific extension\n" -" 'migrate-rbac' => [\n" -" 'class' => 'yii\\console\\controllers\\MigrateController',\n" -" 'migrationPath' => '@yii/rbac/migrations',\n" -" 'migrationTable' => 'migration_rbac',\n" -" ],\n" -" ],\n" -"];\n" +msgid "Applying Migrations" msgstr "" #. type: Plain text #: ../src/guide/databases/db-migrations.md msgid "" -"Note that to synchronize database you now need to run multiple commands " -"instead of one:" +"To upgrade a database to its latest structure, you should apply all " +"available new migrations using the following command:" msgstr "" #. type: Fenced code block #: ../src/guide/databases/db-migrations.md #, no-wrap +msgid "./yii migrate:up\n" +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md msgid "" -"yii migrate-app\n" -"yii migrate-module\n" -"yii migrate-rbac\n" +"This command will list all migrations that have not been applied so far. If " +"you confirm that you want to apply these migrations, it will run the `up()` " +"method in every new migration class, one after another, in the order of " +"their timestamp values. If any of the migrations fails, the command will " +"quit without applying the rest of the migrations." msgstr "" -#. type: Title ## +#. type: Plain text #: ../src/guide/databases/db-migrations.md -#, no-wrap -msgid "Migrating Multiple Databases " +msgid "" +"For each migration that has been successfully applied, the command will " +"insert a row into a database table named `migration` to record the " +"successful application of the migration. This will allow the migration tool " +"to identify which migrations have been applied and which have not." msgstr "" #. type: Plain text #: ../src/guide/databases/db-migrations.md msgid "" -"By default, migrations are applied to the same database specified by the " -"`db` [application component](structure-application-components.md). If you " -"want them to be applied to a different database, you may specify the `db` " -"command-line option like shown below," +"Sometimes, you may only want to apply one or a few new migrations, instead " +"of all available migrations. You can do so by specifying the number of " +"migrations that you want to apply when running the command. For example, " +"the following command will try to apply the next three available migrations:" msgstr "" #. type: Fenced code block #: ../src/guide/databases/db-migrations.md #, no-wrap -msgid "yii migrate --db=db2\n" +msgid "./yii migrate:up --limit=3\n" msgstr "" -#. type: Plain text +#. type: Title ## #: ../src/guide/databases/db-migrations.md -msgid "The above command will apply migrations to the `db2` database." +#, no-wrap +msgid "Reverting Migrations " msgstr "" #. type: Plain text #: ../src/guide/databases/db-migrations.md msgid "" -"Sometimes it may happen that you want to apply *some* of the migrations to " -"one database, while some others to another database. To achieve this goal, " -"when implementing a migration class you should explicitly specify the DB " -"component ID that the migration would use, like the following:" +"To revert (undo) one or multiple migrations that have been applied before, " +"you can run the following command:" msgstr "" -#. type: Fenced code block (php) +#. type: Fenced code block #: ../src/guide/databases/db-migrations.md #, no-wrap msgid "" -"db = 'db2';\n" -" parent::init();\n" -" }\n" -"}\n" +"./yii migrate:down # revert the most recently applied migration\n" +"./yii migrate:down --limit=3 # revert the most 3 recently applied migrations\n" +"./yii migrate:down --all # revert all migrations\n" msgstr "" #. type: Plain text #: ../src/guide/databases/db-migrations.md +#, no-wrap msgid "" -"The above migration will be applied to `db2`, even if you specify a " -"different database through the `db` command-line option. Note that the " -"migration history will still be recorded in the database specified by the " -"`db` command-line option." +"> Note: Not all migrations are reversible. Trying to revert such migrations will cause an error and stop the\n" +"entire reverting process.\n" +msgstr "" + +#. type: Title ## +#: ../src/guide/databases/db-migrations.md +#, no-wrap +msgid "Redoing Migrations " msgstr "" #. type: Plain text #: ../src/guide/databases/db-migrations.md msgid "" -"If you have multiple migrations that use the same database, it is " -"recommended that you create a base migration class with the above `init()` " -"code. Then each migration class can extend from this base class." +"Redoing migrations means first reverting the specified migrations and then " +"applying again. This can be done as follows:" msgstr "" -#. type: Plain text +#. type: Fenced code block #: ../src/guide/databases/db-migrations.md #, no-wrap msgid "" -"> Tip: Besides setting the [[yii\\db\\Migration::db|db]] property, you can also operate on different databases\n" -"by creating new database connections to them in your migration classes. You then use the [DAO methods](db-dao.md)\n" -"with these connections to manipulate different databases.\n" +"./yii migrate:redo # redo the last applied migration\n" +"./yii migrate:redo --limit=3 # redo the last 3 applied migrations\n" +"./yii migrate:redo --all # redo all migrations\n" msgstr "" #. type: Plain text #: ../src/guide/databases/db-migrations.md -msgid "" -"Another strategy that you can take to migrate multiple databases is to keep " -"migrations for different databases in different migration paths. Then you " -"can migrate these databases in separate commands like the following:" +#, no-wrap +msgid "> Note: If a migration is not reversible, you will not be able to redo it.\n" msgstr "" -#. type: Fenced code block +#. type: Title ## #: ../src/guide/databases/db-migrations.md #, no-wrap -msgid "" -"yii migrate --migrationPath=@app/migrations/db1 --db=db1\n" -"yii migrate --migrationPath=@app/migrations/db2 --db=db2\n" -"...\n" +msgid "Listing Migrations " msgstr "" #. type: Plain text #: ../src/guide/databases/db-migrations.md msgid "" -"The first command will apply migrations in `@app/migrations/db1` to the " -"`db1` database, the second command will apply migrations in `@app/migrations/" -"db2` to `db2`, and so on." +"To list which migrations have been applied and which are not, you may use " +"the following commands:" +msgstr "" + +#. type: Fenced code block +#: ../src/guide/databases/db-migrations.md +#, no-wrap +msgid "" +"./yii migrate/history # showing the last 10 applied migrations\n" +"./yii migrate:history --limit=5 # showing the last 5 applied migrations\n" +"./yii migrate:history --all # showing all applied migrations\n" +"\n" +"./yii migrate:new # showing the first 10 new migrations\n" +"./yii migrate:new --limit=5 # showing the first 5 new migrations\n" +"./yii migrate:new --all # showing all new migrations\n" msgstr "" #. type: Title ### @@ -1159,9 +994,15 @@ msgstr "" msgid "" "Migrations in Yii 2.0 and the [yiisoft/db-migration](https://github.com/" "yiisoft/db-migration/) package are not compatible, and the `migration` table " -"is also not compatible. A probable solution is to use structure dumps and " -"rename the old `migration` table. Upon the initial execution of migrations, " -"a new `migration` table with new fields will be created. All further changes " -"in the database schema are applied using the new `migration` component and " -"recorded in the new migration table." +"is also not compatible." +msgstr "" + +#. type: Plain text +#: ../src/guide/databases/db-migrations.md +msgid "" +"A probable solution is to use structure dumps and rename the old `migration` " +"table. Upon the initial execution of migrations, a new `migration` table " +"with new fields will be created. All further changes in the database schema " +"are applied using the new `migration` component and recorded in the new " +"migration table." msgstr "" diff --git a/_translations/pot/internals_010-code-style.md.pot b/_translations/pot/internals_010-code-style.md.pot index 99b2e744..32d81df3 100644 --- a/_translations/pot/internals_010-code-style.md.pot +++ b/_translations/pot/internals_010-code-style.md.pot @@ -7,7 +7,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" -"POT-Creation-Date: 2025-12-24 08:02+0000\n" +"POT-Creation-Date: 2025-12-27 10:28+0000\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -16,14 +16,20 @@ msgstr "" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: 8bit\n" +#. type: Title ## +#: ../src/guide/databases/db-migrations.md ../src/internals/010-code-style.md +#, no-wrap +msgid "Strings" +msgstr "" + #. type: Title # -#: ../src/en/internals/010-code-style.md +#: ../src/internals/010-code-style.md #, no-wrap msgid "010 — Code style" msgstr "" #. type: Plain text -#: ../src/en/internals/010-code-style.md +#: ../src/internals/010-code-style.md msgid "" "Code formatting used in Yii 3 packages is based on [PSR-1](https://www.php-" "fig.org/psr/psr-1/) and [PSR-12](https://www.php-fig.org/psr/psr-12/) with " @@ -31,34 +37,34 @@ msgid "" msgstr "" #. type: Title ### -#: ../src/en/internals/010-code-style.md ../src/en/internals/017-tags.md -#: ../src/en/internals/018-widgets.md +#: ../src/internals/010-code-style.md ../src/internals/017-tags.md +#: ../src/internals/018-widgets.md #, no-wrap msgid "Names" msgstr "" #. type: Bullet: '- ' -#: ../src/en/internals/010-code-style.md +#: ../src/internals/010-code-style.md msgid "Use English only." msgstr "" #. type: Bullet: '- ' -#: ../src/en/internals/010-code-style.md +#: ../src/internals/010-code-style.md msgid "Use camelCase notation, including abbreviations (e.g., `enableIdn`)." msgstr "" #. type: Bullet: '- ' -#: ../src/en/internals/010-code-style.md +#: ../src/internals/010-code-style.md msgid "Use the shortest possible, but an explanatory name." msgstr "" #. type: Bullet: '- ' -#: ../src/en/internals/010-code-style.md +#: ../src/internals/010-code-style.md msgid "Never trim or abbreviate a name." msgstr "" #. type: Bullet: '- ' -#: ../src/en/internals/010-code-style.md +#: ../src/internals/010-code-style.md msgid "" "Postfix classes, interfaces, traits and variables, which is a [collection]" "(https://en.wikipedia.org/wiki/Collection_(abstract_data_type)), with " @@ -66,76 +72,76 @@ msgid "" msgstr "" #. type: Title ## -#: ../src/en/internals/010-code-style.md +#: ../src/internals/010-code-style.md #, no-wrap msgid "Types" msgstr "" #. type: Bullet: '- ' -#: ../src/en/internals/010-code-style.md +#: ../src/internals/010-code-style.md msgid "" "Declare [argument and return types](https://www.php.net/manual/en/" "migration70.new-features.php) where possible." msgstr "" #. type: Bullet: '- ' -#: ../src/en/internals/010-code-style.md +#: ../src/internals/010-code-style.md msgid "" "[Use types for properties](https://wiki.php.net/rfc/typed_properties_v2)." msgstr "" #. type: Bullet: '- ' -#: ../src/en/internals/010-code-style.md +#: ../src/internals/010-code-style.md msgid "" "Use strict typing. Avoid mixed and union types where possible except " "compatible types such as `string|Stringable`." msgstr "" #. type: Title ## -#: ../src/en/internals/010-code-style.md +#: ../src/internals/010-code-style.md #, no-wrap msgid "Comments" msgstr "" #. type: Plain text -#: ../src/en/internals/010-code-style.md +#: ../src/internals/010-code-style.md msgid "" "Inline comments are to be avoided unless code couldn't be understood without " "them. A good example is a workaround for a bug in a certain PHP version." msgstr "" #. type: Plain text -#: ../src/en/internals/010-code-style.md +#: ../src/internals/010-code-style.md msgid "" "Method comment is necessary except it adds nothing to what method name and " "signature already has." msgstr "" #. type: Plain text -#: ../src/en/internals/010-code-style.md +#: ../src/internals/010-code-style.md msgid "Class comment should describe the purpose of the class." msgstr "" #. type: Plain text -#: ../src/en/internals/010-code-style.md +#: ../src/internals/010-code-style.md msgid "" "[See PHPDoc](https://github.com/yiisoft/docs/blob/master/014-docs.md#phpdoc)." msgstr "" #. type: Title ## -#: ../src/en/internals/010-code-style.md +#: ../src/internals/010-code-style.md #, no-wrap msgid "Formatting" msgstr "" #. type: Title ### -#: ../src/en/internals/010-code-style.md +#: ../src/internals/010-code-style.md #, no-wrap msgid "No alignment" msgstr "" #. type: Plain text -#: ../src/en/internals/010-code-style.md +#: ../src/internals/010-code-style.md msgid "" "Property, variable and constant value assignments shouldn't be aligned. The " "same applies to phpdoc tags. The reason is that aligned statements often " @@ -143,7 +149,7 @@ msgid "" msgstr "" #. type: Fenced code block (php) -#: ../src/en/internals/010-code-style.md +#: ../src/internals/010-code-style.md #, no-wrap msgid "" "final class X\n" @@ -167,13 +173,13 @@ msgid "" msgstr "" #. type: Title ### -#: ../src/en/internals/010-code-style.md +#: ../src/internals/010-code-style.md #, no-wrap msgid "Chain calls" msgstr "" #. type: Plain text -#: ../src/en/internals/010-code-style.md +#: ../src/internals/010-code-style.md msgid "" "Chained calls should be formatted for better readability. If it's a long " "chain that doesn't fit the line length of 120 characters, then each call " @@ -181,7 +187,7 @@ msgid "" msgstr "" #. type: Fenced code block (php) -#: ../src/en/internals/010-code-style.md +#: ../src/internals/010-code-style.md #, no-wrap msgid "" "$object\n" @@ -193,143 +199,137 @@ msgid "" msgstr "" #. type: Plain text -#: ../src/en/internals/010-code-style.md +#: ../src/internals/010-code-style.md msgid "If it's a short chain, it's alright for it to be on a single line:" msgstr "" #. type: Fenced code block (php) -#: ../src/en/internals/010-code-style.md +#: ../src/internals/010-code-style.md #, no-wrap msgid "$object = $object->withName('test');\n" msgstr "" -#. type: Title ## -#: ../src/en/internals/010-code-style.md -#, no-wrap -msgid "Strings" -msgstr "" - #. type: Bullet: '- ' -#: ../src/en/internals/010-code-style.md +#: ../src/internals/010-code-style.md msgid "When no variables involved, use `'Hello!'`" msgstr "" #. type: Bullet: '- ' -#: ../src/en/internals/010-code-style.md +#: ../src/internals/010-code-style.md msgid "To get variables into string prefer `\"Hello, $username!\"`" msgstr "" #. type: Title ## -#: ../src/en/internals/010-code-style.md +#: ../src/internals/010-code-style.md #, no-wrap msgid "Classes and interfaces" msgstr "" #. type: Title ### -#: ../src/en/internals/010-code-style.md +#: ../src/internals/010-code-style.md #, no-wrap msgid "Final by default" msgstr "" #. type: Plain text -#: ../src/en/internals/010-code-style.md +#: ../src/internals/010-code-style.md msgid "Classes should be `final` by default." msgstr "" #. type: Title ### -#: ../src/en/internals/010-code-style.md +#: ../src/internals/010-code-style.md #, no-wrap msgid "Private by default" msgstr "" #. type: Plain text -#: ../src/en/internals/010-code-style.md +#: ../src/internals/010-code-style.md msgid "Constants, properties and methods should be private by default." msgstr "" #. type: Title ### -#: ../src/en/internals/010-code-style.md +#: ../src/internals/010-code-style.md #, no-wrap msgid "Composition over inheritance" msgstr "" #. type: Plain text -#: ../src/en/internals/010-code-style.md +#: ../src/internals/010-code-style.md msgid "Prefer [composition to inheritance](guide/en/concept/di-container.md)." msgstr "" #. type: Title ### -#: ../src/en/internals/010-code-style.md +#: ../src/internals/010-code-style.md #, no-wrap msgid "Property, constant and method order" msgstr "" #. type: Plain text -#: ../src/en/internals/010-code-style.md +#: ../src/internals/010-code-style.md msgid "Order should be the following:" msgstr "" #. type: Bullet: '- ' -#: ../src/en/internals/010-code-style.md +#: ../src/internals/010-code-style.md msgid "Constants" msgstr "" #. type: Bullet: '- ' -#: ../src/en/internals/010-code-style.md +#: ../src/internals/010-code-style.md msgid "Properties" msgstr "" #. type: Title ## -#: ../src/en/internals/010-code-style.md ../src/en/internals/017-tags.md -#: ../src/en/internals/018-widgets.md +#: ../src/internals/010-code-style.md ../src/internals/017-tags.md +#: ../src/internals/018-widgets.md #, no-wrap msgid "Methods" msgstr "" #. type: Plain text -#: ../src/en/internals/010-code-style.md +#: ../src/internals/010-code-style.md msgid "Within each category, items should be sorted by visibility:" msgstr "" #. type: Bullet: '- ' -#: ../src/en/internals/010-code-style.md +#: ../src/internals/010-code-style.md msgid "public" msgstr "" #. type: Bullet: '- ' -#: ../src/en/internals/010-code-style.md +#: ../src/internals/010-code-style.md msgid "protected" msgstr "" #. type: Bullet: '- ' -#: ../src/en/internals/010-code-style.md +#: ../src/internals/010-code-style.md msgid "private" msgstr "" #. type: Title ### -#: ../src/en/internals/010-code-style.md +#: ../src/internals/010-code-style.md #, no-wrap msgid "Abstract classes" msgstr "" #. type: Plain text -#: ../src/en/internals/010-code-style.md +#: ../src/internals/010-code-style.md msgid "Abstract classes *shouldn't* be prefixed or postfixed with `Abstract`." msgstr "" #. type: Title #### -#: ../src/en/internals/010-code-style.md +#: ../src/internals/010-code-style.md #, no-wrap msgid "Immutable methods" msgstr "" #. type: Plain text -#: ../src/en/internals/010-code-style.md +#: ../src/internals/010-code-style.md msgid "Immutable method convention is the following:" msgstr "" #. type: Fenced code block (php) -#: ../src/en/internals/010-code-style.md +#: ../src/internals/010-code-style.md #, no-wrap msgid "" "public function withName(string $name): self\n" @@ -341,30 +341,30 @@ msgid "" msgstr "" #. type: Bullet: '1. ' -#: ../src/en/internals/010-code-style.md +#: ../src/internals/010-code-style.md msgid "Cloned object name is `$new`." msgstr "" #. type: Bullet: '2. ' -#: ../src/en/internals/010-code-style.md +#: ../src/internals/010-code-style.md msgid "Return type is `self`." msgstr "" #. type: Title #### -#: ../src/en/internals/010-code-style.md +#: ../src/internals/010-code-style.md #, no-wrap msgid "Boolean check methods" msgstr "" #. type: Plain text -#: ../src/en/internals/010-code-style.md +#: ../src/internals/010-code-style.md msgid "" "Methods that are there to check if something is true should be named like " "the following:" msgstr "" #. type: Fenced code block (php) -#: ../src/en/internals/010-code-style.md +#: ../src/internals/010-code-style.md #, no-wrap msgid "" "public function isDeleted(): bool;\n" @@ -373,31 +373,31 @@ msgid "" msgstr "" #. type: Title #### -#: ../src/en/internals/010-code-style.md +#: ../src/internals/010-code-style.md #, no-wrap msgid "Flags in methods " msgstr "" #. type: Plain text -#: ../src/en/internals/010-code-style.md +#: ../src/internals/010-code-style.md msgid "" "Boolean flags in methods are better to be avoided. It's a sign the method " "may be doing too much, and there should be two methods instead of one." msgstr "" #. type: Fenced code block (php) -#: ../src/en/internals/010-code-style.md +#: ../src/internals/010-code-style.md #, no-wrap msgid "public function login(bool $refreshPage = true): void;\n" msgstr "" #. type: Plain text -#: ../src/en/internals/010-code-style.md +#: ../src/internals/010-code-style.md msgid "It is better to be two methods:" msgstr "" #. type: Fenced code block (php) -#: ../src/en/internals/010-code-style.md +#: ../src/internals/010-code-style.md #, no-wrap msgid "" "public function login(): void;\n" @@ -405,18 +405,18 @@ msgid "" msgstr "" #. type: Title ## -#: ../src/en/internals/010-code-style.md +#: ../src/internals/010-code-style.md #, no-wrap msgid "Variables" msgstr "" #. type: Plain text -#: ../src/en/internals/010-code-style.md +#: ../src/internals/010-code-style.md msgid "Add an underscore (`_`) prefix for unused variables. For example:" msgstr "" #. type: Fenced code block (php) -#: ../src/en/internals/010-code-style.md +#: ../src/internals/010-code-style.md #, no-wrap msgid "" "foreach ($items as $key => $_value) {\n" @@ -425,18 +425,18 @@ msgid "" msgstr "" #. type: Title ## -#: ../src/en/internals/010-code-style.md +#: ../src/internals/010-code-style.md #, no-wrap msgid "Imports" msgstr "" #. type: Plain text -#: ../src/en/internals/010-code-style.md +#: ../src/internals/010-code-style.md msgid "Prefer importing classes and functions to using fully qualified names:" msgstr "" #. type: Fenced code block (php) -#: ../src/en/internals/010-code-style.md +#: ../src/internals/010-code-style.md #, no-wrap msgid "" "use Yiisoft\\Arrays\\ArrayHelper;\n" @@ -448,22 +448,22 @@ msgid "" msgstr "" #. type: Title ## -#: ../src/en/internals/010-code-style.md +#: ../src/internals/010-code-style.md #, no-wrap msgid "Additional conventions" msgstr "" #. type: Bullet: '- ' -#: ../src/en/internals/010-code-style.md +#: ../src/internals/010-code-style.md msgid "[Namespaces](004-namespaces.md)" msgstr "" #. type: Bullet: '- ' -#: ../src/en/internals/010-code-style.md +#: ../src/internals/010-code-style.md msgid "[Exceptions](007-exceptions.md)" msgstr "" #. type: Bullet: '- ' -#: ../src/en/internals/010-code-style.md +#: ../src/internals/010-code-style.md msgid "[Interfaces](008-interfaces.md)" msgstr "" diff --git a/src/es/guide/databases/db-migrations.md b/src/es/guide/databases/db-migrations.md index dd6a9e29..196ac403 100644 --- a/src/es/guide/databases/db-migrations.md +++ b/src/es/guide/databases/db-migrations.md @@ -78,16 +78,22 @@ Add the following configuration to `config/common/params.php`: ], ``` +If you want to place migrations elsewhere, you can define the path in +`newMigrationPath`. If your migrations to be applied are from multiple +sources, such as external modules, `sourcePaths` could be used to define +these. + You need a database connection configured as well. See [Working with databases](../start/databases.md) for an example of configuring it for PostgreSQL. -### Creating a migration +## Creating a migration To create a new empty migration, run the following command: ```sh -make yii migrate:create +make shell +./yii migrate:create ``` The required `name` argument gives a brief description about the new @@ -96,7 +102,8 @@ migration. For example, if the migration is about creating a new table named command: ``` -make yii migrate:create create_news_table +make shell +./yii migrate:create create_news_table ``` @@ -171,8 +178,87 @@ final class M251225221906CreateNewsTable implements RevertibleMigrationInterface } ``` -TODO: explain $b and $qb -Below is the list of all these database accessing methods: +Migration builder `$b` in the above manages database schema while the column +builder `$cb` manages column types. Both allow using *abstract types*. When +a migration is applied to a particular database, the abstract types will be +translated into the corresponding database physical types and corresponding +SQL to define them. + +Methods available in migration builder belong to the following types: + +- Raw queries + - getDb — to get database connection instance. + - execute — to execute raw SQL query. +- Data + - insert / update / delete + - batchInsert + - upsert +- Tables and views + - createTable / renameTable / dropTable + - truncateTable + - addCommentOnTable / dropCommentFromTable + - createView / dropView +- Columns + - addColumn / renameColumn / alterColumn / dropColumn + - addCommentOnColumn / dropCommentFromColumn +- Keys and indexes + - addPrimaryKey / dropPrimaryKey + - addForeignKey / dropForeignKey + - createIndex / dropIndex + +Additionally, there's a `columnBuilder()` which is used to obtain a column +builder as in example above. The builder has static methods that define +various column types: + +- Keys + - primaryKey + - smallPrimaryKey + - bigPrimaryKey + - uuidPrimaryKey +- Boolean + - boolean +- Numbers + - bit + - tinyint + - smallint + - integer + - bigint + - flat + - double + - decimal +- Strings + - char + - string + - text +- Date and time + - timestamp + - datetime + - datetimeWithTimezone + - time + - timeWithTimezone + - date +- Special types + - money + - binary + - uuid + - array + - structured + - json +- enum + +All the above methods create a base type which could be adjusted with +additional methods: + +- null / notNull +- defaultValue +- unique +- scale / size / unsigned +- primaryKey / autoIncrement +- check +- comment +- computed +- extra +- reference ### Irreversible migrations @@ -184,146 +270,31 @@ you should implement `Yiisoft\Db\Migration\MigrationInterface` that has `up()` only. -### Transactional migrations (TODO: update!!!) +### Transactional migrations While performing complex DB migrations, it is important to ensure each migration to either succeed or fail as a whole so that the database can maintain integrity and consistency. To achieve this goal, it is recommended -that you enclose the DB operations of each migration in a -[transaction](db-dao.md#performing-transactions). +that you may enclose the DB operations of each migration in a transaction +automatically by adding `TransactionalMigrationInterface` to `implements` of +your migration. -An even easier way of implementing transactional migrations is to put -migration code in the `safeUp()` and `safeDown()` methods. These two methods -differ from `up()` and `down()` in that they are enclosed implicitly in a -transaction. As a result, if any operation in these methods fails, all +As a result, if any operation in the `up()` or `down()` method fails, all prior operations will be rolled back automatically. -In the following example, besides creating the `news` table we also insert -an initial row into this table. - -```php -createTable('news', [ - 'id' => $this->primaryKey(), - 'title' => $this->string()->notNull(), - 'content' => $this->text(), - ]); - - $this->insert('news', [ - 'title' => 'test 1', - 'content' => 'content 1', - ]); - } - - public function safeDown() - { - $this->delete('news', ['id' => 1]); - $this->dropTable('news'); - } -} -``` - -Note that usually when you perform multiple DB operations in `safeUp()`, you -should reverse their execution order in `safeDown()`. In the above example -we first create the table and then insert a row in `safeUp()`; while in -`safeDown()` we first delete the row and then drop the table. - > Note: Not all DBMS support transactions. And some DB queries cannot be put into a transaction. For some examples, -please refer to [implicit commit](https://dev.mysql.com/doc/refman/5.7/en/implicit-commit.html). If this is the case, -you should still implement `up()` and `down()`, instead. - -TODO: TransactionalMigrationInterface - - - -## TODO: update - -The base migration class [[yii\db\Migration]] exposes a database connection -via the [[yii\db\Migration::db|db]] property. You can use it to manipulate -the database schema using the methods as described in [Working with Database -Schema](db-dao.md#database-schema). +please refer to [implicit commit](https://dev.mysql.com/doc/refman/5.7/en/implicit-commit.html). -Rather than using physical types, when creating a table or column you should use *abstract types* -so that your migrations are independent of specific DBMS. The [[yii\db\Schema]] class defines -a set of constants to represent the supported abstract types. These constants are named in the format -of `TYPE_`. For example, `TYPE_PK` refers to auto-incremental primary key type; `TYPE_STRING` -refers to a string type. When a migration is applied to a particular database, the abstract types -will be translated into the corresponding physical types. In the case of MySQL, `TYPE_PK` will be turned -into `int(11) NOT NULL AUTO_INCREMENT PRIMARY KEY`, while `TYPE_STRING` becomes `varchar(255)`. +## Generating a migration -You can append additional constraints when using abstract types. In the -above example, ` NOT NULL` is appended to `Schema::TYPE_STRING` to specify -that the column cannot be `null`. - -> Info: The mapping between abstract types and physical types is specified by -the [[yii\db\QueryBuilder::$typeMap|$typeMap]] property in each concrete `QueryBuilder` class. - -Since version 2.0.6, you can make use of the newly introduced schema builder -which provides more convenient way of defining column schema. So the -migration above could be written like the following: - -```php -createTable('news', [ - 'id' => $this->primaryKey(), - 'title' => $this->string()->notNull(), - 'content' => $this->text(), - ]); - } - - public function down() - { - $this->dropTable('news'); - } -} -``` - -A list of all available methods for defining the column types is available -in the API documentation of [[yii\db\SchemaBuilderTrait]]. - -> Info: The generated file permissions and ownership will be determined by the current environment. This might lead to -inaccessible files. This could, for example, happen when the migration is created within a docker container -and the files are edited on the host. In this case the `newFileMode` and/or `newFileOwnership` of the MigrateController -can be changed. E.g. in the application config: - ```php - [ - 'migrate' => [ - 'class' => 'yii\console\controllers\MigrateController', - 'newFileOwnership' => '1000:1000', # Default WSL user id - 'newFileMode' => 0660, - ], - ], - ]; - ``` - -## Generating Migrations (TODO: likely is OK but...) - -The command provides a convenient way to create migrations using the -provided -[view](https://github.com/yiisoft/db-migration/tree/master/resources/views): +Instead of writing migrations by hand, the command provides a convenient way +generate some of the code. ```shell -make yii migrate:create my_first_table --command=table --fields=name,example --table-comment=my_first_table +make shell +./yii migrate:create -- my_first_table --command=table --fields=name,example --table-comment=my_first_table ``` - - That would generate the following: ```php @@ -338,19 +309,21 @@ use Yiisoft\Db\Migration\RevertibleMigrationInterface; use Yiisoft\Db\Migration\TransactionalMigrationInterface; /** - * Handles the creation of a table `my_first_table`. + * Handles the creation of table `my_first_table`. */ -final class M240115143455CreateMyFirstTableTable implements RevertibleMigrationInterface, TransactionalMigrationInterface +final class M251227095006CreateMyFirstTableTable implements RevertibleMigrationInterface, TransactionalMigrationInterface { public function up(MigrationBuilder $b): void { + $columnBuilder = $b->columnBuilder(); + $b->createTable('my_first_table', [ - 'id' => $b->primaryKey(), + 'id' => $columnBuilder::primaryKey(), 'name', 'example', ]); - - $b->addCommentOnTable('my_first_table', 'dest'); + + $b->addCommentOnTable('my_first_table', 'my_first_table'); } public function down(MigrationBuilder $b): void @@ -360,9 +333,17 @@ final class M240115143455CreateMyFirstTableTable implements RevertibleMigrationI } ``` -For more information -[see](https://github.com/yiisoft/db-migration/tree/master/docs/guide/en) +Commands available are: +- create - empty migration. +- table - creating a table. Use `--fields` specify a list of fields to + use. Types could be specified as well such as + `id:primaryKey,name:string:defaultValue("Alex"),user_id:integer:foreignKey,category_id2:integer:foreignKey(category + id2)`. +- dropTable - dropping a table. +- addColumn - adding a column. +- dropColumn - dropping a column. +- junction - creating a junction table. Use `--and` specify a second table. ## Applying Migrations @@ -370,62 +351,38 @@ To upgrade a database to its latest structure, you should apply all available new migrations using the following command: ``` -yii migrate +./yii migrate:up ``` This command will list all migrations that have not been applied so far. If you confirm that you want to apply these migrations, it will run the `up()` -or `safeUp()` method in every new migration class, one after another, in the -order of their timestamp values. If any of the migrations fails, the command -will quit without applying the rest of the migrations. - -> Tip: In case you don't have command line at your server you may try [web shell](https://github.com/samdark/yii2-webshell) -> extension. +method in every new migration class, one after another, in the order of +their timestamp values. If any of the migrations fails, the command will +quit without applying the rest of the migrations. For each migration that has been successfully applied, the command will insert a row into a database table named `migration` to record the successful application of the migration. This will allow the migration tool to identify which migrations have been applied and which have not. -> Info: The migration tool will automatically create the `migration` table in the database specified by -the [[yii\console\controllers\MigrateController::db|db]] option of the command. By default, the database -is specified by the `db` [application component](structure-application-components.md). - Sometimes, you may only want to apply one or a few new migrations, instead of all available migrations. You can do so by specifying the number of migrations that you want to apply when running the command. For example, the following command will try to apply the next three available migrations: ``` -yii migrate 3 -``` - -You can also explicitly specify a particular migration to which the database -should be migrated by using the `migrate/to` command in one of the following -formats: - -``` -yii migrate/to 150101_185401 # using timestamp to specify the migration -yii migrate/to "2015-01-01 18:54:01" # using a string that can be parsed by strtotime() -yii migrate/to m150101_185401_create_news_table # using full name -yii migrate/to 1392853618 # using UNIX timestamp +./yii migrate:up --limit=3 ``` -If there are any unapplied migrations earlier than the specified one, they -will all be applied before the specified migration is applied. - -If the specified migration has already been applied before, any later -applied migrations will be reverted. - - ## Reverting Migrations To revert (undo) one or multiple migrations that have been applied before, you can run the following command: ``` -yii migrate/down # revert the most recently applied migration -yii migrate/down 3 # revert the most 3 recently applied migrations +./yii migrate:down # revert the most recently applied migration +./yii migrate:down --limit=3 # revert the most 3 recently applied migrations +./yii migrate:down --all # revert all migrations ``` > Note: Not all migrations are reversible. Trying to revert such migrations will cause an error and stop the @@ -438,238 +395,36 @@ Redoing migrations means first reverting the specified migrations and then applying again. This can be done as follows: ``` -yii migrate/redo # redo the last applied migration -yii migrate/redo 3 # redo the last 3 applied migrations +./yii migrate:redo # redo the last applied migration +./yii migrate:redo --limit=3 # redo the last 3 applied migrations +./yii migrate:redo --all # redo all migrations ``` > Note: If a migration is not reversible, you will not be able to redo it. -## Refreshing Migrations - -Since Yii 2.0.13 you can delete all tables and foreign keys from the -database and apply all migrations from the beginning. - -``` -yii migrate/fresh # truncate the database and apply all migrations from the beginning -``` - ## Listing Migrations To list which migrations have been applied and which are not, you may use the following commands: ``` -yii migrate/history # showing the last 10 applied migrations -yii migrate/history 5 # showing the last 5 applied migrations -yii migrate/history all # showing all applied migrations - -yii migrate/new # showing the first 10 new migrations -yii migrate/new 5 # showing the first 5 new migrations -yii migrate/new all # showing all new migrations -``` +./yii migrate/history # showing the last 10 applied migrations +./yii migrate:history --limit=5 # showing the last 5 applied migrations +./yii migrate:history --all # showing all applied migrations - -## Modifying Migration History - -Instead of actually applying or reverting migrations, sometimes you may -simply want to mark that your database has been upgraded to a particular -migration. This often happens when you manually change the database to a -particular state and you do not want the migration(s) for that change to be -re-applied later. You can achieve this goal with the following command: - -``` -yii migrate/mark 150101_185401 # using timestamp to specify the migration -yii migrate/mark "2015-01-01 18:54:01" # using a string that can be parsed by strtotime() -yii migrate/mark m150101_185401_create_news_table # using full name -yii migrate/mark 1392853618 # using UNIX timestamp +./yii migrate:new # showing the first 10 new migrations +./yii migrate:new --limit=5 # showing the first 5 new migrations +./yii migrate:new --all # showing all new migrations ``` -The command will modify the `migration` table by adding or deleting certain -rows to indicate that the database has been applied migrations to the -specified one. No migrations will be applied or reverted by this command. - - -## Customizing Migrations - -There are several ways to customize the migration command. - - -### Using Command Line Options - -The migration command comes with a few command-line options that can be used -to customize its behaviors: - -* `interactive`: boolean (defaults to `true`), specifies whether to perform - migrations in an interactive mode. When this is `true`, the user will be - prompted before the command performs certain actions. You may want to set - this to `false` if the command is being used in a background process. - -* `migrationPath`: string|array (defaults to `@app/migrations`), specifies - the directory storing all migration class files. This can be specified as - either a directory path or a path [alias](concept-aliases.md). Note that - the directory must exist, or the command may trigger an error. Since - version 2.0.12 an array can be specified for loading migrations from - multiple sources. - -* `migrationTable`: string (defaults to `migration`), specifies the name of - the database table for storing migration history information. The table - will be automatically created by the command if it does not exist. You - may also manually create it using the structure `version varchar(255) - primary key, apply_time integer`. - -* `db`: string (defaults to `db`), specifies the ID of the database - [application component](structure-application-components.md). It - represents the database that will be migrated using this command. - -* `templateFile`: string (defaults to `@yii/views/migration.php`), specifies - the path of the template file that is used for generating skeleton - migration class files. This can be specified as either a file path or a - path [alias](concept-aliases.md). The template file is a PHP script in - which you can use a predefined variable named `$className` to get the - migration class name. - -* `generatorTemplateFiles`: array (defaults to `[ - 'create_table' => '@yii/views/createTableMigration.php', - 'drop_table' => '@yii/views/dropTableMigration.php', - 'add_column' => '@yii/views/addColumnMigration.php', - 'drop_column' => '@yii/views/dropColumnMigration.php', - 'create_junction' => '@yii/views/createTableMigration.php' - ]`), specifies template files for generating migration code. See "[Generating Migrations](#generating-migrations)" - for more details. - -* `fields`: array of column definition strings used for creating migration - code. Defaults to `[]`. The format of each definition is - `COLUMN_NAME:COLUMN_TYPE:COLUMN_DECORATOR`. For example, - `--fields=name:string(12):notNull` produces a string column of size 12 - which is not `null`. - -The following example shows how you can use these options. - -For example, if we want to migrate a `forum` module whose migration files -are located within the module's `migrations` directory, we can use the -following command: - -``` -# migrate the migrations in a forum module non-interactively -yii migrate --migrationPath=@app/modules/forum/migrations --interactive=0 -``` - -### Separated Migrations - - -Sometimes using single migration history for all project migrations is not -desirable. For example: you may install some 'blog' extension, which -contains fully separated functionality and contain its own migrations, which -should not affect the ones dedicated to main project functionality. - -If you want several migrations to be applied and tracked down completely -separated from each other, you can configure multiple migration commands -which will use different namespaces and migration history tables: - -```php -return [ - 'controllerMap' => [ - // Common migrations for the whole application - 'migrate-app' => [ - 'class' => 'yii\console\controllers\MigrateController', - 'migrationNamespaces' => ['app\migrations'], - 'migrationTable' => 'migration_app', - 'migrationPath' => null, - ], - // Migrations for the specific project's module - 'migrate-module' => [ - 'class' => 'yii\console\controllers\MigrateController', - 'migrationNamespaces' => ['module\migrations'], - 'migrationTable' => 'migration_module', - 'migrationPath' => null, - ], - // Migrations for the specific extension - 'migrate-rbac' => [ - 'class' => 'yii\console\controllers\MigrateController', - 'migrationPath' => '@yii/rbac/migrations', - 'migrationTable' => 'migration_rbac', - ], - ], -]; -``` - -Note that to synchronize database you now need to run multiple commands -instead of one: - -``` -yii migrate-app -yii migrate-module -yii migrate-rbac -``` - -## Migrating Multiple Databases - -By default, migrations are applied to the same database specified by the -`db` [application component](structure-application-components.md). If you -want them to be applied to a different database, you may specify the `db` -command-line option like shown below, - -``` -yii migrate --db=db2 -``` - -The above command will apply migrations to the `db2` database. - -Sometimes it may happen that you want to apply *some* of the migrations to -one database, while some others to another database. To achieve this goal, -when implementing a migration class you should explicitly specify the DB -component ID that the migration would use, like the following: - -```php -db = 'db2'; - parent::init(); - } -} -``` - -The above migration will be applied to `db2`, even if you specify a -different database through the `db` command-line option. Note that the -migration history will still be recorded in the database specified by the -`db` command-line option. - -If you have multiple migrations that use the same database, it is -recommended that you create a base migration class with the above `init()` -code. Then each migration class can extend from this base class. - -> Tip: Besides setting the [[yii\db\Migration::db|db]] property, you can also operate on different databases -by creating new database connections to them in your migration classes. You then use the [DAO methods](db-dao.md) -with these connections to manipulate different databases. - -Another strategy that you can take to migrate multiple databases is to keep -migrations for different databases in different migration paths. Then you -can migrate these databases in separate commands like the following: - -``` -yii migrate --migrationPath=@app/migrations/db1 --db=db1 -yii migrate --migrationPath=@app/migrations/db2 --db=db2 -... -``` - -The first command will apply migrations in `@app/migrations/db1` to the -`db1` database, the second command will apply migrations in -`@app/migrations/db2` to `db2`, and so on. - ### Upgrading from Yii 2.0 Migrations in Yii 2.0 and the [yiisoft/db-migration](https://github.com/yiisoft/db-migration/) package are -not compatible, and the `migration` table is also not compatible. A -probable solution is to use structure dumps and rename the old `migration` +not compatible, and the `migration` table is also not compatible. + +A probable solution is to use structure dumps and rename the old `migration` table. Upon the initial execution of migrations, a new `migration` table with new fields will be created. All further changes in the database schema are applied using the new `migration` component and recorded in the new migration table. - diff --git a/src/id/guide/databases/db-migrations.md b/src/id/guide/databases/db-migrations.md index dd6a9e29..196ac403 100644 --- a/src/id/guide/databases/db-migrations.md +++ b/src/id/guide/databases/db-migrations.md @@ -78,16 +78,22 @@ Add the following configuration to `config/common/params.php`: ], ``` +If you want to place migrations elsewhere, you can define the path in +`newMigrationPath`. If your migrations to be applied are from multiple +sources, such as external modules, `sourcePaths` could be used to define +these. + You need a database connection configured as well. See [Working with databases](../start/databases.md) for an example of configuring it for PostgreSQL. -### Creating a migration +## Creating a migration To create a new empty migration, run the following command: ```sh -make yii migrate:create +make shell +./yii migrate:create ``` The required `name` argument gives a brief description about the new @@ -96,7 +102,8 @@ migration. For example, if the migration is about creating a new table named command: ``` -make yii migrate:create create_news_table +make shell +./yii migrate:create create_news_table ``` @@ -171,8 +178,87 @@ final class M251225221906CreateNewsTable implements RevertibleMigrationInterface } ``` -TODO: explain $b and $qb -Below is the list of all these database accessing methods: +Migration builder `$b` in the above manages database schema while the column +builder `$cb` manages column types. Both allow using *abstract types*. When +a migration is applied to a particular database, the abstract types will be +translated into the corresponding database physical types and corresponding +SQL to define them. + +Methods available in migration builder belong to the following types: + +- Raw queries + - getDb — to get database connection instance. + - execute — to execute raw SQL query. +- Data + - insert / update / delete + - batchInsert + - upsert +- Tables and views + - createTable / renameTable / dropTable + - truncateTable + - addCommentOnTable / dropCommentFromTable + - createView / dropView +- Columns + - addColumn / renameColumn / alterColumn / dropColumn + - addCommentOnColumn / dropCommentFromColumn +- Keys and indexes + - addPrimaryKey / dropPrimaryKey + - addForeignKey / dropForeignKey + - createIndex / dropIndex + +Additionally, there's a `columnBuilder()` which is used to obtain a column +builder as in example above. The builder has static methods that define +various column types: + +- Keys + - primaryKey + - smallPrimaryKey + - bigPrimaryKey + - uuidPrimaryKey +- Boolean + - boolean +- Numbers + - bit + - tinyint + - smallint + - integer + - bigint + - flat + - double + - decimal +- Strings + - char + - string + - text +- Date and time + - timestamp + - datetime + - datetimeWithTimezone + - time + - timeWithTimezone + - date +- Special types + - money + - binary + - uuid + - array + - structured + - json +- enum + +All the above methods create a base type which could be adjusted with +additional methods: + +- null / notNull +- defaultValue +- unique +- scale / size / unsigned +- primaryKey / autoIncrement +- check +- comment +- computed +- extra +- reference ### Irreversible migrations @@ -184,146 +270,31 @@ you should implement `Yiisoft\Db\Migration\MigrationInterface` that has `up()` only. -### Transactional migrations (TODO: update!!!) +### Transactional migrations While performing complex DB migrations, it is important to ensure each migration to either succeed or fail as a whole so that the database can maintain integrity and consistency. To achieve this goal, it is recommended -that you enclose the DB operations of each migration in a -[transaction](db-dao.md#performing-transactions). +that you may enclose the DB operations of each migration in a transaction +automatically by adding `TransactionalMigrationInterface` to `implements` of +your migration. -An even easier way of implementing transactional migrations is to put -migration code in the `safeUp()` and `safeDown()` methods. These two methods -differ from `up()` and `down()` in that they are enclosed implicitly in a -transaction. As a result, if any operation in these methods fails, all +As a result, if any operation in the `up()` or `down()` method fails, all prior operations will be rolled back automatically. -In the following example, besides creating the `news` table we also insert -an initial row into this table. - -```php -createTable('news', [ - 'id' => $this->primaryKey(), - 'title' => $this->string()->notNull(), - 'content' => $this->text(), - ]); - - $this->insert('news', [ - 'title' => 'test 1', - 'content' => 'content 1', - ]); - } - - public function safeDown() - { - $this->delete('news', ['id' => 1]); - $this->dropTable('news'); - } -} -``` - -Note that usually when you perform multiple DB operations in `safeUp()`, you -should reverse their execution order in `safeDown()`. In the above example -we first create the table and then insert a row in `safeUp()`; while in -`safeDown()` we first delete the row and then drop the table. - > Note: Not all DBMS support transactions. And some DB queries cannot be put into a transaction. For some examples, -please refer to [implicit commit](https://dev.mysql.com/doc/refman/5.7/en/implicit-commit.html). If this is the case, -you should still implement `up()` and `down()`, instead. - -TODO: TransactionalMigrationInterface - - - -## TODO: update - -The base migration class [[yii\db\Migration]] exposes a database connection -via the [[yii\db\Migration::db|db]] property. You can use it to manipulate -the database schema using the methods as described in [Working with Database -Schema](db-dao.md#database-schema). +please refer to [implicit commit](https://dev.mysql.com/doc/refman/5.7/en/implicit-commit.html). -Rather than using physical types, when creating a table or column you should use *abstract types* -so that your migrations are independent of specific DBMS. The [[yii\db\Schema]] class defines -a set of constants to represent the supported abstract types. These constants are named in the format -of `TYPE_`. For example, `TYPE_PK` refers to auto-incremental primary key type; `TYPE_STRING` -refers to a string type. When a migration is applied to a particular database, the abstract types -will be translated into the corresponding physical types. In the case of MySQL, `TYPE_PK` will be turned -into `int(11) NOT NULL AUTO_INCREMENT PRIMARY KEY`, while `TYPE_STRING` becomes `varchar(255)`. +## Generating a migration -You can append additional constraints when using abstract types. In the -above example, ` NOT NULL` is appended to `Schema::TYPE_STRING` to specify -that the column cannot be `null`. - -> Info: The mapping between abstract types and physical types is specified by -the [[yii\db\QueryBuilder::$typeMap|$typeMap]] property in each concrete `QueryBuilder` class. - -Since version 2.0.6, you can make use of the newly introduced schema builder -which provides more convenient way of defining column schema. So the -migration above could be written like the following: - -```php -createTable('news', [ - 'id' => $this->primaryKey(), - 'title' => $this->string()->notNull(), - 'content' => $this->text(), - ]); - } - - public function down() - { - $this->dropTable('news'); - } -} -``` - -A list of all available methods for defining the column types is available -in the API documentation of [[yii\db\SchemaBuilderTrait]]. - -> Info: The generated file permissions and ownership will be determined by the current environment. This might lead to -inaccessible files. This could, for example, happen when the migration is created within a docker container -and the files are edited on the host. In this case the `newFileMode` and/or `newFileOwnership` of the MigrateController -can be changed. E.g. in the application config: - ```php - [ - 'migrate' => [ - 'class' => 'yii\console\controllers\MigrateController', - 'newFileOwnership' => '1000:1000', # Default WSL user id - 'newFileMode' => 0660, - ], - ], - ]; - ``` - -## Generating Migrations (TODO: likely is OK but...) - -The command provides a convenient way to create migrations using the -provided -[view](https://github.com/yiisoft/db-migration/tree/master/resources/views): +Instead of writing migrations by hand, the command provides a convenient way +generate some of the code. ```shell -make yii migrate:create my_first_table --command=table --fields=name,example --table-comment=my_first_table +make shell +./yii migrate:create -- my_first_table --command=table --fields=name,example --table-comment=my_first_table ``` - - That would generate the following: ```php @@ -338,19 +309,21 @@ use Yiisoft\Db\Migration\RevertibleMigrationInterface; use Yiisoft\Db\Migration\TransactionalMigrationInterface; /** - * Handles the creation of a table `my_first_table`. + * Handles the creation of table `my_first_table`. */ -final class M240115143455CreateMyFirstTableTable implements RevertibleMigrationInterface, TransactionalMigrationInterface +final class M251227095006CreateMyFirstTableTable implements RevertibleMigrationInterface, TransactionalMigrationInterface { public function up(MigrationBuilder $b): void { + $columnBuilder = $b->columnBuilder(); + $b->createTable('my_first_table', [ - 'id' => $b->primaryKey(), + 'id' => $columnBuilder::primaryKey(), 'name', 'example', ]); - - $b->addCommentOnTable('my_first_table', 'dest'); + + $b->addCommentOnTable('my_first_table', 'my_first_table'); } public function down(MigrationBuilder $b): void @@ -360,9 +333,17 @@ final class M240115143455CreateMyFirstTableTable implements RevertibleMigrationI } ``` -For more information -[see](https://github.com/yiisoft/db-migration/tree/master/docs/guide/en) +Commands available are: +- create - empty migration. +- table - creating a table. Use `--fields` specify a list of fields to + use. Types could be specified as well such as + `id:primaryKey,name:string:defaultValue("Alex"),user_id:integer:foreignKey,category_id2:integer:foreignKey(category + id2)`. +- dropTable - dropping a table. +- addColumn - adding a column. +- dropColumn - dropping a column. +- junction - creating a junction table. Use `--and` specify a second table. ## Applying Migrations @@ -370,62 +351,38 @@ To upgrade a database to its latest structure, you should apply all available new migrations using the following command: ``` -yii migrate +./yii migrate:up ``` This command will list all migrations that have not been applied so far. If you confirm that you want to apply these migrations, it will run the `up()` -or `safeUp()` method in every new migration class, one after another, in the -order of their timestamp values. If any of the migrations fails, the command -will quit without applying the rest of the migrations. - -> Tip: In case you don't have command line at your server you may try [web shell](https://github.com/samdark/yii2-webshell) -> extension. +method in every new migration class, one after another, in the order of +their timestamp values. If any of the migrations fails, the command will +quit without applying the rest of the migrations. For each migration that has been successfully applied, the command will insert a row into a database table named `migration` to record the successful application of the migration. This will allow the migration tool to identify which migrations have been applied and which have not. -> Info: The migration tool will automatically create the `migration` table in the database specified by -the [[yii\console\controllers\MigrateController::db|db]] option of the command. By default, the database -is specified by the `db` [application component](structure-application-components.md). - Sometimes, you may only want to apply one or a few new migrations, instead of all available migrations. You can do so by specifying the number of migrations that you want to apply when running the command. For example, the following command will try to apply the next three available migrations: ``` -yii migrate 3 -``` - -You can also explicitly specify a particular migration to which the database -should be migrated by using the `migrate/to` command in one of the following -formats: - -``` -yii migrate/to 150101_185401 # using timestamp to specify the migration -yii migrate/to "2015-01-01 18:54:01" # using a string that can be parsed by strtotime() -yii migrate/to m150101_185401_create_news_table # using full name -yii migrate/to 1392853618 # using UNIX timestamp +./yii migrate:up --limit=3 ``` -If there are any unapplied migrations earlier than the specified one, they -will all be applied before the specified migration is applied. - -If the specified migration has already been applied before, any later -applied migrations will be reverted. - - ## Reverting Migrations To revert (undo) one or multiple migrations that have been applied before, you can run the following command: ``` -yii migrate/down # revert the most recently applied migration -yii migrate/down 3 # revert the most 3 recently applied migrations +./yii migrate:down # revert the most recently applied migration +./yii migrate:down --limit=3 # revert the most 3 recently applied migrations +./yii migrate:down --all # revert all migrations ``` > Note: Not all migrations are reversible. Trying to revert such migrations will cause an error and stop the @@ -438,238 +395,36 @@ Redoing migrations means first reverting the specified migrations and then applying again. This can be done as follows: ``` -yii migrate/redo # redo the last applied migration -yii migrate/redo 3 # redo the last 3 applied migrations +./yii migrate:redo # redo the last applied migration +./yii migrate:redo --limit=3 # redo the last 3 applied migrations +./yii migrate:redo --all # redo all migrations ``` > Note: If a migration is not reversible, you will not be able to redo it. -## Refreshing Migrations - -Since Yii 2.0.13 you can delete all tables and foreign keys from the -database and apply all migrations from the beginning. - -``` -yii migrate/fresh # truncate the database and apply all migrations from the beginning -``` - ## Listing Migrations To list which migrations have been applied and which are not, you may use the following commands: ``` -yii migrate/history # showing the last 10 applied migrations -yii migrate/history 5 # showing the last 5 applied migrations -yii migrate/history all # showing all applied migrations - -yii migrate/new # showing the first 10 new migrations -yii migrate/new 5 # showing the first 5 new migrations -yii migrate/new all # showing all new migrations -``` +./yii migrate/history # showing the last 10 applied migrations +./yii migrate:history --limit=5 # showing the last 5 applied migrations +./yii migrate:history --all # showing all applied migrations - -## Modifying Migration History - -Instead of actually applying or reverting migrations, sometimes you may -simply want to mark that your database has been upgraded to a particular -migration. This often happens when you manually change the database to a -particular state and you do not want the migration(s) for that change to be -re-applied later. You can achieve this goal with the following command: - -``` -yii migrate/mark 150101_185401 # using timestamp to specify the migration -yii migrate/mark "2015-01-01 18:54:01" # using a string that can be parsed by strtotime() -yii migrate/mark m150101_185401_create_news_table # using full name -yii migrate/mark 1392853618 # using UNIX timestamp +./yii migrate:new # showing the first 10 new migrations +./yii migrate:new --limit=5 # showing the first 5 new migrations +./yii migrate:new --all # showing all new migrations ``` -The command will modify the `migration` table by adding or deleting certain -rows to indicate that the database has been applied migrations to the -specified one. No migrations will be applied or reverted by this command. - - -## Customizing Migrations - -There are several ways to customize the migration command. - - -### Using Command Line Options - -The migration command comes with a few command-line options that can be used -to customize its behaviors: - -* `interactive`: boolean (defaults to `true`), specifies whether to perform - migrations in an interactive mode. When this is `true`, the user will be - prompted before the command performs certain actions. You may want to set - this to `false` if the command is being used in a background process. - -* `migrationPath`: string|array (defaults to `@app/migrations`), specifies - the directory storing all migration class files. This can be specified as - either a directory path or a path [alias](concept-aliases.md). Note that - the directory must exist, or the command may trigger an error. Since - version 2.0.12 an array can be specified for loading migrations from - multiple sources. - -* `migrationTable`: string (defaults to `migration`), specifies the name of - the database table for storing migration history information. The table - will be automatically created by the command if it does not exist. You - may also manually create it using the structure `version varchar(255) - primary key, apply_time integer`. - -* `db`: string (defaults to `db`), specifies the ID of the database - [application component](structure-application-components.md). It - represents the database that will be migrated using this command. - -* `templateFile`: string (defaults to `@yii/views/migration.php`), specifies - the path of the template file that is used for generating skeleton - migration class files. This can be specified as either a file path or a - path [alias](concept-aliases.md). The template file is a PHP script in - which you can use a predefined variable named `$className` to get the - migration class name. - -* `generatorTemplateFiles`: array (defaults to `[ - 'create_table' => '@yii/views/createTableMigration.php', - 'drop_table' => '@yii/views/dropTableMigration.php', - 'add_column' => '@yii/views/addColumnMigration.php', - 'drop_column' => '@yii/views/dropColumnMigration.php', - 'create_junction' => '@yii/views/createTableMigration.php' - ]`), specifies template files for generating migration code. See "[Generating Migrations](#generating-migrations)" - for more details. - -* `fields`: array of column definition strings used for creating migration - code. Defaults to `[]`. The format of each definition is - `COLUMN_NAME:COLUMN_TYPE:COLUMN_DECORATOR`. For example, - `--fields=name:string(12):notNull` produces a string column of size 12 - which is not `null`. - -The following example shows how you can use these options. - -For example, if we want to migrate a `forum` module whose migration files -are located within the module's `migrations` directory, we can use the -following command: - -``` -# migrate the migrations in a forum module non-interactively -yii migrate --migrationPath=@app/modules/forum/migrations --interactive=0 -``` - -### Separated Migrations - - -Sometimes using single migration history for all project migrations is not -desirable. For example: you may install some 'blog' extension, which -contains fully separated functionality and contain its own migrations, which -should not affect the ones dedicated to main project functionality. - -If you want several migrations to be applied and tracked down completely -separated from each other, you can configure multiple migration commands -which will use different namespaces and migration history tables: - -```php -return [ - 'controllerMap' => [ - // Common migrations for the whole application - 'migrate-app' => [ - 'class' => 'yii\console\controllers\MigrateController', - 'migrationNamespaces' => ['app\migrations'], - 'migrationTable' => 'migration_app', - 'migrationPath' => null, - ], - // Migrations for the specific project's module - 'migrate-module' => [ - 'class' => 'yii\console\controllers\MigrateController', - 'migrationNamespaces' => ['module\migrations'], - 'migrationTable' => 'migration_module', - 'migrationPath' => null, - ], - // Migrations for the specific extension - 'migrate-rbac' => [ - 'class' => 'yii\console\controllers\MigrateController', - 'migrationPath' => '@yii/rbac/migrations', - 'migrationTable' => 'migration_rbac', - ], - ], -]; -``` - -Note that to synchronize database you now need to run multiple commands -instead of one: - -``` -yii migrate-app -yii migrate-module -yii migrate-rbac -``` - -## Migrating Multiple Databases - -By default, migrations are applied to the same database specified by the -`db` [application component](structure-application-components.md). If you -want them to be applied to a different database, you may specify the `db` -command-line option like shown below, - -``` -yii migrate --db=db2 -``` - -The above command will apply migrations to the `db2` database. - -Sometimes it may happen that you want to apply *some* of the migrations to -one database, while some others to another database. To achieve this goal, -when implementing a migration class you should explicitly specify the DB -component ID that the migration would use, like the following: - -```php -db = 'db2'; - parent::init(); - } -} -``` - -The above migration will be applied to `db2`, even if you specify a -different database through the `db` command-line option. Note that the -migration history will still be recorded in the database specified by the -`db` command-line option. - -If you have multiple migrations that use the same database, it is -recommended that you create a base migration class with the above `init()` -code. Then each migration class can extend from this base class. - -> Tip: Besides setting the [[yii\db\Migration::db|db]] property, you can also operate on different databases -by creating new database connections to them in your migration classes. You then use the [DAO methods](db-dao.md) -with these connections to manipulate different databases. - -Another strategy that you can take to migrate multiple databases is to keep -migrations for different databases in different migration paths. Then you -can migrate these databases in separate commands like the following: - -``` -yii migrate --migrationPath=@app/migrations/db1 --db=db1 -yii migrate --migrationPath=@app/migrations/db2 --db=db2 -... -``` - -The first command will apply migrations in `@app/migrations/db1` to the -`db1` database, the second command will apply migrations in -`@app/migrations/db2` to `db2`, and so on. - ### Upgrading from Yii 2.0 Migrations in Yii 2.0 and the [yiisoft/db-migration](https://github.com/yiisoft/db-migration/) package are -not compatible, and the `migration` table is also not compatible. A -probable solution is to use structure dumps and rename the old `migration` +not compatible, and the `migration` table is also not compatible. + +A probable solution is to use structure dumps and rename the old `migration` table. Upon the initial execution of migrations, a new `migration` table with new fields will be created. All further changes in the database schema are applied using the new `migration` component and recorded in the new migration table. - diff --git a/src/ru/guide/databases/db-migrations.md b/src/ru/guide/databases/db-migrations.md index dd6a9e29..196ac403 100644 --- a/src/ru/guide/databases/db-migrations.md +++ b/src/ru/guide/databases/db-migrations.md @@ -78,16 +78,22 @@ Add the following configuration to `config/common/params.php`: ], ``` +If you want to place migrations elsewhere, you can define the path in +`newMigrationPath`. If your migrations to be applied are from multiple +sources, such as external modules, `sourcePaths` could be used to define +these. + You need a database connection configured as well. See [Working with databases](../start/databases.md) for an example of configuring it for PostgreSQL. -### Creating a migration +## Creating a migration To create a new empty migration, run the following command: ```sh -make yii migrate:create +make shell +./yii migrate:create ``` The required `name` argument gives a brief description about the new @@ -96,7 +102,8 @@ migration. For example, if the migration is about creating a new table named command: ``` -make yii migrate:create create_news_table +make shell +./yii migrate:create create_news_table ``` @@ -171,8 +178,87 @@ final class M251225221906CreateNewsTable implements RevertibleMigrationInterface } ``` -TODO: explain $b and $qb -Below is the list of all these database accessing methods: +Migration builder `$b` in the above manages database schema while the column +builder `$cb` manages column types. Both allow using *abstract types*. When +a migration is applied to a particular database, the abstract types will be +translated into the corresponding database physical types and corresponding +SQL to define them. + +Methods available in migration builder belong to the following types: + +- Raw queries + - getDb — to get database connection instance. + - execute — to execute raw SQL query. +- Data + - insert / update / delete + - batchInsert + - upsert +- Tables and views + - createTable / renameTable / dropTable + - truncateTable + - addCommentOnTable / dropCommentFromTable + - createView / dropView +- Columns + - addColumn / renameColumn / alterColumn / dropColumn + - addCommentOnColumn / dropCommentFromColumn +- Keys and indexes + - addPrimaryKey / dropPrimaryKey + - addForeignKey / dropForeignKey + - createIndex / dropIndex + +Additionally, there's a `columnBuilder()` which is used to obtain a column +builder as in example above. The builder has static methods that define +various column types: + +- Keys + - primaryKey + - smallPrimaryKey + - bigPrimaryKey + - uuidPrimaryKey +- Boolean + - boolean +- Numbers + - bit + - tinyint + - smallint + - integer + - bigint + - flat + - double + - decimal +- Strings + - char + - string + - text +- Date and time + - timestamp + - datetime + - datetimeWithTimezone + - time + - timeWithTimezone + - date +- Special types + - money + - binary + - uuid + - array + - structured + - json +- enum + +All the above methods create a base type which could be adjusted with +additional methods: + +- null / notNull +- defaultValue +- unique +- scale / size / unsigned +- primaryKey / autoIncrement +- check +- comment +- computed +- extra +- reference ### Irreversible migrations @@ -184,146 +270,31 @@ you should implement `Yiisoft\Db\Migration\MigrationInterface` that has `up()` only. -### Transactional migrations (TODO: update!!!) +### Transactional migrations While performing complex DB migrations, it is important to ensure each migration to either succeed or fail as a whole so that the database can maintain integrity and consistency. To achieve this goal, it is recommended -that you enclose the DB operations of each migration in a -[transaction](db-dao.md#performing-transactions). +that you may enclose the DB operations of each migration in a transaction +automatically by adding `TransactionalMigrationInterface` to `implements` of +your migration. -An even easier way of implementing transactional migrations is to put -migration code in the `safeUp()` and `safeDown()` methods. These two methods -differ from `up()` and `down()` in that they are enclosed implicitly in a -transaction. As a result, if any operation in these methods fails, all +As a result, if any operation in the `up()` or `down()` method fails, all prior operations will be rolled back automatically. -In the following example, besides creating the `news` table we also insert -an initial row into this table. - -```php -createTable('news', [ - 'id' => $this->primaryKey(), - 'title' => $this->string()->notNull(), - 'content' => $this->text(), - ]); - - $this->insert('news', [ - 'title' => 'test 1', - 'content' => 'content 1', - ]); - } - - public function safeDown() - { - $this->delete('news', ['id' => 1]); - $this->dropTable('news'); - } -} -``` - -Note that usually when you perform multiple DB operations in `safeUp()`, you -should reverse their execution order in `safeDown()`. In the above example -we first create the table and then insert a row in `safeUp()`; while in -`safeDown()` we first delete the row and then drop the table. - > Note: Not all DBMS support transactions. And some DB queries cannot be put into a transaction. For some examples, -please refer to [implicit commit](https://dev.mysql.com/doc/refman/5.7/en/implicit-commit.html). If this is the case, -you should still implement `up()` and `down()`, instead. - -TODO: TransactionalMigrationInterface - - - -## TODO: update - -The base migration class [[yii\db\Migration]] exposes a database connection -via the [[yii\db\Migration::db|db]] property. You can use it to manipulate -the database schema using the methods as described in [Working with Database -Schema](db-dao.md#database-schema). +please refer to [implicit commit](https://dev.mysql.com/doc/refman/5.7/en/implicit-commit.html). -Rather than using physical types, when creating a table or column you should use *abstract types* -so that your migrations are independent of specific DBMS. The [[yii\db\Schema]] class defines -a set of constants to represent the supported abstract types. These constants are named in the format -of `TYPE_`. For example, `TYPE_PK` refers to auto-incremental primary key type; `TYPE_STRING` -refers to a string type. When a migration is applied to a particular database, the abstract types -will be translated into the corresponding physical types. In the case of MySQL, `TYPE_PK` will be turned -into `int(11) NOT NULL AUTO_INCREMENT PRIMARY KEY`, while `TYPE_STRING` becomes `varchar(255)`. +## Generating a migration -You can append additional constraints when using abstract types. In the -above example, ` NOT NULL` is appended to `Schema::TYPE_STRING` to specify -that the column cannot be `null`. - -> Info: The mapping between abstract types and physical types is specified by -the [[yii\db\QueryBuilder::$typeMap|$typeMap]] property in each concrete `QueryBuilder` class. - -Since version 2.0.6, you can make use of the newly introduced schema builder -which provides more convenient way of defining column schema. So the -migration above could be written like the following: - -```php -createTable('news', [ - 'id' => $this->primaryKey(), - 'title' => $this->string()->notNull(), - 'content' => $this->text(), - ]); - } - - public function down() - { - $this->dropTable('news'); - } -} -``` - -A list of all available methods for defining the column types is available -in the API documentation of [[yii\db\SchemaBuilderTrait]]. - -> Info: The generated file permissions and ownership will be determined by the current environment. This might lead to -inaccessible files. This could, for example, happen when the migration is created within a docker container -and the files are edited on the host. In this case the `newFileMode` and/or `newFileOwnership` of the MigrateController -can be changed. E.g. in the application config: - ```php - [ - 'migrate' => [ - 'class' => 'yii\console\controllers\MigrateController', - 'newFileOwnership' => '1000:1000', # Default WSL user id - 'newFileMode' => 0660, - ], - ], - ]; - ``` - -## Generating Migrations (TODO: likely is OK but...) - -The command provides a convenient way to create migrations using the -provided -[view](https://github.com/yiisoft/db-migration/tree/master/resources/views): +Instead of writing migrations by hand, the command provides a convenient way +generate some of the code. ```shell -make yii migrate:create my_first_table --command=table --fields=name,example --table-comment=my_first_table +make shell +./yii migrate:create -- my_first_table --command=table --fields=name,example --table-comment=my_first_table ``` - - That would generate the following: ```php @@ -338,19 +309,21 @@ use Yiisoft\Db\Migration\RevertibleMigrationInterface; use Yiisoft\Db\Migration\TransactionalMigrationInterface; /** - * Handles the creation of a table `my_first_table`. + * Handles the creation of table `my_first_table`. */ -final class M240115143455CreateMyFirstTableTable implements RevertibleMigrationInterface, TransactionalMigrationInterface +final class M251227095006CreateMyFirstTableTable implements RevertibleMigrationInterface, TransactionalMigrationInterface { public function up(MigrationBuilder $b): void { + $columnBuilder = $b->columnBuilder(); + $b->createTable('my_first_table', [ - 'id' => $b->primaryKey(), + 'id' => $columnBuilder::primaryKey(), 'name', 'example', ]); - - $b->addCommentOnTable('my_first_table', 'dest'); + + $b->addCommentOnTable('my_first_table', 'my_first_table'); } public function down(MigrationBuilder $b): void @@ -360,9 +333,17 @@ final class M240115143455CreateMyFirstTableTable implements RevertibleMigrationI } ``` -For more information -[see](https://github.com/yiisoft/db-migration/tree/master/docs/guide/en) +Commands available are: +- create - empty migration. +- table - creating a table. Use `--fields` specify a list of fields to + use. Types could be specified as well such as + `id:primaryKey,name:string:defaultValue("Alex"),user_id:integer:foreignKey,category_id2:integer:foreignKey(category + id2)`. +- dropTable - dropping a table. +- addColumn - adding a column. +- dropColumn - dropping a column. +- junction - creating a junction table. Use `--and` specify a second table. ## Applying Migrations @@ -370,62 +351,38 @@ To upgrade a database to its latest structure, you should apply all available new migrations using the following command: ``` -yii migrate +./yii migrate:up ``` This command will list all migrations that have not been applied so far. If you confirm that you want to apply these migrations, it will run the `up()` -or `safeUp()` method in every new migration class, one after another, in the -order of their timestamp values. If any of the migrations fails, the command -will quit without applying the rest of the migrations. - -> Tip: In case you don't have command line at your server you may try [web shell](https://github.com/samdark/yii2-webshell) -> extension. +method in every new migration class, one after another, in the order of +their timestamp values. If any of the migrations fails, the command will +quit without applying the rest of the migrations. For each migration that has been successfully applied, the command will insert a row into a database table named `migration` to record the successful application of the migration. This will allow the migration tool to identify which migrations have been applied and which have not. -> Info: The migration tool will automatically create the `migration` table in the database specified by -the [[yii\console\controllers\MigrateController::db|db]] option of the command. By default, the database -is specified by the `db` [application component](structure-application-components.md). - Sometimes, you may only want to apply one or a few new migrations, instead of all available migrations. You can do so by specifying the number of migrations that you want to apply when running the command. For example, the following command will try to apply the next three available migrations: ``` -yii migrate 3 -``` - -You can also explicitly specify a particular migration to which the database -should be migrated by using the `migrate/to` command in one of the following -formats: - -``` -yii migrate/to 150101_185401 # using timestamp to specify the migration -yii migrate/to "2015-01-01 18:54:01" # using a string that can be parsed by strtotime() -yii migrate/to m150101_185401_create_news_table # using full name -yii migrate/to 1392853618 # using UNIX timestamp +./yii migrate:up --limit=3 ``` -If there are any unapplied migrations earlier than the specified one, they -will all be applied before the specified migration is applied. - -If the specified migration has already been applied before, any later -applied migrations will be reverted. - - ## Reverting Migrations To revert (undo) one or multiple migrations that have been applied before, you can run the following command: ``` -yii migrate/down # revert the most recently applied migration -yii migrate/down 3 # revert the most 3 recently applied migrations +./yii migrate:down # revert the most recently applied migration +./yii migrate:down --limit=3 # revert the most 3 recently applied migrations +./yii migrate:down --all # revert all migrations ``` > Note: Not all migrations are reversible. Trying to revert such migrations will cause an error and stop the @@ -438,238 +395,36 @@ Redoing migrations means first reverting the specified migrations and then applying again. This can be done as follows: ``` -yii migrate/redo # redo the last applied migration -yii migrate/redo 3 # redo the last 3 applied migrations +./yii migrate:redo # redo the last applied migration +./yii migrate:redo --limit=3 # redo the last 3 applied migrations +./yii migrate:redo --all # redo all migrations ``` > Note: If a migration is not reversible, you will not be able to redo it. -## Refreshing Migrations - -Since Yii 2.0.13 you can delete all tables and foreign keys from the -database and apply all migrations from the beginning. - -``` -yii migrate/fresh # truncate the database and apply all migrations from the beginning -``` - ## Listing Migrations To list which migrations have been applied and which are not, you may use the following commands: ``` -yii migrate/history # showing the last 10 applied migrations -yii migrate/history 5 # showing the last 5 applied migrations -yii migrate/history all # showing all applied migrations - -yii migrate/new # showing the first 10 new migrations -yii migrate/new 5 # showing the first 5 new migrations -yii migrate/new all # showing all new migrations -``` +./yii migrate/history # showing the last 10 applied migrations +./yii migrate:history --limit=5 # showing the last 5 applied migrations +./yii migrate:history --all # showing all applied migrations - -## Modifying Migration History - -Instead of actually applying or reverting migrations, sometimes you may -simply want to mark that your database has been upgraded to a particular -migration. This often happens when you manually change the database to a -particular state and you do not want the migration(s) for that change to be -re-applied later. You can achieve this goal with the following command: - -``` -yii migrate/mark 150101_185401 # using timestamp to specify the migration -yii migrate/mark "2015-01-01 18:54:01" # using a string that can be parsed by strtotime() -yii migrate/mark m150101_185401_create_news_table # using full name -yii migrate/mark 1392853618 # using UNIX timestamp +./yii migrate:new # showing the first 10 new migrations +./yii migrate:new --limit=5 # showing the first 5 new migrations +./yii migrate:new --all # showing all new migrations ``` -The command will modify the `migration` table by adding or deleting certain -rows to indicate that the database has been applied migrations to the -specified one. No migrations will be applied or reverted by this command. - - -## Customizing Migrations - -There are several ways to customize the migration command. - - -### Using Command Line Options - -The migration command comes with a few command-line options that can be used -to customize its behaviors: - -* `interactive`: boolean (defaults to `true`), specifies whether to perform - migrations in an interactive mode. When this is `true`, the user will be - prompted before the command performs certain actions. You may want to set - this to `false` if the command is being used in a background process. - -* `migrationPath`: string|array (defaults to `@app/migrations`), specifies - the directory storing all migration class files. This can be specified as - either a directory path or a path [alias](concept-aliases.md). Note that - the directory must exist, or the command may trigger an error. Since - version 2.0.12 an array can be specified for loading migrations from - multiple sources. - -* `migrationTable`: string (defaults to `migration`), specifies the name of - the database table for storing migration history information. The table - will be automatically created by the command if it does not exist. You - may also manually create it using the structure `version varchar(255) - primary key, apply_time integer`. - -* `db`: string (defaults to `db`), specifies the ID of the database - [application component](structure-application-components.md). It - represents the database that will be migrated using this command. - -* `templateFile`: string (defaults to `@yii/views/migration.php`), specifies - the path of the template file that is used for generating skeleton - migration class files. This can be specified as either a file path or a - path [alias](concept-aliases.md). The template file is a PHP script in - which you can use a predefined variable named `$className` to get the - migration class name. - -* `generatorTemplateFiles`: array (defaults to `[ - 'create_table' => '@yii/views/createTableMigration.php', - 'drop_table' => '@yii/views/dropTableMigration.php', - 'add_column' => '@yii/views/addColumnMigration.php', - 'drop_column' => '@yii/views/dropColumnMigration.php', - 'create_junction' => '@yii/views/createTableMigration.php' - ]`), specifies template files for generating migration code. See "[Generating Migrations](#generating-migrations)" - for more details. - -* `fields`: array of column definition strings used for creating migration - code. Defaults to `[]`. The format of each definition is - `COLUMN_NAME:COLUMN_TYPE:COLUMN_DECORATOR`. For example, - `--fields=name:string(12):notNull` produces a string column of size 12 - which is not `null`. - -The following example shows how you can use these options. - -For example, if we want to migrate a `forum` module whose migration files -are located within the module's `migrations` directory, we can use the -following command: - -``` -# migrate the migrations in a forum module non-interactively -yii migrate --migrationPath=@app/modules/forum/migrations --interactive=0 -``` - -### Separated Migrations - - -Sometimes using single migration history for all project migrations is not -desirable. For example: you may install some 'blog' extension, which -contains fully separated functionality and contain its own migrations, which -should not affect the ones dedicated to main project functionality. - -If you want several migrations to be applied and tracked down completely -separated from each other, you can configure multiple migration commands -which will use different namespaces and migration history tables: - -```php -return [ - 'controllerMap' => [ - // Common migrations for the whole application - 'migrate-app' => [ - 'class' => 'yii\console\controllers\MigrateController', - 'migrationNamespaces' => ['app\migrations'], - 'migrationTable' => 'migration_app', - 'migrationPath' => null, - ], - // Migrations for the specific project's module - 'migrate-module' => [ - 'class' => 'yii\console\controllers\MigrateController', - 'migrationNamespaces' => ['module\migrations'], - 'migrationTable' => 'migration_module', - 'migrationPath' => null, - ], - // Migrations for the specific extension - 'migrate-rbac' => [ - 'class' => 'yii\console\controllers\MigrateController', - 'migrationPath' => '@yii/rbac/migrations', - 'migrationTable' => 'migration_rbac', - ], - ], -]; -``` - -Note that to synchronize database you now need to run multiple commands -instead of one: - -``` -yii migrate-app -yii migrate-module -yii migrate-rbac -``` - -## Migrating Multiple Databases - -By default, migrations are applied to the same database specified by the -`db` [application component](structure-application-components.md). If you -want them to be applied to a different database, you may specify the `db` -command-line option like shown below, - -``` -yii migrate --db=db2 -``` - -The above command will apply migrations to the `db2` database. - -Sometimes it may happen that you want to apply *some* of the migrations to -one database, while some others to another database. To achieve this goal, -when implementing a migration class you should explicitly specify the DB -component ID that the migration would use, like the following: - -```php -db = 'db2'; - parent::init(); - } -} -``` - -The above migration will be applied to `db2`, even if you specify a -different database through the `db` command-line option. Note that the -migration history will still be recorded in the database specified by the -`db` command-line option. - -If you have multiple migrations that use the same database, it is -recommended that you create a base migration class with the above `init()` -code. Then each migration class can extend from this base class. - -> Tip: Besides setting the [[yii\db\Migration::db|db]] property, you can also operate on different databases -by creating new database connections to them in your migration classes. You then use the [DAO methods](db-dao.md) -with these connections to manipulate different databases. - -Another strategy that you can take to migrate multiple databases is to keep -migrations for different databases in different migration paths. Then you -can migrate these databases in separate commands like the following: - -``` -yii migrate --migrationPath=@app/migrations/db1 --db=db1 -yii migrate --migrationPath=@app/migrations/db2 --db=db2 -... -``` - -The first command will apply migrations in `@app/migrations/db1` to the -`db1` database, the second command will apply migrations in -`@app/migrations/db2` to `db2`, and so on. - ### Upgrading from Yii 2.0 Migrations in Yii 2.0 and the [yiisoft/db-migration](https://github.com/yiisoft/db-migration/) package are -not compatible, and the `migration` table is also not compatible. A -probable solution is to use structure dumps and rename the old `migration` +not compatible, and the `migration` table is also not compatible. + +A probable solution is to use structure dumps and rename the old `migration` table. Upon the initial execution of migrations, a new `migration` table with new fields will be created. All further changes in the database schema are applied using the new `migration` component and recorded in the new migration table. -