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_51.php
47 lines
| 1 | <?php |
| 2 | |
| 3 | namespace IAWP\Migrations; |
| 4 | |
| 5 | /** @internal */ |
| 6 | class Migration_51 extends \IAWP\Migrations\Step_Migration |
| 7 | { |
| 8 | /** |
| 9 | * @return int |
| 10 | */ |
| 11 | protected function database_version() : int |
| 12 | { |
| 13 | return 51; |
| 14 | } |
| 15 | /** |
| 16 | * @return array |
| 17 | */ |
| 18 | protected function queries() : array |
| 19 | { |
| 20 | return [$this->drop_table_if_exists($this->tables::links()), $this->create_links_table(), $this->populate_links_table(), $this->add_link_id_column_to_clicked_links_table(), $this->populate_link_id_column(), $this->remove_click_target_id_from_clicks_table(), $this->switch_primary_key_for_clicked_links_table()]; |
| 21 | } |
| 22 | private function create_links_table() : string |
| 23 | { |
| 24 | return "\n CREATE TABLE {$this->tables::links()} (\n id BIGINT(20) UNSIGNED AUTO_INCREMENT,\n link_rule_id BIGINT(20) UNSIGNED,\n click_target_id BIGINT(20) UNSIGNED,\n PRIMARY KEY (id),\n INDEX(link_rule_id),\n INDEX(click_target_id),\n UNIQUE INDEX(link_rule_id, click_target_id)\n ) DEFAULT CHARACTER SET {$this->character_set()} COLLATE {$this->collation()};\n "; |
| 25 | } |
| 26 | private function populate_links_table() : string |
| 27 | { |
| 28 | return "\n INSERT INTO {$this->tables::links()} (link_rule_id, click_target_id)\n SELECT DISTINCT\n clicked_links.link_rule_id,\n clicks.click_target_id\n FROM\n {$this->tables::clicked_links()} AS clicked_links\n JOIN {$this->tables::clicks()} AS clicks ON clicked_links.click_id = clicks.click_id;\n "; |
| 29 | } |
| 30 | private function add_link_id_column_to_clicked_links_table() : string |
| 31 | { |
| 32 | return "\n ALTER TABLE {$this->tables::clicked_links()}\n ADD COLUMN link_id BIGINT(20) UNSIGNED,\n ADD INDEX (link_id);\n "; |
| 33 | } |
| 34 | private function populate_link_id_column() : string |
| 35 | { |
| 36 | return "\n UPDATE {$this->tables::clicked_links()} AS clicked_links\n JOIN {$this->tables::clicks()} AS clicks ON clicked_links.click_id = clicks.click_id\n JOIN {$this->tables::links()} AS links ON clicks.click_target_id = links.click_target_id AND clicked_links.link_rule_id = links.link_rule_id\n SET\n clicked_links.link_id = links.id;\n "; |
| 37 | } |
| 38 | private function remove_click_target_id_from_clicks_table() : string |
| 39 | { |
| 40 | return "\n ALTER TABLE {$this->tables::clicks()} DROP COLUMN click_target_id;\n "; |
| 41 | } |
| 42 | private function switch_primary_key_for_clicked_links_table() : string |
| 43 | { |
| 44 | return "\n ALTER TABLE {$this->tables::clicked_links()}\n DROP PRIMARY KEY,\n ADD PRIMARY KEY (click_id, link_id),\n DROP COLUMN link_rule_id;\n "; |
| 45 | } |
| 46 | } |
| 47 |