public function up() { $table = Base::table('pages'); $table2 = Base::table('posts'); if ($this->has_table_column($table, 'content')) { $sql = 'ALTER TABLE `' . $table . '` '; $sql .= 'CHANGE `content` `markdown` TEXT'; DB::ask($sql); } if (!$this->has_table_column($table, 'html') && $this->has_table_column($table, 'markdown')) { $sql = 'ALTER TABLE `' . $table . '` '; $sql .= 'ADD `html` TEXT NOT NULL AFTER `markdown`'; DB::ask($sql); $pages = Page::sort('menu_order', 'desc')->get(); foreach ($pages as $page) { Page::update($page->id, array('html' => parse($page->markdown))); } } if (!$this->has_table_column($table2, 'markdown') && $this->has_table_column($table2, 'html')) { $sql = 'ALTER TABLE `' . $table2 . '` '; $sql .= 'ADD `markdown` TEXT NOT NULL AFTER `description`'; DB::ask($sql); $migrate_data_sql = 'update `' . $table2 . '` set `markdown` = `html`, `html` = "";'; DB::ask($migrate_data_sql); $posts = Post::sort('created', 'desc')->get(); foreach ($posts as $post) { Post::update($post->id, array('html' => parse($post->markdown))); } } }
public function down() { $posts = Base::table('posts'); if ($this->has_table($posts)) { if ($this->has_table_column($posts, 'updated')) { $sql = 'ALTER TABLE `' . $posts . '` '; $sql .= 'DROP COLUMN `updated`'; DB::ask($sql); } } $pages = Base::table('pages'); if ($this->has_table($pages)) { if ($this->has_table_column($pages, 'updated')) { $sql = 'ALTER TABLE `' . $pages . '` '; $sql .= 'DROP COLUMN `updated`'; DB::ask($sql); } } $users = Base::table('users'); if ($this->has_table($users)) { if ($this->has_table_column($users, 'updated')) { $sql = 'ALTER TABLE `' . $users . '` '; $sql .= 'DROP COLUMN `updated`'; DB::ask($sql); } } }
public function up() { $table = Base::table('comments'); if ($this->has_table($table)) { $sql = 'ALTER TABLE `' . $table . '` CHANGE `status` `status` enum(\'pending\',\'approved\',\'spam\') NOT NULL AFTER `post`'; DB::ask($sql); } }
public function up() { $table = Base::table('post_meta'); if ($this->has_table_column($table, 'custom_fields')) { $sql = 'ALTER TABLE `' . $table . '` DROP `custom_fields`'; DB::ask($sql); } }
public function down() { $table = Base::table('posts'); if ($this->has_table_column($table, 'html')) { $sql = 'ALTER TABLE `' . $table . '` MODIFY COLUMN `html` TEXT NOT NULL'; DB::ask($sql); } }
public function up() { $table = Base::table('category_meta'); if (!$this->has_table($table)) { $sql = "CREATE TABLE IF NOT EXISTS `" . $table . "` (\n `id` int(6) NOT NULL AUTO_INCREMENT,\n `category` int(6) NOT NULL,\n `extend` int(6) NOT NULL,\n `data` text NOT NULL,\n PRIMARY KEY (`id`),\n KEY `item` (`category`),\n KEY `extend` (`extend`)\n ) ENGINE=InnoDB"; DB::ask($sql); } }
public function up() { $table = Base::table('comments'); if ($this->has_table($table)) { $sql = 'ALTER TABLE `' . $table . '` CHANGE `date` `date` datetime NOT NULL AFTER `status`'; DB::ask($sql); } }
public function up() { $table = Base::table('posts'); if ($this->has_table_column($table, 'created')) { $sql = 'ALTER TABLE `' . $table . '` CHANGE `created` `created` datetime NOT NULL AFTER `js`'; DB::ask($sql); } }
public function up() { $table = Base::table('pages'); if (!$this->has_table_column($table, 'show_in_menu')) { $sql = 'ALTER TABLE `' . $table . '` ADD `show_in_menu` tinyint(1) NOT NULL'; DB::ask($sql); } }
public function up() { $table = Base::table('pages'); if (!$this->has_table_column($table, 'menu_order')) { $sql = 'ALTER TABLE `' . $table . '` ADD `menu_order` int(4) NOT NULL DEFAULT 0'; DB::ask($sql); } }
public function up() { $table = Base::table('pages'); if (!$this->has_table_column($table, 'parent')) { $sql = 'ALTER TABLE `' . $table . '` ADD `parent` int(6) NOT NULL AFTER `id`'; DB::ask($sql); } }
public function up() { $table = Base::table('sessions'); if ($this->has_table_column($table, 'date')) { $sql = 'ALTER TABLE `' . $table . '` CHANGE `date` `expire` int(10) NOT NULL AFTER `id`'; DB::ask($sql); } }
public function up() { $table = Base::table('extend'); if (!$this->has_table($table)) { $sql = "CREATE TABLE IF NOT EXISTS `' . {$table} . '` (\n\t\t\t\t`id` int(6) NOT NULL AUTO_INCREMENT,\n\t\t\t\t`type` enum('post','page') NOT NULL,\n\t\t\t\t`field` enum('text','html','image','file') NOT NULL,\n\t\t\t\t`key` varchar(160) NOT NULL,\n\t\t\t\t`label` varchar(160) NOT NULL,\n\t\t\t\t`attributes` text NOT NULL,\n\t\t\t\tPRIMARY KEY (`id`)\n\t\t\t) ENGINE=InnoDB"; DB::ask($sql); } }
public function down() { $table = Base::table('extend'); if ($this->has_table_column($table, 'type')) { $sql = 'ALTER TABLE `' . $table . '` MODIFY COLUMN `type` enum("post", "page") NOT NULL'; DB::ask($sql); } }
public function up() { $table = Base::table('page_meta'); if (!$this->has_table($table)) { $sql = "CREATE TABLE IF NOT EXISTS `' . {$table} . '` (\n\t\t\t\t`id` int(6) NOT NULL AUTO_INCREMENT,\n\t\t\t\t`page` int(6) NOT NULL,\n\t\t\t\t`extend` int(6) NOT NULL,\n\t\t\t\t`data` text NOT NULL,\n\t\t\t\tPRIMARY KEY (`id`),\n\t\t\t\tKEY `page` (`page`),\n\t\t\t\tKEY `extend` (`extend`)\n\t\t\t) ENGINE=InnoDB"; DB::ask($sql); } }
public function up() { $table = Base::table('users'); if ($this->has_table_column($table, 'password')) { $sql = 'ALTER TABLE `' . $table . '` CHANGE `password` `password` text NOT NULL AFTER `username`'; DB::ask($sql); } }
public function up() { $table = Base::table('sessions'); if ($this->has_table_column($table, 'ip')) { $sql = 'ALTER TABLE `' . $table . '` DROP `ip`'; DB::ask($sql); } }
public function up() { $table = Base::table('pages'); if ($this->has_table_column($table, 'menu_order')) { $sql = 'ALTER TABLE `' . $table . '`;'; $sql .= 'ALTER COLUMN `menu_order` SET DEFAULT 0'; DB::ask($sql); } }
public function up() { $table = Base::table('user_meta'); if (!$this->has_table($table)) { $sql = "CREATE TABLE IF NOT EXISTS `" . $table . "` (\n\t\t\t\t`id` int(6) NOT NULL AUTO_INCREMENT,\n\t\t\t\t`user` int(6) NOT NULL,\n\t\t\t\t`extend` int(6) NOT NULL,\n\t\t\t\t`data` text NOT NULL,\n\t\t\t\tPRIMARY KEY (`id`),\n\t\t\t\tKEY `item` (`user`),\n\t\t\t\tKEY `extend` (`extend`)\n\t\t\t) ENGINE=InnoDB"; DB::ask($sql); } $table2 = Base::table('extend'); if ($this->has_table($table2)) { $sql2 = "ALTER TABLE `" . $table2 . "` CHANGE `type` `type` ENUM('post','page','category','user') NOT NULL"; DB::ask($sql2); } }
public function has_table_column($table, $column) { if ($this->has_table($table)) { $sql = 'SHOW COLUMNS FROM `' . $table . '`'; list($result, $statement) = DB::ask($sql); $statement->setFetchMode(PDO::FETCH_OBJ); $columns = array(); foreach ($statement->fetchAll() as $row) { $columns[] = $row->Field; } return in_array($column, $columns); } else { return false; } }
public function up() { $table = Base::table('pagetypes'); if (!$this->has_table($table)) { $sql = "CREATE TABLE IF NOT EXISTS `" . $table . "` (\n\t\t\t\t`key` varchar(32) NOT NULL,\n\t\t\t\t`value` varchar(32) NOT NULL\n\t\t\t) ENGINE=InnoDB"; DB::ask($sql); Query::table($table)->insert(array('key' => 'all', 'value' => 'All Pages')); } $table2 = Base::table('extend'); if (!$this->has_table_column($table2, 'pagetype')) { $sql2 = "ALTER TABLE `" . $table2 . "` ADD `pagetype` VARCHAR(140) NOT NULL DEFAULT 'all' AFTER `type`"; DB::ask($sql2); } $table3 = Base::table('pages'); if (!$this->has_table_column($table3, 'pagetype')) { $sql2 = "ALTER TABLE `" . $table3 . "` ADD `pagetype` VARCHAR(140) NOT NULL DEFAULT 'all' AFTER `slug`"; DB::ask($sql2); } }