Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
1.72% covered (danger)
1.72%
1 / 58
50.00% covered (danger)
50.00%
1 / 2
CRAP
0.00% covered (danger)
0.00%
0 / 1
CreateChannelProviderTable
1.72% covered (danger)
1.72%
1 / 58
50.00% covered (danger)
50.00%
1 / 2
5.80
0.00% covered (danger)
0.00%
0 / 1
 up
0.00% covered (danger)
0.00%
0 / 57
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 CreateChannelProviderTable extends Migration
8{
9    public function up()
10    {
11        $this->forge->addField([
12
13            'id' => [
14                'type'           => 'INT',
15                'constraint'     => 11,
16                'unsigned'       => true,
17                'auto_increment' => true,
18            ],
19
20            'channel' => [
21                'type'       => 'ENUM',
22                'constraint' => ['sms', 'whatsapp', 'email'],
23            ],
24
25            'name' => [
26                'type'       => 'VARCHAR',
27                'constraint' => 120,
28            ],
29
30            'code' => [
31                'type'       => 'VARCHAR',
32                'constraint' => 80,
33                'unique'     => true,
34            ],
35
36            'status' => [
37                'type'       => 'TINYINT',
38                'constraint' => 1,
39                'default'    => 1,
40            ],
41
42            'priority' => [
43                'type'       => 'INT',
44                'constraint' => 11,
45                'default'    => 1,
46            ],
47
48            'scope' => [
49                'type'       => 'ENUM',
50                'constraint' => ['global', 'country'],
51                'default'    => 'global',   // global par défaut, plus sûr
52            ],
53
54            // Renseigné uniquement si scope = country (ISO 3166-1 alpha-2)
55            'country_code' => [
56                'type'       => 'VARCHAR',
57                'constraint' => 2,
58                'null'       => true,
59                'default'    => null,
60            ],
61
62            // AUDIT
63            'created_at' => [
64                'type' => 'DATETIME',
65                'null' => true,
66            ],
67
68            'updated_at' => [
69                'type' => 'DATETIME',
70                'null' => true,
71            ],
72        ]);
73
74        // PRIMARY KEY
75        $this->forge->addKey('id', true);
76
77        // INDEX PERFORMANCE
78        $this->forge->addKey(['channel']);
79        $this->forge->addKey(['status']);
80        $this->forge->addKey(['scope']);
81        $this->forge->addKey(['country_code']);
82
83        // INDEX COMPOSITE — requête providers($channel) + getVisible()
84        $this->forge->addKey(['channel', 'scope', 'country_code']);
85
86        $this->forge->createTable('channel_provider', true);
87    }
88
89    public function down()
90    {
91        $this->forge->dropTable('channel_provider', true);
92    }
93}