andmemasin / yii2-myabstract
my custom activerecord classes
Package info
github.com/TonisOrmisson/yii2-myabstract
Type:yii2-extension
pkg:composer/andmemasin/yii2-myabstract
Requires
- php: >=8.3.0
- andmemasin/yii2-helpers: ^1.5.0
- yiisoft/yii2: ^2.0.14
Requires (Dev)
- codeception/codeception: ^5.3
- codeception/module-asserts: ^3.0.0
- codeception/module-yii2: ^1.1.7
- phpstan/phpstan: ^2.2
This package is auto-updated.
Last update: 2026-06-19 12:47:34 UTC
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.
This package keeps timestamp values as DATETIME(6) / Y-m-d H:i:s.u values. Laravel's migration helpers commonly create SQL TIMESTAMP columns for created_at, updated_at, and deleted_at, but that is not a UNIX integer timestamp. Both DATETIME(6) and TIMESTAMP(6) are read by Laravel/Eloquent as date objects.
The practical difference is timezone handling: MySQL DATETIME stores the exact calendar value written, while MySQL TIMESTAMP can be converted according to the DB session timezone. Keeping DATETIME(6) avoids timezone surprises during the Yii-to-Laravel transition. A future schema cleanup may convert these columns to TIMESTAMP(6) if strict Laravel migration-helper compatibility becomes more important than preserving current DB behavior.
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]]);
Use dateTime(6) for this migration phase unless the module explicitly decides to also take on timezone semantics changes. Do not convert to UNIX integer timestamps.
- 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.