Migration_25.php
| 1 | <?php |
| 2 | |
| 3 | namespace IAWP\Migrations; |
| 4 | |
| 5 | use IAWP\Query; |
| 6 | /** @internal */ |
| 7 | class Migration_25 extends \IAWP\Migrations\Step_Migration |
| 8 | { |
| 9 | /** |
| 10 | * @return int |
| 11 | */ |
| 12 | protected function database_version() : int |
| 13 | { |
| 14 | return 25; |
| 15 | } |
| 16 | /** |
| 17 | * @return array |
| 18 | */ |
| 19 | protected function queries() : array |
| 20 | { |
| 21 | return [$this->add_temporary_column(), $this->copy_timestamp_data_to_temporary_column(), $this->delete_original_column(), $this->rename_temporary_column()]; |
| 22 | } |
| 23 | private function add_temporary_column() : string |
| 24 | { |
| 25 | $resources_table = Query::get_table_name(Query::RESOURCES); |
| 26 | return "\n ALTER TABLE {$resources_table} ADD COLUMN cached_date_temp DATE; \n "; |
| 27 | } |
| 28 | private function copy_timestamp_data_to_temporary_column() : string |
| 29 | { |
| 30 | $resources_table = Query::get_table_name(Query::RESOURCES); |
| 31 | return "\n UPDATE {$resources_table} SET cached_date_temp = FROM_UNIXTIME(cached_date) WHERE cached_date REGEXP '^[0-9]+\$';\n "; |
| 32 | } |
| 33 | private function delete_original_column() : string |
| 34 | { |
| 35 | $resources_table = Query::get_table_name(Query::RESOURCES); |
| 36 | return "\n ALTER TABLE {$resources_table} DROP COLUMN cached_date;\n "; |
| 37 | } |
| 38 | private function rename_temporary_column() : string |
| 39 | { |
| 40 | $resources_table = Query::get_table_name(Query::RESOURCES); |
| 41 | return "\n ALTER TABLE {$resources_table} CHANGE COLUMN cached_date_temp cached_date DATE;\n "; |
| 42 | } |
| 43 | } |
| 44 |