bp/app/Database/Migrations/2026-02-08-120000_CreateAtt...

75 lines
2.1 KiB
PHP

<?php
namespace App\Database\Migrations;
use CodeIgniter\Database\Migration;
class CreateAttachmentsTable extends Migration
{
public function up()
{
$this->forge->addField([
'id' => [
'type' => 'INT',
'constraint' => 11,
'unsigned' => true,
'auto_increment' => true,
],
'entity_type' => [
'type' => 'VARCHAR',
'constraint' => 50,
'null' => false,
'comment' => 'Тип сущности: task, deal, contact, etc.',
],
'entity_id' => [
'type' => 'INT',
'constraint' => 11,
'null' => false,
],
'file_name' => [
'type' => 'VARCHAR',
'constraint' => 255,
'null' => false,
],
'file_path' => [
'type' => 'VARCHAR',
'constraint' => 500,
'null' => false,
],
'file_size' => [
'type' => 'INT',
'constraint' => 11,
'default' => 0,
],
'file_type' => [
'type' => 'VARCHAR',
'constraint' => 100,
'default' => '',
],
'uploaded_by' => [
'type' => 'INT',
'constraint' => 11,
'null' => false,
],
'created_at' => [
'type' => 'DATETIME',
'null' => true,
],
'updated_at' => [
'type' => 'DATETIME',
'null' => true,
],
]);
$this->forge->addKey('id', true);
$this->forge->addKey(['entity_type', 'entity_id']);
$this->forge->addKey('uploaded_by');
$this->forge->createTable('attachments');
}
public function down()
{
$this->forge->dropTable('attachments');
}
}