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
- yiisoft/yii2: ^2.0.14
Requires (Dev)
- codeception/codeception: ^5.3
- codeception/module-asserts: ^3.0.0
- codeception/module-yii2: ^1.1.7
- infection/codeception-adapter: ^0.4.7
- infection/infection: ^0.34
- phpstan/phpstan: ^2.2
Suggests
None
Provides
None
Conflicts
None
Replaces
None
- 10.1.0
- dev-master / 10.0.x-dev
- 10.0.1
- 10.0.0
- 9.0.3
- 9.0.2
- 9.0.1
- 9.0.0
- 8.2.3
- 8.2.2
- 8.2.1
- 8.2.0
- 8.1.2
- 8.1.1
- 8.1.0
- 8.0.0
- 7.0.7
- 7.0.6
- 7.0.5
- 7.0.4
- 7.0.3
- 7.0.2
- 7.0.1
- 7.0.0
- 6.1.0
- 6.0.12
- 6.0.11
- 6.0.10
- 6.0.9
- 6.0.8
- 6.0.7
- 6.0.6
- 6.0.5
- 6.0.4
- 6.0.3
- 6.0.2
- 6.0.1
- 6.0.0
- 5.1.5
- 5.1.4
- 5.1.3
- 5.1.2
- 5.1.1
- 5.1.0
- 5.0.14
- 5.0.13
- 5.0.12
- 5.0.11
- 5.0.10
- 5.0.9
- 5.0.8
- 5.0.7
- 5.0.6
- 5.0.5
- 5.0.4
- 5.0.3
- 5.0.2
- 5.0.1
- 5.0.0
- 4.0.2
- 4.0.1
- 4.0.0
- 3.0.7
- 3.0.6
- 3.0.5
- 3.0.4
- 3.0.3
- 3.0.2
- 3.0.1
- 3.0.0
- 2.16.0
- 2.15.3
- 2.15.2
- 2.15.1
- 2.15.0
- 2.14.5
- 2.14.4
- 2.14.3
- 2.14.2
- 2.14.1
- 2.14.0
- 2.13.0
- 2.12.0
- 2.11.0
- 2.10.1
- 2.10.0
- 2.9.0
- 2.8.8
- 2.8.7
- 2.8.6
- 2.8.5
- 2.8.4
- 2.8.3
- 2.8.2
- 2.8.1
- 2.8.0
- 2.7.0
- 2.6.4
- 2.6.3
- 2.6.2
- 2.6.1
- 2.6.0
- 2.5.16
- 2.5.15
- 2.5.14
- 2.5.13
- 2.5.12
- 2.5.11
- 2.5.10
- 2.5.9
- 2.5.8
- 2.5.7
- 2.5.6
- 2.5.5
- 2.5.4
- 2.5.3
- 2.5.2
- 2.5.1
- 2.5.0
- 2.4.1
- 2.4.0
- 2.3.15
- 2.3.14
- 2.3.13
- 2.3.12
- 2.3.11
- 2.3.10
- 2.3.9
- 2.3.8
- 2.3.7
- 2.3.6
- 2.3.5
- 2.3.4
- 2.3.3.3
- 2.3.3.2
- 2.3.3.1
- 2.3.3
- 2.3.2.1
- 2.3.2
- 2.3.1
- 2.3.0.1
- 2.3.0
- 2.2.4
- 2.2.3
- 2.2.2
- 2.2.1
- 2.2.0
- 2.1.2
- 2.1.1
- 2.1.0
- 2.0.1
- 2.0.0
- 1.5.5
- 1.5.4
- 1.5.3
- 1.5.2
- 1.5.0
- 1.2.14
- 1.2.13
- 1.2.12
- 1.2.11
- 1.2.10
- 1.2.9
- 1.2.7
- 1.2.6
- 1.2.5
- 1.2.4
- 1.2.3
- 1.2.2
- 1.2.1
- 1.2.0
- 1.1.0
- 1.0.2
- 1.0.1
- dev-test/hello-world-smoke
- dev-plan/remove-myarrayhelper
This package is auto-updated.
Last update: 2026-09-10 07:27:14 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.
Junction relations in 10.x
Raw viaTable() calls are rejected because a table-name string cannot identify soft-delete behavior. Use an explicit junction ActiveRecord class:
return $this->hasMany(ResponseClick::class, ['response_id' => 'response_id']) ->using(Response::class, ['respondent_id' => 'respondent_id']);
using() derives the table from Response::tableName(). When the junction extends MyActiveRecord and logical deletion is enabled, its deleted_at IS NULL condition is added automatically.
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.
Optional audit schema helper
MyAbstract provides andmemasin\myabstract\schema\AuditSchemaHelper for explicit schema maintenance in migrations or project-owned maintenance code.
It is not a console command and does not run automatically.
use andmemasin\myabstract\schema\AuditSchemaHelper; $helper = new AuditSchemaHelper(Yii::$app->db, [ 'survey', 'sample', ]); $helper->ensure();
The helper only creates the current audit columns: created_by, updated_by, deleted_by, created_at, updated_at, and deleted_at.
It never creates legacy columns: user_created, user_updated, user_closed, time_created, time_updated, or time_closed.
The user table and auth/runtime tables are skipped by default. Old-column renames are still the owning module's migration responsibility.