Creates_Reports.php
1 year ago
Migration.php
1 year ago
Migration_10.php
2 years ago
Migration_11.php
2 years ago
Migration_12.php
1 year ago
Migration_13.php
2 years ago
Migration_14.php
2 years ago
Migration_15.php
2 years ago
Migration_16.php
2 years ago
Migration_17.php
1 year ago
Migration_18.php
2 years ago
Migration_19.php
2 years ago
Migration_1_0.php
2 years ago
Migration_1_6.php
2 years ago
Migration_1_8.php
2 years ago
Migration_1_9.php
2 years ago
Migration_2.php
2 years ago
Migration_20.php
2 years ago
Migration_21.php
2 years ago
Migration_22.php
2 years ago
Migration_23.php
1 year ago
Migration_24.php
2 years ago
Migration_25.php
2 years ago
Migration_26.php
2 years ago
Migration_27.php
2 years ago
Migration_28.php
2 years ago
Migration_29.php
2 years ago
Migration_3.php
2 years ago
Migration_30.php
2 years ago
Migration_31.php
2 years ago
Migration_32.php
2 years ago
Migration_33.php
2 years ago
Migration_34.php
1 year ago
Migration_35.php
1 year ago
Migration_36.php
1 year ago
Migration_37.php
1 year ago
Migration_38.php
1 year ago
Migration_39.php
1 year ago
Migration_4.php
2 years ago
Migration_40.php
1 year ago
Migration_41.php
1 year ago
Migration_42.php
1 year ago
Migration_43.php
1 year ago
Migration_44.php
9 months ago
Migration_45.php
8 months ago
Migration_46.php
8 months ago
Migration_47.php
8 months ago
Migration_48.php
8 months ago
Migration_49.php
8 months ago
Migration_5.php
2 years ago
Migration_50.php
9 months ago
Migration_51.php
8 months ago
Migration_52.php
8 months ago
Migration_6.php
2 years ago
Migration_7.php
1 year ago
Migration_8.php
2 years ago
Migration_9.php
2 years ago
Migration_Job.php
1 year ago
Migrations.php
8 months ago
Step_Migration.php
6 months ago
Migration_45.php
55 lines
| 1 | <?php |
| 2 | |
| 3 | namespace IAWP\Migrations; |
| 4 | |
| 5 | use IAWP\Database; |
| 6 | /** @internal */ |
| 7 | class Migration_45 extends \IAWP\Migrations\Step_Migration |
| 8 | { |
| 9 | /** |
| 10 | * @return int |
| 11 | */ |
| 12 | protected function database_version() : int |
| 13 | { |
| 14 | return 45; |
| 15 | } |
| 16 | /** |
| 17 | * @return array |
| 18 | */ |
| 19 | protected function queries() : array |
| 20 | { |
| 21 | return [$this->drop_table_if_exists($this->tables::referrer_types()), $this->create_referrer_types_table(), $this->populate_referrer_types_table(), $this->add_referrer_type_id_column(), $this->populate_referrer_type_id_column(), $this->modify_referrer_type_id_column(), $this->drop_original_referrer_type_column(), $this->index_new_column()]; |
| 22 | } |
| 23 | private function create_referrer_types_table() : string |
| 24 | { |
| 25 | return "\n CREATE TABLE {$this->tables::referrer_types()} (\n id BIGINT(20) UNSIGNED AUTO_INCREMENT,\n referrer_type ENUM('Ad','Direct','Referrer','Search','Social', 'AI') NOT NULL,\n PRIMARY KEY (id),\n UNIQUE INDEX (referrer_type)\n ) DEFAULT CHARACTER SET {$this->character_set()} COLLATE {$this->collation()};\n "; |
| 26 | } |
| 27 | private function populate_referrer_types_table() : string |
| 28 | { |
| 29 | return "\n INSERT INTO {$this->tables::referrer_types()} (referrer_type)\n SELECT DISTINCT type\n FROM {$this->tables::referrers()} WHERE type IS NOT NULL\n "; |
| 30 | } |
| 31 | private function add_referrer_type_id_column() : string |
| 32 | { |
| 33 | return "\n ALTER TABLE {$this->tables::referrers()} ADD COLUMN referrer_type_id BIGINT(20) UNSIGNED;\n "; |
| 34 | } |
| 35 | private function populate_referrer_type_id_column() : string |
| 36 | { |
| 37 | $old_collation = Database::column_collation_for($this->tables::referrers(), 'type'); |
| 38 | $current_collation = $this->collation(); |
| 39 | $collation_statement = $this->get_collation_statement($current_collation, $old_collation); |
| 40 | return "\n UPDATE\n {$this->tables::referrers()} AS referrers\n JOIN {$this->tables::referrer_types()} AS referrer_types ON referrers.type = referrer_types.referrer_type {$collation_statement}\n SET\n referrers.referrer_type_id = referrer_types.id\n "; |
| 41 | } |
| 42 | private function modify_referrer_type_id_column() : string |
| 43 | { |
| 44 | return "\n ALTER TABLE {$this->tables::referrers()} MODIFY COLUMN referrer_type_id BIGINT(20) UNSIGNED NOT NULL;\n "; |
| 45 | } |
| 46 | private function drop_original_referrer_type_column() : string |
| 47 | { |
| 48 | return "\n ALTER TABLE {$this->tables::referrers()} DROP COLUMN type;\n "; |
| 49 | } |
| 50 | private function index_new_column() : string |
| 51 | { |
| 52 | return "\n ALTER TABLE {$this->tables::referrers()} ADD INDEX (referrer_type_id);\n "; |
| 53 | } |
| 54 | } |
| 55 |