Created
September 7, 2011 20:33
-
-
Save nerdsrescueme/1201651 to your computer and use it in GitHub Desktop.
fuelmod-blog migration
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$glob = glob(APPPATH .'migrations/*_*.php'); | |
list($last) = explode('_', basename(end($glob))); | |
$file = APPPATH.'migrations/'.str_pad($last + 1, 3, '0', STR_PAD_LEFT).'_create_blog_tables.php'; | |
if ( ! file_put_contents($file, $content) | |
{ | |
throw new Exception('Cannot write migration.'); | |
} | |
@chmod($file, 0666); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace Fuel\Migrations; | |
class Create_blog_tables { | |
public function up() | |
{ | |
$sql = <<<BLOGSQL | |
CREATE TABLE `sw_articles` ( | |
`id` int(11) unsigned NOT NULL AUTO_INCREMENT, | |
`user_id` int(11) unsigned NOT NULL DEFAULT '0', | |
`category_id` int(11) DEFAULT NULL, | |
`title` varchar(140) COLLATE utf8_unicode_ci DEFAULT NULL, | |
`body` text COLLATE utf8_unicode_ci, | |
`published` tinyint(3) unsigned NOT NULL DEFAULT '0', | |
`created_at` bigint(20) unsigned DEFAULT NULL, | |
`updated_at` bigint(20) DEFAULT NULL, | |
PRIMARY KEY (`id`), | |
UNIQUE KEY `slug` (`slug`), | |
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; | |
CREATE TABLE `sw_categories` ( | |
`id` int(11) NOT NULL AUTO_INCREMENT, | |
`user_id` int(11) unsigned NOT NULL DEFAULT '0', | |
`name` varchar(140) COLLATE utf8_unicode_ci DEFAULT NULL, | |
`description` tinytext COLLATE utf8_unicode_ci, | |
`created_at` bigint(20) DEFAULT NULL, | |
`updated_at` bigint(20) DEFAULT NULL, | |
PRIMARY KEY (`id`), | |
UNIQUE KEY `slug` (`slug`), | |
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; | |
BLOGSQL; | |
\DB::query($sql); | |
} | |
public function down() | |
{ | |
\DBUtil::drop_table('blog_posts'); | |
\DBUtil::drop_table('blog_categories'); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment