<?php

class Version001000 implements MigrationInterface
{
    public function getVersion(): string
    {
        return '1.0';
    }

    public function getDescription(): string
    {
        return 'Upgrade from 1.0 - Widen column types and add indexes';
    }

    public function up(PDO $pdo, string $prefix): void
    {
        $pdo->exec("ALTER TABLE admin CHANGE COLUMN id id smallint(5) unsigned default NULL");
        $pdo->exec("ALTER TABLE admin CHANGE COLUMN admin admin tinyint(4) default NULL");
        $pdo->exec("ALTER TABLE category CHANGE COLUMN id id smallint(5) unsigned NOT NULL auto_increment");
        $pdo->exec("ALTER TABLE data CHANGE COLUMN department department smallint(6) unsigned default NULL");
        $pdo->exec("ALTER TABLE data CHANGE COLUMN reviewer reviewer smallint(6) unsigned default NULL");
        $pdo->exec("ALTER TABLE data CHANGE COLUMN status status smallint(6) unsigned default NULL");
        $pdo->exec("ALTER TABLE data CHANGE COLUMN publishable publishable tinyint(4) default NULL");
        $pdo->exec("ALTER TABLE data CHANGE COLUMN default_rights default_rights tinyint(4) default NULL");
        $pdo->exec("ALTER TABLE data CHANGE COLUMN comment comment varchar(255) default ''");
        $pdo->exec("ALTER TABLE data CHANGE COLUMN id id smallint(5) unsigned NOT NULL auto_increment");
        $pdo->exec("ALTER TABLE data CHANGE COLUMN owner owner smallint(6) unsigned default NULL");
        $pdo->exec("ALTER TABLE data ADD INDEX data_idx (id,owner)");
        $pdo->exec("ALTER TABLE department CHANGE COLUMN id id smallint(5) unsigned NOT NULL auto_increment");
        $pdo->exec("ALTER TABLE dept_perms CHANGE COLUMN fid fid smallint(5) unsigned default NULL");
        $pdo->exec("ALTER TABLE dept_perms CHANGE COLUMN dept_id dept_id smallint(5) unsigned default NULL");
        $pdo->exec("ALTER TABLE dept_reviewer CHANGE COLUMN user_id user_id smallint(5) unsigned default NULL");
        $pdo->exec("ALTER TABLE dept_reviewer CHANGE COLUMN dept_id dept_id smallint(5) unsigned default NULL");
        $pdo->exec("ALTER TABLE log CHANGE COLUMN id id int(10) unsigned NOT NULL default '0'");
        $pdo->exec("ALTER TABLE user CHANGE COLUMN department department smallint(5) unsigned default NULL");
        $pdo->exec("ALTER TABLE user CHANGE COLUMN id id smallint(5) unsigned NOT NULL auto_increment");
        $pdo->exec("ALTER TABLE user_perms CHANGE COLUMN fid fid smallint(5) unsigned default NULL");
        $pdo->exec("ALTER TABLE user_perms CHANGE COLUMN uid uid smallint(5) unsigned NOT NULL default '0'");
        $pdo->exec("ALTER TABLE user_perms ADD INDEX user_perms_idx (fid,uid,rights)");
    }

    public function down(PDO $pdo, string $prefix): void
    {
    }
}