Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
1.23% covered (danger)
1.23%
1 / 81
50.00% covered (danger)
50.00%
1 / 2
CRAP
0.00% covered (danger)
0.00%
0 / 1
CreateContactTable
1.23% covered (danger)
1.23%
1 / 81
50.00% covered (danger)
50.00%
1 / 2
5.85
0.00% covered (danger)
0.00%
0 / 1
 up
0.00% covered (danger)
0.00%
0 / 80
0.00% covered (danger)
0.00%
0 / 1
2
 down
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
1<?php
2
3namespace App\Database\Migrations;
4
5use CodeIgniter\Database\Migration;
6
7class CreateContactTable extends Migration
8{
9    public function up()
10    {
11        $this->forge->addField([
12
13            /**
14             * =========================
15             * IDENTIFIANT
16             * =========================
17             */
18            'id' => [
19                'type'           => 'INT',
20                'constraint'     => 11,
21                'unsigned'       => true,
22                'auto_increment' => true,
23            ],
24
25            /**
26             * =========================
27             * IDENTITÉ
28             * =========================
29             */
30            'type' => [
31                'type'       => 'VARCHAR',
32                'constraint' => 50,
33                'null'       => true,
34            ],
35            'name' => [
36                'type'       => 'VARCHAR',
37                'constraint' => 150,
38            ],
39            'email' => [
40                'type'       => 'VARCHAR',
41                'constraint' => 150,
42                'null'       => true,
43            ],
44            'phone' => [
45                'type'       => 'VARCHAR',
46                'constraint' => 30,
47                'null'       => true,
48            ],
49            'whatsapp' => [
50                'type'       => 'VARCHAR',
51                'constraint' => 30,
52                'null'       => true,
53            ],
54            'company' => [
55                'type'       => 'VARCHAR',
56                'constraint' => 150,
57                'null'       => true,
58            ],
59            'job_title' => [
60                'type'       => 'VARCHAR',
61                'constraint' => 150,
62                'null'       => true,
63            ],
64            'status' => [
65                'type'       => 'VARCHAR',
66                'constraint' => 30,
67                'default'    => 'active',
68            ],
69
70            /**
71             * =========================
72             * CANAUX
73             * =========================
74             */
75            'sms_enabled' => [
76                'type'       => 'TINYINT',
77                'constraint' => 1,
78                'default'    => 1,
79            ],
80            'email_enabled' => [
81                'type'       => 'TINYINT',
82                'constraint' => 1,
83                'default'    => 1,
84            ],
85            'whatsapp_enabled' => [
86                'type'       => 'TINYINT',
87                'constraint' => 1,
88                'default'    => 0,
89            ],
90
91            /**
92             * =========================
93             * MÉTADATA FLEXIBLE
94             * =========================
95             */
96            'metadata' => [
97                'type' => 'TEXT',
98                'null' => true,
99            ],
100
101            /**
102             * =========================
103             * TIMESTAMPS
104             * =========================
105             */
106            'created_at' => [
107                'type' => 'DATETIME',
108                'null' => true,
109            ],
110            'updated_at' => [
111                'type' => 'DATETIME',
112                'null' => true,
113            ],
114        ]);
115
116        $this->forge->addKey('id', true);
117
118        // Index pour performance CRM
119        $this->forge->addKey('email');
120        $this->forge->addKey('phone');
121        $this->forge->addKey('type');
122        $this->forge->addKey('status');
123
124        $this->forge->createTable('contact', true);
125    }
126
127    public function down()
128    {
129        $this->forge->dropTable('contact', true);
130    }
131}