forge->addField([ 'id' => [ 'type' => 'INT', 'constraint' => 11, 'unsigned' => true, 'auto_increment' => true, ], 'organization_id' => [ 'type' => 'INT', 'constraint' => 11, 'unsigned' => true, ], 'customer_id' => [ 'type' => 'INT', 'constraint' => 11, 'unsigned' => true, 'comment' => 'Ссылка на клиента (компанию)', ], 'name' => [ 'type' => 'VARCHAR', 'constraint' => 255, 'comment' => 'Имя контакта', ], 'email' => [ 'type' => 'VARCHAR', 'constraint' => 255, 'null' => true, ], 'phone' => [ 'type' => 'VARCHAR', 'constraint' => 50, 'null' => true, ], 'position' => [ 'type' => 'VARCHAR', 'constraint' => 255, 'null' => true, 'comment' => 'Должность', ], 'is_primary' => [ 'type' => 'TINYINT', 'constraint' => 1, 'unsigned' => true, 'default' => 0, 'comment' => 'Основной контакт', ], 'notes' => [ 'type' => 'TEXT', 'null' => true, ], 'created_at' => [ 'type' => 'DATETIME', 'null' => true, ], 'updated_at' => [ 'type' => 'DATETIME', 'null' => true, ], 'deleted_at' => [ 'type' => 'DATETIME', 'null' => true, ], ]); $this->forge->addKey('id', true); $this->forge->addKey('organization_id'); $this->forge->addKey('customer_id'); $this->forge->addForeignKey('organization_id', 'organizations', 'id', 'CASCADE', 'CASCADE'); $this->forge->addForeignKey('customer_id', 'organizations_clients', 'id', 'CASCADE', 'CASCADE'); $this->forge->createTable('contacts'); } public function down() { $this->forge->dropTable('contacts'); } }