php - codeigniter dynamic field added on migration time -
i have 2 database called "migrate_new" , "migrate_old" , both have 1 table called "cms_pages".
i want compare "migrate_old" db "cms_pages" "migrate_new" "cms_pages" table structure if "migrate_new" database "cms_pages" not have "field" alter table automatically.
below code compare "migrate_old" "cms_pages" fields not in "migrate_new" "cms_pages" want add fields on table. want continue process in place of exit.
**> 1 can have idea add fields automatically no need stop migration task?
i not able field details type , key , etc. how know alter table use modify or add fields. short want set structure out loss of data automatically. in advance..
**
$this->load->database(); $admin_db = $this->load->database('admindb', true); $query = $this->db->get('cms_page'); $result = $query->result(); $fields_old = $this->db->list_fields('cms_page'); // $fields_new = $admin_db->list_fields('cms_page'); $flag = false; foreach ($fields_old $field){ if (!$admin_db->field_exists($field, 'cms_page')) { echo $field.'=> not exists in new table please contact developer <br>'; $flag = true; } } if($flag){ exit; }
Comments
Post a Comment