andmemasin/yii2-myabstract
Composer 安装命令:
composer require andmemasin/yii2-myabstract
包简介
my custom activerecord classes
关键字:
README 文档
README
Soft delete schema
This major version uses Laravel-style soft-delete timestamp semantics by default.
Default lifecycle columns:
created_atupdated_atdeleted_at
Default audit columns:
created_byupdated_bydeleted_by
Active records have deleted_at IS NULL. Deleted records have deleted_at set to the deletion timestamp.
Apps that still use the previous columns must override the column-name properties on their models until their own migrations are complete:
public string $userCreatedCol = 'user_created'; public string $userUpdatedCol = 'user_updated'; public string $userClosedCol = 'user_closed'; public string $timeCreatedCol = 'time_created'; public string $timeUpdatedCol = 'time_updated'; public string $timeClosedCol = 'time_closed';
Overrides only change column names. They do not preserve the old end-of-time active-row convention; active rows must still have the configured deleted timestamp column set to NULL.
Migrating an app module to 9.x
Migrate one app module or table group at a time.
- Update the module package constraint to allow
andmemasin/yii2-myabstract:^9. - Add a DB migration that renames the columns:
$this->renameColumn('{{table_name}}', 'time_created', 'created_at'); $this->renameColumn('{{table_name}}', 'time_updated', 'updated_at'); $this->renameColumn('{{table_name}}', 'time_closed', 'deleted_at'); $this->renameColumn('{{table_name}}', 'user_created', 'created_by'); $this->renameColumn('{{table_name}}', 'user_updated', 'updated_by'); $this->renameColumn('{{table_name}}', 'user_closed', 'deleted_by');
- Convert active rows to the new Laravel-style soft-delete state:
$this->alterColumn('{{table_name}}', 'deleted_at', $this->dateTime(6)->null()); $this->alterColumn('{{table_name}}', 'deleted_by', $this->integer()->null()); $this->update('{{table_name}}', ['deleted_at' => null, 'deleted_by' => null], ['deleted_by' => [0, null]]);
- Replace indexes that include
user_closedwith equivalent indexes usingdeleted_at. - Remove old column-name overrides from migrated models.
- Keep explicit old-name overrides only on models whose tables are not migrated yet.
- Search the module for direct references to old names and update queries/search models/tests:
rg -n "time_created|time_updated|time_closed|user_created|user_updated|user_closed" modules/andmemasin/<module>
- Run the module tests and PHPStan before release:
vendor/bin/codecept run modules/andmemasin/<module>/tests php vendor/bin/phpstan analyze -c modules/andmemasin/<module>/phpstan-dev.neon
Do not dual-write old and new columns. If a module cannot migrate its tables yet, keep it on the old major version or add explicit old-name overrides until that module gets its own migration.
统计信息
- 总下载量: 9.17k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 1
- 依赖项目数: 6
- 推荐数: 0
其他信息
- 授权协议: proprietary
- 更新时间: 2018-05-09