<?php

class m130430_122020_import_rabc_and_users extends MyDbMigration
{
  public function up()
  {
    $this->execute("
      DROP TABLE IF EXISTS `authassignment`;
      CREATE TABLE IF NOT EXISTS `authassignment` (
        `itemname` varchar(64) NOT NULL,
        `userid` varchar(64) NOT NULL,
        `bizrule` text,
        `data` text,
        PRIMARY KEY (`itemname`,`userid`)
      ) ENGINE=MyISAM DEFAULT CHARSET=latin1;

      INSERT INTO `authassignment` (`itemname`, `userid`, `bizrule`, `data`) VALUES
      ('civilian_low', '10', NULL, 'N;'),
      ('police_high', '9', NULL, 'N;'),
      ('police_medium', '8', NULL, 'N;'),
      ('police_low', '7', NULL, 'N;'),
      ('civilian_high', '11', NULL, 'N;');

      DROP TABLE IF EXISTS `authitem`;
      CREATE TABLE IF NOT EXISTS `authitem` (
        `name` varchar(64) NOT NULL,
        `type` int(11) NOT NULL,
        `description` text,
        `bizrule` text,
        `data` text,
        PRIMARY KEY (`name`)
      ) ENGINE=MyISAM DEFAULT CHARSET=latin1;

      INSERT INTO `authitem` (`name`, `type`, `description`, `bizrule`, `data`) VALUES
      ('civilian_low', 2, 'Civile Primo Livello', NULL, 'N;'),
      ('civilian_high', 2, 'Civile Supervisore', NULL, 'N;'),
      ('police_low', 2, 'PM Basso Livello', NULL, 'N;'),
      ('police_medium', 2, 'PM Medio Livello', NULL, 'N;'),
      ('police_high', 2, 'PM Alto Livello (Supervisore)', NULL, 'N;'),
      ('start_stop_service', 0, 'Avvia i servizi', NULL, 'N;'),
      ('edit_event_behaviors', 0, 'Visualizza e modifica i behaviors', NULL, 'N;'),
      ('edit_pending_events', 0, 'Modifica eventi sospesi', NULL, 'N;'),
      ('view_all_events', 0, 'Può visualizzare tutti gli eventi', NULL, 'N;');


      DROP TABLE IF EXISTS `authitemchild`;
      CREATE TABLE IF NOT EXISTS `authitemchild` (
        `parent` varchar(64) NOT NULL,
        `child` varchar(64) NOT NULL,
        PRIMARY KEY (`parent`,`child`)
      ) ENGINE=MyISAM DEFAULT CHARSET=latin1;


      INSERT INTO `authitemchild` (`parent`, `child`) VALUES
      ('police_high', 'edit_event_behaviors'),
      ('police_high', 'edit_pending_events'),
      ('police_high', 'view_all_events'),
      ('police_medium', 'edit_event_behaviors');
    ");
  }

  public function down()
  {
    echo "You shall not pass!";
    return true;
  }

}
