add CRM module start
This commit is contained in:
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
namespace App\Database\Migrations;
|
||||
|
||||
use CodeIgniter\Database\Migration;
|
||||
|
||||
class AddTokenExpiresToUsers extends Migration
|
||||
{
|
||||
public function up()
|
||||
{
|
||||
// Проверяем, существует ли уже поле token_expires_at
|
||||
$fields = $this->db->getFieldData('users');
|
||||
$existingFields = array_column($fields, 'name');
|
||||
|
||||
if (!in_array('token_expires_at', $existingFields)) {
|
||||
$this->db->simpleQuery("ALTER TABLE users ADD COLUMN token_expires_at DATETIME NULL AFTER verification_token");
|
||||
}
|
||||
}
|
||||
|
||||
public function down()
|
||||
{
|
||||
$fields = $this->db->getFieldData('users');
|
||||
$existingFields = array_column($fields, 'name');
|
||||
|
||||
if (in_array('token_expires_at', $existingFields)) {
|
||||
$this->db->simpleQuery("ALTER TABLE users DROP COLUMN token_expires_at");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
namespace App\Database\Migrations;
|
||||
|
||||
use CodeIgniter\Database\Migration;
|
||||
|
||||
class AddInviteExpiresToOrganizationUsers extends Migration
|
||||
{
|
||||
public function up()
|
||||
{
|
||||
// Проверяем, существует ли уже поле invite_expires_at
|
||||
$fields = $this->db->getFieldData('organization_users');
|
||||
$existingFields = array_column($fields, 'name');
|
||||
|
||||
if (!in_array('invite_expires_at', $existingFields)) {
|
||||
$this->db->simpleQuery("ALTER TABLE organization_users ADD COLUMN invite_expires_at DATETIME NULL AFTER invited_at");
|
||||
}
|
||||
}
|
||||
|
||||
public function down()
|
||||
{
|
||||
$fields = $this->db->getFieldData('organization_users');
|
||||
$existingFields = array_column($fields, 'name');
|
||||
|
||||
if (in_array('invite_expires_at', $existingFields)) {
|
||||
$this->db->simpleQuery("ALTER TABLE organization_users DROP COLUMN invite_expires_at");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
namespace App\Database\Migrations;
|
||||
|
||||
use CodeIgniter\Database\Migration;
|
||||
|
||||
class AddStatusToOrganizations extends Migration
|
||||
{
|
||||
public function up()
|
||||
{
|
||||
// Проверяем, существует ли уже поле status
|
||||
$fields = $this->db->getFieldData('organizations');
|
||||
$existingFields = array_column($fields, 'name');
|
||||
|
||||
if (!in_array('status', $existingFields)) {
|
||||
$this->db->simpleQuery("ALTER TABLE organizations ADD COLUMN status ENUM('active', 'blocked') NOT NULL DEFAULT 'active' AFTER settings");
|
||||
}
|
||||
}
|
||||
|
||||
public function down()
|
||||
{
|
||||
$fields = $this->db->getFieldData('organizations');
|
||||
$existingFields = array_column($fields, 'name');
|
||||
|
||||
if (in_array('status', $existingFields)) {
|
||||
$this->db->simpleQuery("ALTER TABLE organizations DROP COLUMN status");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,206 @@
|
||||
<?php
|
||||
|
||||
namespace App\Database\Migrations;
|
||||
|
||||
use CodeIgniter\Database\Migration;
|
||||
|
||||
class CreateDealsTables extends Migration
|
||||
{
|
||||
public function up()
|
||||
{
|
||||
// Таблица этапов сделок
|
||||
$this->forge->addField([
|
||||
'id' => [
|
||||
'type' => 'INT',
|
||||
'constraint' => 11,
|
||||
'unsigned' => true,
|
||||
'auto_increment' => true,
|
||||
],
|
||||
'organization_id' => [
|
||||
'type' => 'INT',
|
||||
'constraint' => 11,
|
||||
'unsigned' => true,
|
||||
],
|
||||
'name' => [
|
||||
'type' => 'VARCHAR',
|
||||
'constraint' => 255,
|
||||
],
|
||||
'color' => [
|
||||
'type' => 'VARCHAR',
|
||||
'constraint' => 7,
|
||||
'default' => '#6B7280',
|
||||
],
|
||||
'order_index' => [
|
||||
'type' => 'INT',
|
||||
'constraint' => 11,
|
||||
'default' => 0,
|
||||
],
|
||||
'type' => [
|
||||
'type' => 'ENUM',
|
||||
'constraint' => ['progress', 'won', 'lost'],
|
||||
'default' => 'progress',
|
||||
],
|
||||
'probability' => [
|
||||
'type' => 'INT',
|
||||
'constraint' => 3,
|
||||
'unsigned' => true,
|
||||
'default' => 0,
|
||||
],
|
||||
'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->addForeignKey('organization_id', 'organizations', 'id', 'CASCADE', 'CASCADE');
|
||||
$this->forge->createTable('deal_stages');
|
||||
|
||||
// Таблица сделок
|
||||
$this->forge->addField([
|
||||
'id' => [
|
||||
'type' => 'BIGINT',
|
||||
'constraint' => 20,
|
||||
'unsigned' => true,
|
||||
'auto_increment' => true,
|
||||
],
|
||||
'organization_id' => [
|
||||
'type' => 'INT',
|
||||
'constraint' => 11,
|
||||
'unsigned' => true,
|
||||
],
|
||||
'contact_id' => [
|
||||
'type' => 'INT',
|
||||
'constraint' => 11,
|
||||
'unsigned' => true,
|
||||
'null' => true,
|
||||
],
|
||||
'company_id' => [
|
||||
'type' => 'INT',
|
||||
'constraint' => 11,
|
||||
'unsigned' => true,
|
||||
'null' => true,
|
||||
],
|
||||
'title' => [
|
||||
'type' => 'VARCHAR',
|
||||
'constraint' => 255,
|
||||
],
|
||||
'description' => [
|
||||
'type' => 'TEXT',
|
||||
'null' => true,
|
||||
],
|
||||
'amount' => [
|
||||
'type' => 'DECIMAL',
|
||||
'constraint' => '15,2',
|
||||
'default' => 0.00,
|
||||
],
|
||||
'currency' => [
|
||||
'type' => 'CHAR',
|
||||
'constraint' => 3,
|
||||
'default' => 'RUB',
|
||||
],
|
||||
'stage_id' => [
|
||||
'type' => 'INT',
|
||||
'constraint' => 11,
|
||||
'unsigned' => true,
|
||||
],
|
||||
'assigned_user_id' => [
|
||||
'type' => 'INT',
|
||||
'constraint' => 11,
|
||||
'unsigned' => true,
|
||||
'null' => true,
|
||||
],
|
||||
'expected_close_date' => [
|
||||
'type' => 'DATE',
|
||||
'null' => true,
|
||||
],
|
||||
'created_by' => [
|
||||
'type' => 'INT',
|
||||
'constraint' => 11,
|
||||
'unsigned' => 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('stage_id');
|
||||
$this->forge->addKey('assigned_user_id');
|
||||
$this->forge->addForeignKey('organization_id', 'organizations', 'id', 'CASCADE', 'CASCADE');
|
||||
$this->forge->addForeignKey('stage_id', 'deal_stages', 'id', 'CASCADE', 'CASCADE');
|
||||
$this->forge->addForeignKey('assigned_user_id', 'users', 'id', 'SET NULL', 'SET NULL');
|
||||
$this->forge->createTable('deals');
|
||||
|
||||
// Таблица истории сделок
|
||||
$this->forge->addField([
|
||||
'id' => [
|
||||
'type' => 'BIGINT',
|
||||
'constraint' => 20,
|
||||
'unsigned' => true,
|
||||
'auto_increment' => true,
|
||||
],
|
||||
'deal_id' => [
|
||||
'type' => 'BIGINT',
|
||||
'constraint' => 20,
|
||||
'unsigned' => true,
|
||||
],
|
||||
'user_id' => [
|
||||
'type' => 'INT',
|
||||
'constraint' => 11,
|
||||
'unsigned' => true,
|
||||
],
|
||||
'action' => [
|
||||
'type' => 'VARCHAR',
|
||||
'constraint' => 50,
|
||||
],
|
||||
'field_name' => [
|
||||
'type' => 'VARCHAR',
|
||||
'constraint' => 50,
|
||||
'null' => true,
|
||||
],
|
||||
'old_value' => [
|
||||
'type' => 'TEXT',
|
||||
'null' => true,
|
||||
],
|
||||
'new_value' => [
|
||||
'type' => 'TEXT',
|
||||
'null' => true,
|
||||
],
|
||||
'created_at' => [
|
||||
'type' => 'DATETIME',
|
||||
'null' => true,
|
||||
],
|
||||
]);
|
||||
$this->forge->addKey('id', true);
|
||||
$this->forge->addKey('deal_id');
|
||||
$this->forge->addKey('user_id');
|
||||
$this->forge->addForeignKey('deal_id', 'deals', 'id', 'CASCADE', 'CASCADE');
|
||||
$this->forge->addForeignKey('user_id', 'users', 'id', 'CASCADE', 'CASCADE');
|
||||
$this->forge->createTable('deal_history');
|
||||
}
|
||||
|
||||
public function down()
|
||||
{
|
||||
$this->forge->dropTable('deal_history');
|
||||
$this->forge->dropTable('deals');
|
||||
$this->forge->dropTable('deal_stages');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,87 @@
|
||||
<?php
|
||||
|
||||
namespace App\Database\Migrations;
|
||||
|
||||
use CodeIgniter\Database\Migration;
|
||||
|
||||
class CreateContactsTable extends Migration
|
||||
{
|
||||
public function up()
|
||||
{
|
||||
// Таблица контактов
|
||||
$this->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');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user