Skip to content
This repository has been archived by the owner on May 19, 2020. It is now read-only.

Commit

Permalink
Fix migration for altering post content fields
Browse files Browse the repository at this point in the history
  • Loading branch information
CraigChilds94 committed Feb 26, 2016
1 parent 29ac0e0 commit ff54846
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions anchor/migrations/211_alter_post_page_content.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,29 @@ public function up() {
$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)
));
}
}
}

Expand Down

0 comments on commit ff54846

Please sign in to comment.