You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
<?phpnamespaceApp\Core\Migration;
use yii\db\Expression;
use yii\db\Migration;
abstractclassMigrationAbstractextendsMigration
{
/** * Setup the binary id column */publicfunctionbinaryId(): string
{
return "BINARY(16) NOT NULL COMMENT '(DC2Type:uuid_binary_ordered_time)'";
//return $this->binary(16)->notNull()->unique()->comment('(DC2Type:uuid_binary_ordered_time)');
}
/** * Setup the UUID column * @return \yii\db\ColumnSchemaBuilder */publicfunctionuuid()
{
return$this->string(36)->notNull()->unique()->comment('(DC2Type:uuid)');
}
/** * Setup the status column * @return \yii\db\ColumnSchemaBuilder */publicfunctionstatus()
{
return$this->smallInteger(1)->notNull()->defaultValue(1);
}
/** * Setup the deleted column * @return \yii\db\ColumnSchemaBuilder */publicfunctiondeleted()
{
return$this->smallInteger(1)->notNull()->defaultValue(0);
}
/** * Returns the blame and timed events columns list * @return array */publicfunctionblameAndTimedEventsColumns(): array
{
return array_merge(
$this->timedEventsColumns(),
$this->blameColumns()
);
}
/** * Returns the blame columns list * @return array */publicfunctionblameColumns(): array
{
return [
'created_by' => $this->string(100)->notNull(),
'updated_by' => $this->string(100)->defaultValue(newExpression('NULL')),
'deleted_by' => $this->string(100)->defaultValue(newExpression('NULL')),
];
}
/** * Returns the timed events columns list * @return array */publicfunctiontimedEventsColumns(): array
{
return [
'created_at' => $this->dateTime()->notNull(),
'updated_at' => $this->dateTime()->defaultValue(newExpression('NULL')),
'deleted_at' => $this->dateTime()->defaultValue(newExpression('NULL')),
];
}
}
migration-template.php file:
<?php/** * This view is used by console/controllers/MigrateController.php. * * The following variables are available in this view: *//* @var $className string the new migration class name without namespace *//* @var $namespace string the new migration class namespace */echo "<?php\n";
if (!empty($namespace)) {
echo "\nnamespace {$namespace};\n";
}
?>
use App\Core\Migration\MigrationAbstract;
/**
* Class <?=$className . "\n" ?>
*/
class <?=$className?> extends MigrationAbstract
{
/**
* {@inheritdoc}
*/
public function safeUp()
{
// set the table columns
$columns = [
'id' => $this->binaryId(),
'uuid' => $this->uuid(),
'status' => $this->status(),
'deleted' => $this->deleted()
];
$this->createTable(
'{{%table_name}}',
array_merge($columns, $this->blameAndTimedEventsColumns()),
'CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE=InnoDB'
);
$this->addPrimaryKey('pk_table_name_id', '{{%table_name}}', 'id');
}
/**
* {@inheritdoc}
*/
public function safeDown()
{
$this->dropTable('{{%table_name}}');
}
}
The text was updated successfully, but these errors were encountered:
In the
config/console.php
file, update themigrate
values to:Create the package
Core/Migration
with 2 files:MigrationAbstract
file:migration-template.php
file:The text was updated successfully, but these errors were encountered: