This repository has been archived on 2024-06-26. You can view files and clone it, but cannot push or open issues or pull requests.
sakura/migrations/2015_04_01_172649_info_pages_and_nulls.php

49 lines
1.7 KiB
PHP
Raw Normal View History

2016-02-19 21:49:00 +00:00
<?php
use Sakura\Migration\IMigration;
use Sakura\DB;
class InfoPagesAndNulls implements IMigration
{
public function up()
{
// Add multi column to the groups table
DB::prepare("ALTER TABLE `{prefix}groups` ADD `multi` tinyint(1) unsigned NOT NULL DEFAULT '0'")
->execute();
// Create info pages table
DB::prepare("CREATE TABLE `{prefix}infopages` (
`shorthand` varchar(255) COLLATE utf8_bin NOT NULL,
`pagetitle` varchar(255) COLLATE utf8_bin NOT NULL,
`content` text COLLATE utf8_bin NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin")
->execute();
// Make certain fields in the users table nullable
DB::prepare('ALTER TABLE `{prefix}users` MODIFY `usertitle` DEFAULT NULL')
->execute();
DB::prepare('ALTER TABLE `{prefix}users` MODIFY `avatar_url` DEFAULT NULL')
->execute();
DB::prepare('ALTER TABLE `{prefix}users` MODIFY `background_url` DEFAULT NULL')
->execute();
}
public function down()
{
// Drop the multi column from the groups table
DB::prepare("ALTER TABLE `{prefix}groups` DROP COLUMN `multi`")
->execute();
// Drop info pages table
DB::prepare("DROP TABLE `{prefix}infopages`")
->execute();
// Revert the null
DB::prepare('ALTER TABLE `{prefix}users` MODIFY `usertitle` NOT NULL')
->execute();
DB::prepare('ALTER TABLE `{prefix}users` MODIFY `avatar_url` NOT NULL')
->execute();
DB::prepare('ALTER TABLE `{prefix}users` MODIFY `background_url` NOT NULL')
->execute();
}
}