Exemple #1
0
 /**
  * create the sessions table
  * php oil r session:create
  */
 public static function create()
 {
     // load session config
     \Config::load('session', true);
     if (\Config::get('session.driver') != 'db') {
         // prompt the user to confirm they want to remove the table.
         $continue = \Cli::prompt(\Cli::color('Your current driver type is not set db. Would you like to continue and add the sessions table anyway?', 'yellow'), array('y', 'n'));
         if ($continue === 'n') {
             return \Cli::color('Database sessions table was not created.', 'red');
         }
     }
     if (\DBUtil::table_exists(\Config::get('session.db.table'))) {
         return \Cli::write('Session table already exists.');
     }
     // create the session table using the table name from the config file
     \DBUtil::create_table(\Config::get('session.db.table'), array('session_id' => array('constraint' => 40, 'type' => 'varchar'), 'previous_id' => array('constraint' => 40, 'type' => 'varchar'), 'user_agent' => array('type' => 'text', 'null' => false), 'ip_hash' => array('constraint' => 32, 'type' => 'char'), 'created' => array('constraint' => 10, 'type' => 'int', 'unsigned' => true), 'updated' => array('constraint' => 10, 'type' => 'int', 'unsigned' => true), 'payload' => array('type' => 'longtext')), array('session_id'), false, 'InnoDB', \Config::get('db.default.charset'));
     // make previous_id a unique_key. speeds up query and prevents duplicate id's
     \DBUtil::create_index(\Config::get('session.db.table'), 'previous_id', 'previous_id', 'unique');
     if (\Config::get('session.driver') === 'db') {
         // return success message.
         return \Cli::color('Success! Your session table has been created!', 'green');
     } else {
         // return success message notifying that the driver is not db.
         return \Cli::color('Success! Your session table has been created! Your current session driver type is set to ' . \Config::get('session.driver') . '. In order to use the table you just created to manage your sessions, you will need to set your driver type to "db" in your session config file.', 'green');
     }
 }
 public function up()
 {
     \DBUtil::create_table('menu', array('id' => array('constraint' => 11, 'type' => 'int', 'auto_increment' => true, 'unsigned' => true), 'left_id' => array('constraint' => 11, 'type' => 'int', 'unsigned' => true), 'right_id' => array('constraint' => 11, 'type' => 'int', 'unsigned' => true), 'tree_id' => array('constraint' => 11, 'type' => 'int', 'unsigned' => true), 'name' => array('constraint' => 252, 'type' => 'varchar'), 'slug' => array('constraint' => 255, 'type' => 'varchar', 'null' => true), 'url' => array('constraint' => 255, 'type' => 'varchar', 'null' => true), 'fields' => array('type' => 'text', 'null' => true)), array('id'));
     \DBUtil::create_index('menu', 'left_id');
     \DBUtil::create_index('menu', 'right_id');
     \DBUtil::create_table('menu_meta', array('id' => array('constraint' => 11, 'type' => 'int', 'auto_increment' => true), 'menu_id' => array('constraint' => 11, 'type' => 'int'), 'key' => array('type' => 'text'), 'value' => array('type' => 'text')), array('id'));
 }
 function up()
 {
     // get the driver used
     \Config::load('auth', true);
     $drivers = \Config::get('auth.driver', array());
     is_array($drivers) or $drivers = array($drivers);
     if (in_array('Simpleauth', $drivers)) {
         // get the tablename
         \Config::load('simpleauth', true);
         $table = \Config::get('simpleauth.table_name', 'users') . '_providers';
         // make sure the configured DB is used
         \DBUtil::set_connection(\Config::get('simpleauth.db_connection', null));
     } elseif (in_array('Ormauth', $drivers)) {
         // get the tablename
         \Config::load('ormauth', true);
         $table = \Config::get('ormauth.table_name', 'users') . '_providers';
         // make sure the configured DB is used
         \DBUtil::set_connection(\Config::get('ormauth.db_connection', null));
     }
     if (isset($table)) {
         \DBUtil::create_table($table, array('id' => array('type' => 'int', 'constraint' => 11, 'auto_increment' => true), 'parent_id' => array('type' => 'int', 'constraint' => 11, 'default' => 0), 'provider' => array('type' => 'varchar', 'constraint' => 50), 'uid' => array('type' => 'varchar', 'constraint' => 255), 'secret' => array('type' => 'varchar', 'constraint' => 255, 'null' => true), 'access_token' => array('type' => 'varchar', 'constraint' => 255, 'null' => true), 'expires' => array('type' => 'int', 'constraint' => 12, 'default' => 0, 'null' => true), 'refresh_token' => array('type' => 'varchar', 'constraint' => 255, 'null' => true), 'user_id' => array('type' => 'int', 'constraint' => 11, 'default' => 0), 'created_at' => array('type' => 'int', 'constraint' => 11, 'default' => 0), 'updated_at' => array('type' => 'int', 'constraint' => 11, 'default' => 0)), array('id'));
         \DBUtil::create_index($table, 'parent_id', 'parent_id');
     }
     // reset any DBUtil connection set
     \DBUtil::set_connection(null);
 }
 function up()
 {
     // get the drivers defined
     $drivers = normalize_driver_types();
     if (in_array('Simpleauth', $drivers)) {
         // get the tablename
         \Config::load('simpleauth', true);
         $basetable = \Config::get('simpleauth.table_name', 'users');
         // make sure the configured DB is used
         \DBUtil::set_connection(\Config::get('simpleauth.db_connection', null));
     } elseif (in_array('Ormauth', $drivers)) {
         // get the tablename
         \Config::load('ormauth', true);
         $basetable = \Config::get('ormauth.table_name', 'users');
         // make sure the configured DB is used
         \DBUtil::set_connection(\Config::get('ormauth.db_connection', null));
     } else {
         $basetable = 'users';
     }
     \DBUtil::create_table($basetable . '_clients', array('id' => array('type' => 'int', 'constraint' => 11, 'auto_increment' => true), 'name' => array('type' => 'varchar', 'constraint' => 32, 'default' => ''), 'client_id' => array('type' => 'varchar', 'constraint' => 32, 'default' => ''), 'client_secret' => array('type' => 'varchar', 'constraint' => 32, 'default' => ''), 'redirect_uri' => array('type' => 'varchar', 'constraint' => 255, 'default' => ''), 'auto_approve' => array('type' => 'tinyint', 'constraint' => 1, 'default' => 0), 'autonomous' => array('type' => 'tinyint', 'constraint' => 1, 'default' => 0), 'status' => array('type' => 'enum', 'constraint' => '"development","pending","approved","rejected"', 'default' => 'development'), 'suspended' => array('type' => 'tinyint', 'constraint' => 1, 'default' => 0), 'notes' => array('type' => 'tinytext')), array('id'));
     \DBUtil::create_index($basetable . '_clients', 'client_id', 'client_id', 'UNIQUE');
     \DBUtil::create_table($basetable . '_sessions', array('id' => array('type' => 'int', 'constraint' => 11, 'auto_increment' => true), 'client_id' => array('type' => 'varchar', 'constraint' => 32, 'default' => ''), 'redirect_uri' => array('type' => 'varchar', 'constraint' => 255, 'default' => ''), 'type_id' => array('type' => 'varchar', 'constraint' => 64), 'type' => array('type' => 'enum', 'constraint' => '"user","auto"', 'default' => 'user'), 'code' => array('type' => 'text'), 'access_token' => array('type' => 'varchar', 'constraint' => 50, 'default' => ''), 'stage' => array('type' => 'enum', 'constraint' => '"request","granted"', 'default' => 'request'), 'first_requested' => array('type' => 'int', 'constraint' => 11), 'last_updated' => array('type' => 'int', 'constraint' => 11), 'limited_access' => array('type' => 'tinyint', 'constraint' => 1, 'default' => 0)), array('id'), true, false, null, array(array('constraint' => 'oauth_sessions_ibfk_1', 'key' => 'client_id', 'reference' => array('table' => $basetable . '_clients', 'column' => 'client_id'), 'on_delete' => 'CASCADE')));
     \DBUtil::create_table($basetable . '_scopes', array('id' => array('type' => 'int', 'constraint' => 11, 'auto_increment' => true), 'scope' => array('type' => 'varchar', 'constraint' => 64, 'default' => ''), 'name' => array('type' => 'varchar', 'constraint' => 64, 'default' => ''), 'description' => array('type' => 'varchar', 'constraint' => 255, 'default' => '')), array('id'));
     \DBUtil::create_index($basetable . '_scopes', 'scope', 'scope', 'UNIQUE');
     \DBUtil::create_table($basetable . '_sessionscopes', array('id' => array('type' => 'int', 'constraint' => 11, 'auto_increment' => true), 'session_id' => array('type' => 'int', 'constraint' => 11), 'access_token' => array('type' => 'varchar', 'constraint' => 50, 'default' => ''), 'scope' => array('type' => 'varchar', 'constraint' => 64, 'default' => '')), array('id'), true, false, null, array(array('constraint' => 'oauth_sessionscopes_ibfk_1', 'key' => 'scope', 'reference' => array('table' => $basetable . '_scopes', 'column' => 'scope')), array('constraint' => 'oauth_sessionscopes_ibfk_2', 'key' => 'session_id', 'reference' => array('table' => $basetable . '_sessions', 'column' => 'id'), 'on_delete' => 'CASCADE')));
     \DBUtil::create_index($basetable . '_sessionscopes', 'session_id', 'session_id');
     \DBUtil::create_index($basetable . '_sessionscopes', 'access_token', 'access_token');
     \DBUtil::create_index($basetable . '_sessionscopes', 'scope', 'scope');
     // reset any DBUtil connection set
     \DBUtil::set_connection(null);
 }
 public function up()
 {
     \DBUtil::create_table('statistics', array('id' => array('type' => 'int', 'constraint' => 11, 'auto_increment' => true), 'seller_id' => array('type' => 'int', 'constraint' => 11), 'type' => array('type' => 'varchar', 'constraint' => 50), 'name' => array('type' => 'varchar', 'constraint' => 255), 'value' => array('type' => 'text'), 'date' => array('type' => 'date')), array('id'));
     \DBUtil::create_index('statistics', 'seller_id', 'seller_id');
     \DBUtil::create_index('statistics', array('seller_id', 'type'), 'seller_type');
     \DBUtil::create_index('statistics', array('seller_id', 'type', 'name'), 'seller_type_name');
 }
 public function up()
 {
     \DBUtil::create_table('customer_gateways', array('id' => array('type' => 'int', 'constraint' => 11, 'auto_increment' => true), 'customer_id' => array('type' => 'int', 'constraint' => 11), 'gateway_id' => array('type' => 'int', 'constraint' => 11), 'external_id' => array('type' => 'varchar', 'constraint' => 255, 'null' => true)), array('id'));
     \DBUtil::create_index('customer_gateways', 'customer_id', 'customer_id');
     \DBUtil::create_index('customer_gateways', 'gateway_id', 'gateway_id');
     \DBUtil::create_index('customer_gateways', array('customer_id', 'gateway_id'), 'customer_gateway', 'unique');
 }
 function up()
 {
     // get the configured table name
     $table = \Config::get('simpleauth.table_name', 'users');
     // table users
     \DBUtil::create_table($table, array('id' => array('type' => 'int', 'constraint' => 11, 'auto_increment' => true), 'username' => array('type' => 'varchar', 'constraint' => 50), 'password' => array('type' => 'varchar', 'constraint' => 255), 'group' => array('type' => 'int', 'constraint' => 11, 'default' => 1), 'email' => array('type' => 'varchar', 'constraint' => 255), 'last_login' => array('type' => 'varchar', 'constraint' => 25), 'login_hash' => array('type' => 'varchar', 'constraint' => 255), 'profile_fields' => array('type' => 'text'), 'created_at' => array('type' => 'int', 'constraint' => 11, 'default' => 0)), array('id'));
     // add a unique index on username and email
     \DBUtil::create_index('users', array('username', 'email'), 'username', 'UNIQUE');
 }
 function up()
 {
     // only do this if it doesn't exist yet
     if (!\DBUtil::table_exists('users')) {
         // table users
         \DBUtil::create_table('users', array('id' => array('type' => 'integer primary key', 'autoincrement' => true), 'username' => array('type' => 'text'), 'password' => array('type' => 'text'), 'group' => array('type' => 'integer', 'default' => 1), 'email' => array('type' => 'text'), 'last_login' => array('type' => 'text'), 'login_hash' => array('type' => 'text'), 'profile_fields' => array('type' => 'text'), 'created_at' => array('type' => 'integer', 'default' => 0), 'updated_at' => array('type' => 'integer', 'default' => 0)));
         // add a unique index on username and email
         \DBUtil::create_index('users', array('username', 'email'), 'username', 'UNIQUE');
     }
 }
Exemple #9
0
 public function up()
 {
     // For optimizing relations
     \DBUtil::create_index('comments', 'post_id');
     \DBUtil::create_index('posts', 'category_id');
     \DBUtil::create_index('posts', 'user_id');
     // For optimizing slug retrieval
     \DBUtil::create_index('posts', 'slug');
     \DBUtil::create_index('categories', 'slug');
 }
    public function up()
    {
        /*         * *********************************************************************************************
                  monitor_type
                 * ********************************************************************************************* */
        $monitor_type = \DBUtil::checkIfExist('monitor_type');
        if (!$monitor_type) {
            \DBUtil::create_table('monitor_type', array('id' => array('constraint' => 11, 'type' => 'int', 'auto_increment' => true), 'name' => array('constraint' => 250, 'type' => 'varchar')), array('id'), true, 'InnoDB', 'utf8_unicode_ci');
            \DBUtil::truncate_table('monitor_type');
            // insert default connector type
            list($insert_id, $rows_affected) = \DB::insert('monitor_type')->columns(array('id', 'name'))->values(array('1', 'Nagios'))->execute();
        }
        /*         * *********************************************************************************************
                  monitor_source
                 * ********************************************************************************************* */
        $monitor_source = \DBUtil::checkIfExist('monitor_source');
        if (!$monitor_source) {
            \DBUtil::create_table('monitor_source', array('id' => array('constraint' => 11, 'type' => 'int', 'auto_increment' => true), 'typeID' => array('constraint' => 11, 'type' => 'int'), 'user' => array('constraint' => 250, 'type' => 'varchar'), 'pass' => array('constraint' => 250, 'type' => 'varchar'), 'content' => array('type' => 'text', 'null' => true), 'meta_update_time' => array('constraint' => 11, 'type' => 'int', 'default' => '0'), 'meta_update_user' => array('constraint' => 11, 'type' => 'int', 'default' => '0')), array('id'), true, 'InnoDB', 'utf8_unicode_ci');
            //create indexes for wiki
            \DBUtil::create_index('monitor_source', 'typeID');
        }
        /*         * *********************************************************************************************
                  monitoring
                 * ********************************************************************************************* */
        $monitoring = \DBUtil::checkIfExist('monitoring');
        if (!$monitoring) {
            \DBUtil::create_table('monitoring', array('id' => array('constraint' => 11, 'type' => 'int', 'auto_increment' => true), 'iconw' => array('constraint' => 11, 'type' => 'int'), 'iconu' => array('constraint' => 11, 'type' => 'int'), 'iconc' => array('constraint' => 11, 'type' => 'int'), 'osdw' => array('constraint' => 11, 'type' => 'int'), 'osdu' => array('constraint' => 11, 'type' => 'int'), 'osdc' => array('constraint' => 11, 'type' => 'int'), 'soundc' => array('constraint' => 11, 'type' => 'int'), 'soundw' => array('constraint' => 11, 'type' => 'int'), 'soundu' => array('constraint' => 11, 'type' => 'int'), 'meta_update_user' => array('constraint' => 11, 'type' => 'int', 'default' => '0')), array('id'), true, 'InnoDB', 'utf8_unicode_ci');
            //create indexes for wiki
            //\DBUtil::create_index('vps', 'masterID');
            \DBUtil::truncate_table('monitoring');
            // insert default connector type
            list($insert_id, $rows_affected) = \DB::insert('monitoring')->columns(array('id', 'iconw', 'iconu', 'iconc', 'osdw', 'osdu', 'osdc', 'soundc', 'soundw', 'soundu', 'meta_update_user'))->values(array('1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1'))->execute();
        }
        /*         * *********************************************************************************************
                  FOREIGN KEYS
                 * ********************************************************************************************* */
        //monitor
        if (!$monitor_source) {
            $query = \DB::query('ALTER TABLE `monitor_source`
				ADD CONSTRAINT `monitor_ibfk_1` FOREIGN KEY (`typeID`) REFERENCES `monitor_type` (`id`) 
				ON DELETE CASCADE ON UPDATE CASCADE')->execute();
        }
        /*
         * UPDATE version 
         * 
         * */
        $now = time();
        list($insert_id, $rows_affected) = \DB::insert('version')->columns(array('value', 'meta_update_time'))->values(array('1.08', $now))->execute();
    }
 function up()
 {
     // get the driver used
     \Config::load('auth', true);
     $drivers = \Config::get('auth.driver', array());
     is_array($drivers) or $drivers = array($drivers);
     if (in_array('Ormauth', $drivers)) {
         // get the tablename
         \Config::load('ormauth', true);
         $table = \Config::get('ormauth.table_name', 'users');
         // table users_perms
         \DBUtil::create_table($table . '_permissions', array('id' => array('type' => 'int', 'constraint' => 11, 'auto_increment' => true), 'area' => array('type' => 'varchar', 'constraint' => 25), 'permission' => array('type' => 'varchar', 'constraint' => 25), 'description' => array('type' => 'varchar', 'constraint' => 255), 'user_id' => array('type' => 'int', 'constraint' => 11, 'default' => 0), 'created_at' => array('type' => 'int', 'constraint' => 11, 'default' => 0), 'updated_at' => array('type' => 'int', 'constraint' => 11, 'default' => 0)), array('id'));
         // add a unique index on group and permission
         \DBUtil::create_index($table . '_permissions', array('area', 'permission'), 'permission', 'UNIQUE');
     }
 }
 function up()
 {
     // get the drivers defined
     $drivers = normalize_driver_types();
     if (in_array('Ormauth', $drivers)) {
         // get the tablename
         \Config::load('ormauth', true);
         $table = \Config::get('ormauth.table_name', 'users');
         // make sure the configured DB is used
         \DBUtil::set_connection(\Config::get('ormauth.db_connection', null));
         // table users_perms
         \DBUtil::create_table($table . '_permissions', array('id' => array('type' => 'int', 'constraint' => 11, 'auto_increment' => true), 'area' => array('type' => 'varchar', 'constraint' => 25), 'permission' => array('type' => 'varchar', 'constraint' => 25), 'description' => array('type' => 'varchar', 'constraint' => 255), 'user_id' => array('type' => 'int', 'constraint' => 11, 'default' => 0), 'created_at' => array('type' => 'int', 'constraint' => 11, 'default' => 0), 'updated_at' => array('type' => 'int', 'constraint' => 11, 'default' => 0)), array('id'));
         // add a unique index on group and permission
         \DBUtil::create_index($table . '_permissions', array('area', 'permission'), 'permission', 'UNIQUE');
     }
     // reset any DBUtil connection set
     \DBUtil::set_connection(null);
 }
    public function up()
    {
        /*         * *********************************************************************************************
                  munin
                 * ********************************************************************************************* */
        $munin = \DBUtil::checkIfExist('munin');
        if (!$munin) {
            \DBUtil::create_table('munin', array('id' => array('constraint' => 11, 'type' => 'int', 'auto_increment' => true), 'url' => array('constraint' => 250, 'type' => 'varchar'), 'deviceID' => array('constraint' => 11, 'type' => 'int'), 'user' => array('constraint' => 250, 'type' => 'varchar'), 'pass' => array('constraint' => 250, 'type' => 'varchar'), 'meta_update_user' => array('constraint' => 11, 'type' => 'int', 'default' => '0')), array('id'), true, 'InnoDB', 'utf8_unicode_ci');
            //create indexes for graphing
            \DBUtil::create_index('munin', 'deviceID');
        }
        //graphing
        if (!$munin) {
            $query = \DB::query('ALTER TABLE `munin`
					ADD CONSTRAINT `munin_ibfk_1` FOREIGN KEY (`deviceID`) REFERENCES `device` (`id`)
					ON DELETE CASCADE ON UPDATE CASCADE')->execute();
        }
    }
 function down()
 {
     // get the driver used
     \Config::load('auth', true);
     $drivers = \Config::get('auth.driver', array());
     is_array($drivers) or $drivers = array($drivers);
     if (in_array('Ormauth', $drivers)) {
         // get the tablename
         \Config::load('ormauth', true);
         $basetable = \Config::get('ormauth.table_name', 'users');
         // make sure the configured DB is used
         \DBUtil::set_connection(\Config::get('ormauth.db_connection', null));
         \DBUtil::drop_fields($basetable . '_user_permissions', array('id'));
         \DBUtil::create_index($basetable . '_user_permissions', array('user_id', 'perms_id'), '', 'PRIMARY');
         \DBUtil::drop_fields($basetable . '_group_permissions', array('id'));
         \DBUtil::create_index($basetable . '_group_permissions', array('group_id', 'perms_id'), '', 'PRIMARY');
         \DBUtil::drop_fields($basetable . '_role_permissions', array('id'));
         \DBUtil::create_index($basetable . '_role_permissions', array('role_id', 'perms_id'), '', 'PRIMARY');
     }
     // reset any DBUtil connection set
     \DBUtil::set_connection(null);
 }
 public function up()
 {
     //populate the system roles if they don't exist
     if (\DBUtil::table_exists('roles')) {
         if (\DB::count_records('roles') == 0) {
             $roles = array(\Access::ROLE_ADMIN => 'Admin', \Access::ROLE_DEVELOPER => 'Developer', \Access::ROLE_EDITOR => 'Editor', \Access::ROLE_PENDING => 'Pending', \Access::ROLE_STANDARD => 'Standard', \Access::ROLE_SILVER => 'Silver', \Access::ROLE_GOLD => 'Gold', \Access::ROLE_DUMMY => 'Dummy');
             foreach ($roles as $id => $role) {
                 \DB::insert('roles')->set(array('id' => $id, 'name' => strtolower($role), 'Description' => $role))->execute();
             }
             \Cli::write("\nPopulated roles.");
         }
     }
     //create default admin user if we have no users
     if (\DBUtil::table_exists('users')) {
         if (\DB::count_records('users') == 0) {
             //create the admin user
             $data = array('username' => \Cli::prompt("Please enter an admin username"), 'email' => \Cli::prompt("Please enter an admin email"), 'password' => \Cli::prompt("Please enter an admin password"));
             try {
                 $user = new \Warden\Model_User($data);
                 if (\Config::get('warden.confirmable.in_use') === true) {
                     $user->is_confirmed = true;
                 }
                 \Access::set_roles(array(\Access::ROLE_STANDARD, \Access::ROLE_ADMIN), $user);
                 //this will assign the roles and save the user
                 \Cli::write("\nCreated admin user.");
                 \Cli::write(\Cli::color("\nUsername : {$user->username}", 'blue'));
                 \Cli::write(\Cli::color("\nEmail    : {$user->email}", 'blue'));
             } catch (\Exception $e) {
                 \Cli::error("\n:( Failed to create admin user because: " . $e->getMessage());
             }
         }
     }
     //create the blog table if it doesnt exist
     if (!\DBUtil::table_exists('blogs')) {
         \DBUtil::create_table('blogs', array('id' => array('constraint' => 11, 'type' => 'int', 'unsigned' => true, 'auto_increment' => true), 'user_id' => array('constraint' => 11, 'type' => 'int', 'unsigned' => true), 'title' => array('constraint' => 255, 'type' => 'varchar'), 'post' => array('type' => 'text'), 'publish_flag' => array('constraint' => 11, 'type' => 'int', 'default' => 0, 'unsigned' => true), 'public_flag' => array('constraint' => 11, 'type' => 'int', 'default' => 0, 'unsigned' => true), 'created_at' => array('type' => 'timestamp', 'default' => \DB::expr('CURRENT_TIMESTAMP')), 'updated_at' => array('type' => 'timestamp')), array('id'), true, 'InnoDB');
         \DBUtil::create_index('blogs', 'user_id', 'user_id');
     }
 }
 protected static function usertable()
 {
     if (!\DBUtil::table_exists(static::$data['ormauth_table'])) {
         if (!\DBUtil::table_exists(static::$data['simpleauth_table'])) {
             // table users
             \DBUtil::create_table(static::$data['ormauth_table'], array('id' => array('type' => 'int', 'constraint' => 11, 'auto_increment' => true), 'username' => array('type' => 'varchar', 'constraint' => 50), 'password' => array('type' => 'varchar', 'constraint' => 255), 'group_id' => array('type' => 'int', 'constraint' => 11, 'default' => 1), 'email' => array('type' => 'varchar', 'constraint' => 255), 'last_login' => array('type' => 'varchar', 'constraint' => 25), 'previous_login' => array('type' => 'varchar', 'constraint' => 25, 'default' => 0), 'login_hash' => array('type' => 'varchar', 'constraint' => 255), 'user_id' => array('type' => 'int', 'constraint' => 11, 'default' => 0), 'created_at' => array('type' => 'int', 'constraint' => 11, 'default' => 0), 'updated_at' => array('type' => 'int', 'constraint' => 11, 'default' => 0)), array('id'));
             // add a unique index on username and email
             \DBUtil::create_index(static::$data['ormauth_table'], array('username', 'email'), 'username', 'UNIQUE');
         } else {
             \DBUtil::rename_table(static::$data['simpleauth_table'], static::$data['ormauth_table']);
         }
     }
     // run a check on required fields, and deal with missing ones. we might be migrating from simpleauth
     if (\DBUtil::field_exists(static::$data['ormauth_table'], 'group')) {
         \DBUtil::modify_fields(static::$data['ormauth_table'], array('group' => array('name' => 'group_id', 'type' => 'int', 'constraint' => 11)));
     }
     if (!\DBUtil::field_exists(static::$data['ormauth_table'], 'group_id')) {
         \DBUtil::add_fields(static::$data['ormauth_table'], array('group_id' => array('type' => 'int', 'constraint' => 11, 'default' => 1, 'after' => 'password')));
     }
     if (!\DBUtil::field_exists(static::$data['ormauth_table'], 'previous_login')) {
         \DBUtil::add_fields(static::$data['ormauth_table'], array('previous_login' => array('type' => 'varchar', 'constraint' => 25, 'default' => 0, 'after' => 'last_login')));
     }
     if (!\DBUtil::field_exists(static::$data['ormauth_table'], 'user_id')) {
         \DBUtil::add_fields(static::$data['ormauth_table'], array('user_id' => array('type' => 'int', 'constraint' => 11, 'default' => 0, 'after' => 'login_hash')));
     }
     if (\DBUtil::field_exists(static::$data['ormauth_table'], 'created')) {
         \DBUtil::modify_fields(static::$data['ormauth_table'], array('created' => array('name' => 'created_at', 'type' => 'int', 'constraint' => 11)));
     }
     if (!\DBUtil::field_exists(static::$data['ormauth_table'], 'created_at')) {
         \DBUtil::add_fields(static::$data['ormauth_table'], array('created_at' => array('type' => 'int', 'constraint' => 11, 'default' => 0, 'after' => 'user_id')));
     }
     if (\DBUtil::field_exists(static::$data['ormauth_table'], 'updated')) {
         \DBUtil::modify_fields(static::$data['ormauth_table'], array('updated' => array('name' => 'updated_at', 'type' => 'int', 'constraint' => 11)));
     }
     if (!\DBUtil::field_exists(static::$data['ormauth_table'], 'updated_at')) {
         \DBUtil::add_fields(static::$data['ormauth_table'], array('updated_at' => array('type' => 'int', 'constraint' => 11, 'default' => 0, 'after' => 'created_at')));
     }
 }
 public function up()
 {
     \DBUtil::create_table('authentications', array('id' => array('type' => 'int unsigned', 'auto_increment' => true), 'user_id' => array('type' => 'int unsigned'), 'provider' => array('constraint' => 50, 'type' => 'varchar'), 'uid' => array('constraint' => 255, 'type' => 'varchar'), 'token' => array('constraint' => 255, 'type' => 'varchar'), 'secret' => array('constraint' => 255, 'type' => 'varchar'), 'created_at' => array('constraint' => 11, 'type' => 'int'), 'updated_at' => array('constraint' => 11, 'type' => 'int')), array('id'));
     \DBUtil::create_index('authentications', 'token', 'token');
     \DBUtil::create_index('authentications', 'user_id', 'user_id');
 }
    public function up()
    {
        /*         * *********************************************************************************************
                  graphing
                 * ********************************************************************************************* */
        $graphing = \DBUtil::checkIfExist('graphing');
        if (!$graphing) {
            \DBUtil::create_table('graphing', array('id' => array('constraint' => 11, 'type' => 'int', 'auto_increment' => true), 'name' => array('constraint' => 250, 'type' => 'varchar'), 'value' => array('constraint' => 250, 'type' => 'varchar'), 'meta_update_user' => array('constraint' => 11, 'type' => 'int', 'default' => '0')), array('id'), true, 'InnoDB', 'utf8_unicode_ci');
            \DBUtil::truncate_table('graphing');
            // insert default connector type
            list($insert_id, $rows_affected) = \DB::insert('graphing')->columns(array('id', 'name', 'value', 'meta_update_user'))->values(array('1', 'cacti_size', '1', '1'))->execute();
        }
        /*         * *********************************************************************************************
                  graphing_type
                 * ********************************************************************************************* */
        $graphing_type = \DBUtil::checkIfExist('graphing_type');
        if (!$graphing_type) {
            \DBUtil::create_table('graphing_type', array('id' => array('constraint' => 11, 'type' => 'int', 'auto_increment' => true), 'name' => array('constraint' => 250, 'type' => 'varchar')), array('id'), true, 'InnoDB', 'utf8_unicode_ci');
            \DBUtil::truncate_table('graphing_type');
            // insert default connector type
            list($insert_id, $rows_affected) = \DB::insert('graphing_type')->columns(array('id', 'name'))->values(array('1', 'Cacti'))->execute();
        }
        /*         * *********************************************************************************************
                  graphing_source
                 * ********************************************************************************************* */
        $graphing_source = \DBUtil::checkIfExist('graphing_source');
        if (!$graphing_source) {
            \DBUtil::create_table('graphing_source', array('id' => array('constraint' => 11, 'type' => 'int', 'auto_increment' => true), 'typeID' => array('constraint' => 11, 'type' => 'int'), 'user' => array('constraint' => 250, 'type' => 'varchar'), 'pass' => array('constraint' => 250, 'type' => 'varchar'), 'content' => array('type' => 'text', 'null' => true), 'meta_update_time' => array('constraint' => 11, 'type' => 'int', 'default' => '0'), 'meta_update_user' => array('constraint' => 11, 'type' => 'int', 'default' => '0')), array('id'), true, 'InnoDB', 'utf8_unicode_ci');
            //create indexes for graphing
            \DBUtil::create_index('graphing_source', 'typeID');
        }
        /*         * *********************************************************************************************
                  graphing_cacti
                 * ********************************************************************************************* */
        $graphing_cacti = \DBUtil::checkIfExist('graphing_cacti');
        if (!$graphing_cacti) {
            \DBUtil::create_table('graphing_cacti', array('id' => array('constraint' => 11, 'type' => 'int', 'auto_increment' => true), 'sourceID' => array('constraint' => 11, 'type' => 'int'), 'name' => array('constraint' => 250, 'type' => 'varchar'), 'num' => array('constraint' => 250, 'type' => 'varchar'), 'macID' => array('constraint' => 11, 'type' => 'int'), 'graphID' => array('constraint' => 11, 'type' => 'int'), 'meta_update_time' => array('constraint' => 11, 'type' => 'int', 'default' => '0'), 'meta_update_user' => array('constraint' => 11, 'type' => 'int', 'default' => '0'), 'deviceID' => array('constraint' => 11, 'type' => 'int')), array('id'), true, 'InnoDB', 'utf8_unicode_ci');
            //create indexes for graphing
            \DBUtil::create_index('graphing_cacti', 'deviceID');
            \DBUtil::create_index('graphing_cacti', 'sourceID');
            \DBUtil::create_index('graphing_cacti', 'macID');
        }
        /*         * *********************************************************************************************
                  FOREIGN KEYS
                 * ********************************************************************************************* */
        //graphing
        if (!$graphing_source) {
            $query = \DB::query('ALTER TABLE `graphing_source`
					ADD CONSTRAINT `graphing_ibfk_1` FOREIGN KEY (`typeID`) REFERENCES `graphing_type` (`id`)
					ON DELETE CASCADE ON UPDATE CASCADE')->execute();
        }
        //graphing_cacti
        if (!$graphing_cacti) {
            $query = \DB::query('ALTER TABLE `graphing_cacti`
					ADD CONSTRAINT `graphing_cacti_ibfk_1` FOREIGN KEY (`sourceID`) REFERENCES `graphing_source` (`id`)
					ON DELETE CASCADE ON UPDATE CASCADE')->execute();
            /*
             $query = \DB::query('ALTER TABLE `graphing_cacti`
             ADD CONSTRAINT `graphing_cacti_ibfk_2` FOREIGN KEY (`macID`) REFERENCES `network_mac_ports` (`id`)
             ON DELETE CASCADE ON UPDATE CASCADE')->execute();
            */
            $query = \DB::query('ALTER TABLE `graphing_cacti`
					ADD CONSTRAINT `graphing_cacti_ibfk_3` FOREIGN KEY (`deviceID`) REFERENCES `device` (`id`)
					ON DELETE CASCADE ON UPDATE CASCADE')->execute();
        }
        /*
         * UPDATE version
         *
         * */
        $now = time();
        list($insert_id, $rows_affected) = \DB::insert('version')->columns(array('value', 'meta_update_time'))->values(array('1.09', $now))->execute();
    }
 public function up()
 {
     \DBUtil::create_table('customer_product_options', array('id' => array('type' => 'int', 'constraint' => 11, 'auto_increment' => true), 'customer_id' => array('type' => 'int', 'constraint' => 11), 'product_option_id' => array('type' => 'int', 'constraint' => 11), 'order_id' => array('type' => 'int', 'constraint' => 11), 'name' => array('type' => 'varchar', 'constraint' => 255, 'null' => true), 'status' => array('type' => 'varchar', 'constraint' => 50), 'created_at' => array('type' => 'datetime'), 'updated_at' => array('type' => 'datetime')), array('id'));
     \DBUtil::create_index('customer_product_options', 'customer_id', 'customer_id');
     \DBUtil::create_index('customer_product_options', 'product_option_id', 'product_option_id');
 }
 public function up()
 {
     \DBUtil::create_table('statistic_tasks', array('id' => array('type' => 'int', 'constraint' => 11, 'auto_increment' => true), 'type' => array('type' => 'varchar', 'constraint' => 255), 'message' => array('type' => 'varchar', 'constraint' => 255, 'null' => true), 'status' => array('type' => 'varchar', 'constraint' => 50), 'created_at' => array('type' => 'datetime'), 'updated_at' => array('type' => 'datetime')), array('id'));
     \DBUtil::create_index('statistic_tasks', 'type', 'type');
     \DBUtil::create_index('statistic_tasks', array('type', 'status'), 'type_status');
 }
Exemple #21
0
    public function up()
    {
        //make subnets
        /*         * *********************************************************************************************
                  vps ports
                 * ********************************************************************************************* */
        $vps_ports = \DBUtil::checkIfExist('vps_ports');
        if (!$vps_ports) {
            \DBUtil::create_table('vps_ports', array('id' => array('constraint' => 11, 'type' => 'int', 'auto_increment' => true), 'vpsID' => array('constraint' => 11, 'type' => 'int'), 'portID' => array('constraint' => 11, 'type' => 'int'), 'type' => array('constraint' => 11, 'type' => 'int')), array('id'), true, 'InnoDB', 'utf8_unicode_ci');
            //create indexes for wiki
            \DBUtil::create_index('vps_ports', 'vpsID');
            \DBUtil::create_index('vps_ports', 'portID');
        }
        //ips of vps
        if (!$vps_ports) {
            $query = \DB::query('ALTER TABLE `vps_ports`
					ADD CONSTRAINT `vps_ip__portibfk_1` FOREIGN KEY (`vpsID`) REFERENCES `vps` (`id`)
					ON DELETE CASCADE ON UPDATE CASCADE')->execute();
        }
        //$this->parse_vps_address();
        /*         * *********************************************************************************************
                  monitor_source
                 * *********************************************************************************************
                  $monitor_source=\DBUtil::checkIfExist('monitor_source');
                  if(!$monitor_source){
                  \DBUtil::create_table('monitor_source',array(
                  'id' => array('constraint' => 11, 'type' => 'int', 'auto_increment' => true),
                  'typeID' => array('constraint' => 11, 'type' => 'int'),
                  'user' => array('constraint' => 250, 'type' => 'varchar'),
                  'pass' => array('constraint' => 250, 'type' => 'varchar'),
                  'content' => array('type' => 'text','null'=>true),
                  'meta_update_time' => array('constraint' => 11, 'type' => 'int','default'=>'0'),
                  'meta_update_user' => array('constraint' => 11, 'type' => 'int','default'=>'0')
                  ),
                  array('id'), true, 'InnoDB', 'utf8_unicode_ci'
                  );
        
                  //create indexes for wiki
                  \DBUtil::create_index('monitor_source', 'typeID');
                  }
        
                 */
    }
 public function up()
 {
     \DBUtil::create_table('seller_gateways', array('id' => array('type' => 'int', 'constraint' => 11, 'auto_increment' => true), 'seller_id' => array('type' => 'int', 'constraint' => 11), 'gateway_id' => array('type' => 'int', 'constraint' => 11)), array('id'));
     \DBUtil::create_index('seller_gateways', 'seller_id', 'seller_id');
     \DBUtil::create_index('seller_gateways', 'gateway_id', 'gateway_id');
 }
 function up()
 {
     // get the driver used
     \Config::load('auth', true);
     $drivers = \Config::get('auth.driver', array());
     is_array($drivers) or $drivers = array($drivers);
     if (in_array('Simpleauth', $drivers)) {
         // get the tablename
         \Config::load('simpleauth', true);
         $table = \Config::get('simpleauth.table_name', 'users');
         // only do this if it doesn't exist yet
         if (!\DBUtil::table_exists($table)) {
             // table users
             \DBUtil::create_table($table, array('id' => array('type' => 'int', 'constraint' => 11, 'auto_increment' => true), 'username' => array('type' => 'varchar', 'constraint' => 50), 'password' => array('type' => 'varchar', 'constraint' => 255), 'group' => array('type' => 'int', 'constraint' => 11, 'default' => 1), 'email' => array('type' => 'varchar', 'constraint' => 255), 'last_login' => array('type' => 'varchar', 'constraint' => 25), 'login_hash' => array('type' => 'varchar', 'constraint' => 255), 'profile_fields' => array('type' => 'text'), 'created_at' => array('type' => 'int', 'constraint' => 11, 'default' => 0), 'updated_at' => array('type' => 'int', 'constraint' => 11, 'default' => 0)), array('id'));
             // add a unique index on username and email
             \DBUtil::create_index($table, array('username', 'email'), 'username', 'UNIQUE');
         }
     } elseif (in_array('Ormauth', $drivers)) {
         // get the tablename
         \Config::load('ormauth', true);
         $table = \Config::get('ormauth.table_name', 'users');
         if (!\DBUtil::table_exists($table)) {
             // get the simpleauth tablename, maybe that exists
             \Config::load('simpleauth', true);
             $simpletable = \Config::get('simpleauth.table_name', 'users');
             if (!\DBUtil::table_exists($simpletable)) {
                 // table users
                 \DBUtil::create_table($table, array('id' => array('type' => 'int', 'constraint' => 11, 'auto_increment' => true), 'username' => array('type' => 'varchar', 'constraint' => 50), 'password' => array('type' => 'varchar', 'constraint' => 255), 'group_id' => array('type' => 'int', 'constraint' => 11, 'default' => 1), 'email' => array('type' => 'varchar', 'constraint' => 255), 'last_login' => array('type' => 'varchar', 'constraint' => 25), 'previous_login' => array('type' => 'varchar', 'constraint' => 25, 'default' => 0), 'login_hash' => array('type' => 'varchar', 'constraint' => 255), 'user_id' => array('type' => 'int', 'constraint' => 11, 'default' => 0), 'created_at' => array('type' => 'int', 'constraint' => 11, 'default' => 0), 'updated_at' => array('type' => 'int', 'constraint' => 11, 'default' => 0)), array('id'));
                 // add a unique index on username and email
                 \DBUtil::create_index($table, array('username', 'email'), 'username', 'UNIQUE');
             } else {
                 \DBUtil::rename_table($simpletable, $table);
             }
         }
         // run a check on required fields, and deal with missing ones. we might be migrating from simpleauth
         if (\DBUtil::field_exists($table, 'group')) {
             \DBUtil::modify_fields($table, array('group' => array('name' => 'group_id', 'type' => 'int', 'constraint' => 11)));
         }
         if (!\DBUtil::field_exists($table, 'group_id')) {
             \DBUtil::add_fields($table, array('group_id' => array('type' => 'int', 'constraint' => 11, 'default' => 1, 'after' => 'password')));
         }
         if (!\DBUtil::field_exists($table, 'previous_login')) {
             \DBUtil::add_fields($table, array('previous_login' => array('type' => 'varchar', 'constraint' => 25, 'default' => 0, 'after' => 'last_login')));
         }
         if (!\DBUtil::field_exists($table, 'user_id')) {
             \DBUtil::add_fields($table, array('user_id' => array('type' => 'int', 'constraint' => 11, 'default' => 0, 'after' => 'login_hash')));
         }
         if (\DBUtil::field_exists($table, 'created')) {
             \DBUtil::modify_fields($table, array('created' => array('name' => 'created_at', 'type' => 'int', 'constraint' => 11)));
         }
         if (!\DBUtil::field_exists($table, 'created_at')) {
             \DBUtil::add_fields($table, array('created_at' => array('type' => 'int', 'constraint' => 11, 'default' => 0, 'after' => 'user_id')));
         }
         if (\DBUtil::field_exists($table, 'updated')) {
             \DBUtil::modify_fields($table, array('updated' => array('name' => 'updated_at', 'type' => 'int', 'constraint' => 11)));
         }
         if (!\DBUtil::field_exists($table, 'updated_at')) {
             \DBUtil::add_fields($table, array('updated_at' => array('type' => 'int', 'constraint' => 11, 'default' => 0, 'after' => 'created_at')));
         }
         // table users_meta
         \DBUtil::create_table($table . '_metadata', array('id' => array('type' => 'int', 'constraint' => 11, 'auto_increment' => true), 'parent_id' => array('type' => 'int', 'constraint' => 11, 'default' => 0), 'key' => array('type' => 'varchar', 'constraint' => 20), 'value' => array('type' => 'varchar', 'constraint' => 100), 'user_id' => array('type' => 'int', 'constraint' => 11, 'default' => 0), 'created_at' => array('type' => 'int', 'constraint' => 11, 'default' => 0), 'updated_at' => array('type' => 'int', 'constraint' => 11, 'default' => 0)), array('id'));
         // convert profile fields to metadata, and drop the column
         if (\DBUtil::field_exists($table, 'profile_fields')) {
             $result = \DB::select('id', 'profile_fields')->from($table)->execute();
             foreach ($result as $row) {
                 $profile_fields = empty($row['profile_fields']) ? array() : unserialize($row['profile_fields']);
                 foreach ($profile_fields as $field => $value) {
                     if (!is_numeric($field)) {
                         \DB::insert($table . '_metadata')->set(array('parent_id' => $row['id'], 'key' => $field, 'value' => $value))->execute();
                     }
                 }
             }
             \DBUtil::drop_fields($table, array('profile_fields'));
         }
         // table users_user_role
         \DBUtil::create_table($table . '_user_roles', array('user_id' => array('type' => 'int', 'constraint' => 11), 'role_id' => array('type' => 'int', 'constraint' => 11)), array('user_id', 'role_id'));
         // table users_user_perms
         \DBUtil::create_table($table . '_user_permissions', array('user_id' => array('type' => 'int', 'constraint' => 11), 'perms_id' => array('type' => 'int', 'constraint' => 11)), array('user_id', 'perms_id'));
     }
 }
 public function up()
 {
     \DBUtil::create_table('customer_transactions', array('id' => array('type' => 'int', 'constraint' => 11, 'auto_increment' => true), 'customer_id' => array('type' => 'int', 'constraint' => 11), 'gateway_id' => array('type' => 'int', 'constraint' => 11), 'external_id' => array('type' => 'varchar', 'constraint' => 255, 'null' => true), 'type' => array('type' => 'varchar', 'constraint' => 50), 'provider' => array('type' => 'varchar', 'constraint' => 50), 'account' => array('type' => 'varchar', 'constraint' => 50), 'amount' => array('type' => 'decimal', 'constraint' => '10,2'), 'status' => array('type' => 'varchar', 'constraint' => 50), 'created_at' => array('type' => 'datetime'), 'updated_at' => array('type' => 'datetime')), array('id'));
     \DBUtil::create_index('customer_transactions', 'customer_id', 'customer_id');
     \DBUtil::create_index('customer_transactions', array('customer_id', 'status'), 'customer_status');
 }
 public function up()
 {
     \DBUtil::create_table('product_option_fees', array('id' => array('type' => 'int', 'constraint' => 11, 'auto_increment' => true), 'product_option_id' => array('type' => 'int', 'constraint' => 11), 'name' => array('type' => 'varchar', 'constraint' => 255), 'interval' => array('type' => 'int', 'constraint' => 2), 'interval_unit' => array('type' => 'varchar', 'constraint' => 25), 'interval_price' => array('type' => 'decimal', 'constraint' => '10,2'), 'status' => array('type' => 'varchar', 'constraint' => 50), 'created_at' => array('type' => 'datetime'), 'updated_at' => array('type' => 'datetime')), array('id'));
     \DBUtil::create_index('product_option_fees', 'product_option_id', 'product_option_id');
 }
 public function up()
 {
     \DBUtil::create_table('product_option_metas', array('id' => array('type' => 'int', 'constraint' => 11, 'unsigned' => true, 'auto_increment' => true), 'product_option_id' => array('type' => 'int', 'constraint' => 11, 'unsigned' => true), 'product_meta_option_id' => array('type' => 'int', 'constraint' => 11, 'unsigned' => true)), array('id'));
     \DBUtil::create_index('product_option_metas', 'product_option_id', 'product_option_id');
 }
Exemple #27
0
    function up()
    {
        $user = \DB::select('id')->from('users')->limit(1)->execute()->current();
        /*         * *********************************************************************************************
                  building
                 * ********************************************************************************************* */
        $building = \DBUtil::checkIfExist('building');
        if (!$building) {
            \DBUtil::create_table('building', array('id' => array('constraint' => 11, 'type' => 'int', 'auto_increment' => true), 'name' => array('constraint' => 250, 'type' => 'varchar'), 'name_short' => array('constraint' => 250, 'type' => 'varchar', 'null' => true), 'notes' => array('type' => 'text', 'null' => true), 'meta_default_data' => array('constraint' => 11, 'type' => 'int', 'null' => true, 'default' => '0'), 'meta_update_time' => array('constraint' => 11, 'type' => 'int', 'default' => '0'), 'meta_update_user' => array('constraint' => 11, 'type' => 'int', 'default' => '0')), array('id'), true, 'InnoDB', 'utf8_unicode_ci');
            // insert default building
            list($building_id, $rows_affected) = \DB::insert('building')->columns(array('id', 'name', 'name_short', 'notes', 'meta_default_data', 'meta_update_time', 'meta_update_user'))->values(array('1', 'Building Demo', '', '', '', time(), $user['id']))->execute();
        }
        /*         * *********************************************************************************************
                  cables
                 * ********************************************************************************************* */
        $cables = \DBUtil::checkIfExist('cables');
        if (!$cables) {
            \DBUtil::create_table('cables', array('id' => array('constraint' => 11, 'type' => 'int', 'auto_increment' => true), 'dev1' => array('constraint' => 11, 'type' => 'int'), 'port1' => array('constraint' => 11, 'type' => 'int'), 'name1' => array('constraint' => 4, 'type' => 'int'), 'dev2' => array('constraint' => 11, 'type' => 'int'), 'port2' => array('constraint' => 11, 'type' => 'int'), 'name2' => array('constraint' => 4, 'type' => 'int'), 'type' => array('constraint' => 11, 'type' => 'int'), 'meta_update_time' => array('constraint' => 11, 'type' => 'int', 'default' => '0'), 'meta_update_user' => array('constraint' => 11, 'type' => 'int', 'default' => '0')), array('id'), true, 'InnoDB', 'utf8_unicode_ci');
            //create indexes for cable devices
            \DBUtil::create_index('cables', 'dev1');
            \DBUtil::create_index('cables', 'dev2');
        }
        /*         * *********************************************************************************************
                  connector speed
                 * ********************************************************************************************* */
        $connector_speed = \DBUtil::checkIfExist('connector_speed');
        if (!$connector_speed) {
            \DBUtil::create_table('connector_speed', array('id' => array('constraint' => 11, 'type' => 'int', 'auto_increment' => true), 'name' => array('constraint' => 250, 'type' => 'varchar')), array('id'), true, 'InnoDB', 'utf8_unicode_ci');
            \DBUtil::truncate_table('connector_speed');
            // insert default connector speed
            list($insert_id, $rows_affected) = \DB::insert('connector_speed')->columns(array('id', 'name'))->values(array('1', '10 MBs'), array('2', '10/100 MBs'), array('3', '1 GBs'), array('4', '10 GBs'))->execute();
        }
        /*         * *********************************************************************************************
                  connector type
                 * ********************************************************************************************* */
        $connector_type = \DBUtil::checkIfExist('connector_type');
        if (!$connector_type) {
            \DBUtil::create_table('connector_type', array('id' => array('constraint' => 11, 'type' => 'int', 'auto_increment' => true), 'name' => array('constraint' => 250, 'type' => 'varchar')), array('id'), true, 'InnoDB', 'utf8_unicode_ci');
            \DBUtil::truncate_table('connector_type');
            // insert default connector type
            list($insert_id, $rows_affected) = \DB::insert('connector_type')->columns(array('id', 'name'))->values(array('1', 'RJ45'), array('2', 'Fiber LC'))->execute();
        }
        /*         * *********************************************************************************************
                  device
                 * ********************************************************************************************* */
        $device = \DBUtil::checkIfExist('device');
        if (!$device) {
            \DBUtil::create_table('device', array('id' => array('constraint' => 11, 'type' => 'int', 'auto_increment' => true), 'hostname' => array('constraint' => 250, 'type' => 'varchar'), 'type' => array('constraint' => 11, 'type' => 'int'), 'cat' => array('constraint' => 11, 'type' => 'int'), 'rack' => array('constraint' => 11, 'type' => 'int'), 'rack_pos' => array('constraint' => 11, 'type' => 'int', 'default' => '0'), 'rack_units' => array('constraint' => 11, 'type' => 'int', 'default' => '1'), 'parent_device' => array('constraint' => 11, 'type' => 'int', 'default' => '0'), 'meta_default_data' => array('constraint' => 11, 'type' => 'int', 'default' => '0'), 'meta_update_time' => array('constraint' => 11, 'type' => 'int', 'default' => '0'), 'meta_update_user' => array('constraint' => 11, 'type' => 'int', 'default' => '0')), array('id'), true, 'InnoDB', 'utf8_unicode_ci');
            //create indexes for device
            \DBUtil::create_index('device', 'type');
            \DBUtil::create_index('device', 'cat');
            \DBUtil::create_index('device', 'rack');
        }
        /*         * *********************************************************************************************
                  device category
                 * ********************************************************************************************* */
        $device_category = \DBUtil::checkIfExist('device_category');
        if (!$device_category) {
            \DBUtil::create_table('device_category', array('id' => array('constraint' => 11, 'type' => 'int', 'auto_increment' => true), 'name' => array('constraint' => 250, 'type' => 'varchar')), array('id'), true, 'InnoDB', 'utf8_unicode_ci');
            \DBUtil::truncate_table('device_category');
            // insert default connector type
            list($insert_id, $rows_affected) = \DB::insert('device_category')->columns(array('id', 'name'))->values(array('1', 'Server'), array('2', 'Switch'), array('3', 'Router'), array('4', 'PDU'), array('5', 'Patch Panel'), array('6', 'KVM Switch'), array('7', 'APC ATS'), array('8', 'FC Switch'), array('9', 'Human Interface'), array('10', 'UPS'))->execute();
        }
        /*         * *********************************************************************************************
                  device fieldset
                 * ********************************************************************************************* */
        $device_fieldset = \DBUtil::checkIfExist('device_fieldset');
        if (!$device_fieldset) {
            \DBUtil::create_table('device_fieldset', array('id' => array('constraint' => 11, 'type' => 'int', 'auto_increment' => true), 'name' => array('constraint' => 250, 'type' => 'varchar'), 'type' => array('constraint' => 250, 'type' => 'varchar'), 'deviceID' => array('constraint' => 11, 'type' => 'int'), 'tab' => array('constraint' => 11, 'type' => 'int'), 'value' => array('type' => 'text', 'null' => true), 'extra' => array('constraint' => 250, 'type' => 'varchar', 'null' => true), 'static' => array('constraint' => 1, 'type' => 'int')), array('id'), true, 'InnoDB', 'utf8_unicode_ci');
            //create indexes for device
            \DBUtil::create_index('device_fieldset', 'deviceID');
            //\DBUtil::create_index('device_fieldset',array('name','type','deviceID'),'un_key_field','unique');
        }
        /*         * *********************************************************************************************
                  device KVM
                 * ********************************************************************************************* */
        $device_kvm = \DBUtil::checkIfExist('device_kvm');
        if (!$device_kvm) {
            \DBUtil::create_table('device_kvm', array('id' => array('constraint' => 11, 'type' => 'int', 'auto_increment' => true), 'fieldsetID' => array('constraint' => 11, 'type' => 'int'), 'deviceID' => array('constraint' => 11, 'type' => 'int'), 'input' => array('constraint' => 11, 'type' => 'int'), 'output' => array('constraint' => 11, 'type' => 'int'), 'type' => array('constraint' => 11, 'type' => 'int')), array('id'), true, 'InnoDB', 'utf8_unicode_ci');
            //create indexes for device kvm
            \DBUtil::create_index('device_kvm', 'fieldsetID');
            \DBUtil::create_index('device_kvm', 'deviceID');
        }
        /*         * *********************************************************************************************
                  device KVM socket
                 * ********************************************************************************************* */
        $device_kvm_socket = \DBUtil::checkIfExist('device_kvm_socket');
        if (!$device_kvm_socket) {
            \DBUtil::create_table('device_kvm_socket', array('id' => array('constraint' => 11, 'type' => 'int', 'auto_increment' => true), 'kvmID' => array('constraint' => 11, 'type' => 'int'), 'conn_type' => array('constraint' => 11, 'type' => 'int'), 'type' => array('constraint' => 11, 'type' => 'int')), array('id'), true, 'InnoDB', 'utf8_unicode_ci');
            //create indexes for device kvm socket
            \DBUtil::create_index('device_kvm_socket', 'kvmID');
        }
        /*         * *********************************************************************************************
                  device network
                 * ********************************************************************************************* */
        $device_network = \DBUtil::checkIfExist('device_network');
        if (!$device_network) {
            \DBUtil::create_table('device_network', array('id' => array('constraint' => 11, 'type' => 'int', 'auto_increment' => true), 'fieldsetID' => array('constraint' => 11, 'type' => 'int'), 'deviceID' => array('constraint' => 11, 'type' => 'int'), 'nics' => array('constraint' => 11, 'type' => 'int'), 'vports' => array('constraint' => 11, 'type' => 'int'), 'ports' => array('constraint' => 11, 'type' => 'int'), 'uplinks' => array('constraint' => 11, 'type' => 'int'), 'config_data' => array('type' => 'text'), 'type' => array('constraint' => 11, 'type' => 'int')), array('id'), true, 'InnoDB', 'utf8_unicode_ci');
            //create indexes for device network
            \DBUtil::create_index('device_network', 'fieldsetID');
            \DBUtil::create_index('device_network', 'deviceID');
        }
        /*         * *********************************************************************************************
                  device Power
                 * ********************************************************************************************* */
        $device_power = \DBUtil::checkIfExist('device_power');
        if (!$device_power) {
            \DBUtil::create_table('device_power', array('id' => array('constraint' => 11, 'type' => 'int', 'auto_increment' => true), 'fieldsetID' => array('constraint' => 11, 'type' => 'int'), 'deviceID' => array('constraint' => 11, 'type' => 'int'), 'input' => array('constraint' => 11, 'type' => 'int'), 'output' => array('constraint' => 11, 'type' => 'int'), 'current' => array('constraint' => 11, 'type' => 'int'), 'ru' => array('constraint' => 11, 'type' => 'int'), 'pos' => array('constraint' => 11, 'type' => 'int'), 'type' => array('constraint' => 11, 'type' => 'int')), array('id'), true, 'InnoDB', 'utf8_unicode_ci');
            //create indexes for device kvm
            \DBUtil::create_index('device_power', 'fieldsetID');
            \DBUtil::create_index('device_power', 'deviceID');
        }
        /*         * *********************************************************************************************
                  device Power socket
                 * ********************************************************************************************* */
        $device_power_socket = \DBUtil::checkIfExist('device_power_socket');
        if (!$device_power_socket) {
            \DBUtil::create_table('device_power_socket', array('id' => array('constraint' => 11, 'type' => 'int', 'auto_increment' => true), 'powerID' => array('constraint' => 11, 'type' => 'int'), 'conn_type' => array('constraint' => 11, 'type' => 'int'), 'type' => array('constraint' => 11, 'type' => 'int')), array('id'), true, 'InnoDB', 'utf8_unicode_ci');
            //create indexes for device kvm socket
            \DBUtil::create_index('device_power_socket', 'powerID');
        }
        /*         * *********************************************************************************************
                  device template
                 * ********************************************************************************************* */
        $device_template = \DBUtil::checkIfExist('device_template');
        if (!$device_template) {
            \DBUtil::create_table('device_template', array('id' => array('constraint' => 11, 'type' => 'int', 'auto_increment' => true), 'name' => array('constraint' => 250, 'type' => 'varchar'), 'categoryID' => array('constraint' => 11, 'type' => 'int'), 'hidden' => array('constraint' => 11, 'type' => 'int', 'default' => '0'), 'meta_update_user' => array('constraint' => 11, 'type' => 'int'), 'rack_unit' => array('constraint' => 11, 'type' => 'int')), array('id'), true, 'InnoDB', 'utf8_unicode_ci');
            //create indexes for device template
            \DBUtil::create_index('device_template', 'categoryID');
            \DBUtil::create_index('device_template', 'meta_update_user');
        }
        /*         * *********************************************************************************************
                  device template field
                 * ********************************************************************************************* */
        $device_temp_field = \DBUtil::checkIfExist('device_temp_field');
        if (!$device_temp_field) {
            \DBUtil::create_table('device_temp_field', array('id' => array('constraint' => 11, 'type' => 'int', 'auto_increment' => true), 'templateID' => array('constraint' => 11, 'type' => 'int'), 'tab' => array('constraint' => 2, 'type' => 'int'), 'name' => array('constraint' => 250, 'type' => 'varchar'), 'type' => array('constraint' => 250, 'type' => 'varchar'), 'static' => array('constraint' => 1, 'type' => 'int'), 'extra' => array('constraint' => 250, 'type' => 'varchar', 'null' => true), 'value' => array('constraint' => 250, 'type' => 'varchar', 'null' => true)), array('id'), true, 'InnoDB', 'utf8_unicode_ci');
            //create indexes for device template field
            \DBUtil::create_index('device_temp_field', 'templateID');
        }
        /*         * *********************************************************************************************
                  device template KVM
                 * ********************************************************************************************* */
        $device_temp_kvm = \DBUtil::checkIfExist('device_temp_kvm');
        if (!$device_temp_kvm) {
            \DBUtil::create_table('device_temp_kvm', array('id' => array('constraint' => 11, 'type' => 'int', 'auto_increment' => true), 'fieldsetID' => array('constraint' => 11, 'type' => 'int'), 'templateID' => array('constraint' => 11, 'type' => 'int'), 'input' => array('constraint' => 11, 'type' => 'int'), 'output' => array('constraint' => 11, 'type' => 'int'), 'type' => array('constraint' => 11, 'type' => 'int')), array('id'), true, 'InnoDB', 'utf8_unicode_ci');
            //create indexes for device template kvm
            \DBUtil::create_index('device_temp_kvm', 'fieldsetID');
            \DBUtil::create_index('device_temp_kvm', 'templateID');
        }
        /*         * *********************************************************************************************
                  device template KVM socket
                 * ********************************************************************************************* */
        $device_temp_kvm_socket = \DBUtil::checkIfExist('device_temp_kvm_socket');
        if (!$device_temp_kvm_socket) {
            \DBUtil::create_table('device_temp_kvm_socket', array('id' => array('constraint' => 11, 'type' => 'int', 'auto_increment' => true), 'kvmID' => array('constraint' => 11, 'type' => 'int'), 'conn_type' => array('constraint' => 11, 'type' => 'int'), 'type' => array('constraint' => 11, 'type' => 'int')), array('id'), true, 'InnoDB', 'utf8_unicode_ci');
            //create indexes for device kvm socket
            \DBUtil::create_index('device_temp_kvm_socket', 'kvmID');
        }
        /*         * *********************************************************************************************
                  device template network
                 * ********************************************************************************************* */
        $device_temp_network = \DBUtil::checkIfExist('device_temp_network');
        if (!$device_temp_network) {
            \DBUtil::create_table('device_temp_network', array('id' => array('constraint' => 11, 'type' => 'int', 'auto_increment' => true), 'fieldID' => array('constraint' => 11, 'type' => 'int'), 'templateID' => array('constraint' => 11, 'type' => 'int'), 'nics' => array('constraint' => 11, 'type' => 'int'), 'vports' => array('constraint' => 11, 'type' => 'int'), 'ports' => array('constraint' => 11, 'type' => 'int'), 'uplinks' => array('constraint' => 11, 'type' => 'int'), 'config_data' => array('type' => 'text'), 'type' => array('constraint' => 11, 'type' => 'int')), array('id'), true, 'InnoDB', 'utf8_unicode_ci');
            //create indexes for device network
            \DBUtil::create_index('device_temp_network', 'fieldID');
            \DBUtil::create_index('device_temp_network', 'templateID');
        }
        /*         * *********************************************************************************************
                  device template Power
                 * ********************************************************************************************* */
        $device_temp_power = \DBUtil::checkIfExist('device_temp_power');
        if (!$device_temp_power) {
            \DBUtil::create_table('device_temp_power', array('id' => array('constraint' => 11, 'type' => 'int', 'auto_increment' => true), 'fieldsetID' => array('constraint' => 11, 'type' => 'int'), 'templateID' => array('constraint' => 11, 'type' => 'int'), 'input' => array('constraint' => 11, 'type' => 'int'), 'output' => array('constraint' => 11, 'type' => 'int'), 'current' => array('constraint' => 11, 'type' => 'int'), 'ru' => array('constraint' => 11, 'type' => 'int'), 'pos' => array('constraint' => 11, 'type' => 'int'), 'type' => array('constraint' => 11, 'type' => 'int')), array('id'), true, 'InnoDB', 'utf8_unicode_ci');
            //create indexes for device template power
            \DBUtil::create_index('device_temp_power', 'fieldsetID');
            \DBUtil::create_index('device_temp_power', 'templateID');
        }
        /*         * *********************************************************************************************
                  device template Power socket
                 * ********************************************************************************************* */
        $device_temp_power_socket = \DBUtil::checkIfExist('device_temp_power_socket');
        if (!$device_temp_power_socket) {
            \DBUtil::create_table('device_temp_power_socket', array('id' => array('constraint' => 11, 'type' => 'int', 'auto_increment' => true), 'powerID' => array('constraint' => 11, 'type' => 'int'), 'conn_type' => array('constraint' => 11, 'type' => 'int'), 'type' => array('constraint' => 11, 'type' => 'int')), array('id'), true, 'InnoDB', 'utf8_unicode_ci');
            //create indexes for device kvm socket
            \DBUtil::create_index('device_temp_power_socket', 'powerID');
        }
        /*         * *********************************************************************************************
                  floor
                 * ********************************************************************************************* */
        $floor = \DBUtil::checkIfExist('floor');
        if (!$floor) {
            \DBUtil::create_table('floor', array('id' => array('constraint' => 11, 'type' => 'int', 'auto_increment' => true), 'name' => array('constraint' => 250, 'type' => 'varchar'), 'building' => array('constraint' => 11, 'type' => 'int'), 'has_rooms' => array('constraint' => 11, 'type' => 'int', 'default' => '0', 'null' => true), 'notes' => array('type' => 'text', 'null' => true), 'meta_default_data' => array('constraint' => 11, 'type' => 'int', 'default' => '0', 'null' => true), 'meta_update_time' => array('constraint' => 11, 'type' => 'int', 'default' => '0'), 'meta_update_user' => array('constraint' => 11, 'type' => 'int', 'default' => '0')), array('id'), true, 'InnoDB', 'utf8_unicode_ci');
            //create indexes for floor
            \DBUtil::create_index('floor', 'building');
            // insert default building
            list($floor_id, $rows_affected) = \DB::insert('floor')->columns(array('id', 'name', 'building', 'has_rooms', 'notes', 'meta_default_data', 'meta_update_time', 'meta_update_user'))->values(array('1', 'Floor 1', $building_id[0], '', '', '', time(), $user['id']))->execute();
        }
        /*         * *********************************************************************************************
                  hardware raid
                 * ********************************************************************************************* */
        $hardware_raid = \DBUtil::checkIfExist('hardware_raid');
        if (!$hardware_raid) {
            \DBUtil::create_table('hardware_raid', array('id' => array('constraint' => 11, 'type' => 'int', 'auto_increment' => true), 'fieldsetID' => array('constraint' => 11, 'type' => 'int', 'null' => true), 'raid_type' => array('constraint' => 11, 'type' => 'int', 'null' => true), 'size' => array('constraint' => 250, 'type' => 'varchar', 'null' => true), 'total' => array('constraint' => 11, 'type' => 'int', 'null' => true), 'meta_update_time' => array('constraint' => 11, 'type' => 'int', 'default' => '0'), 'meta_update_user' => array('constraint' => 11, 'type' => 'int', 'default' => '0'), 'tempfieldID' => array('constraint' => 11, 'type' => 'int', 'null' => true)), array('id'), true, 'InnoDB', 'utf8_unicode_ci');
            //create indexes for hardware raid
            \DBUtil::create_index('hardware_raid', 'raid_type');
            //\DBUtil::create_index('hardware_raid', 'fieldsetID');
        }
        /*         * *********************************************************************************************
                  hardware raid data
                 * ********************************************************************************************* */
        $hardware_raid_data = \DBUtil::checkIfExist('hardware_raid_data');
        if (!$hardware_raid_data) {
            \DBUtil::create_table('hardware_raid_data', array('id' => array('constraint' => 11, 'type' => 'int', 'auto_increment' => true), 'hardware_raid' => array('constraint' => 11, 'type' => 'int'), 'model' => array('constraint' => 250, 'type' => 'varchar'), 'size' => array('constraint' => 250, 'type' => 'varchar', 'null' => true), 'vport' => array('constraint' => 250, 'type' => 'varchar'), 'meta_update_time' => array('constraint' => 11, 'type' => 'int', 'default' => '0'), 'meta_update_user' => array('constraint' => 11, 'type' => 'int', 'default' => '0'), 'serial_number' => array('constraint' => 250, 'type' => 'varchar')), array('id'), true, 'InnoDB', 'utf8_unicode_ci');
            //create indexes for hardware raid
            \DBUtil::create_index('hardware_raid_data', 'hardware_raid');
        }
        /*         * *********************************************************************************************
                  hardware ram
                 * ********************************************************************************************* */
        $hardware_ram = \DBUtil::checkIfExist('hardware_ram');
        if (!$hardware_ram) {
            \DBUtil::create_table('hardware_ram', array('id' => array('constraint' => 11, 'type' => 'int', 'auto_increment' => true), 'fieldsetID' => array('constraint' => 11, 'type' => 'int', 'null' => true), 'ram_type' => array('constraint' => 11, 'type' => 'int', 'null' => true), 'size' => array('constraint' => 250, 'type' => 'varchar', 'null' => true), 'total' => array('constraint' => 11, 'type' => 'int', 'null' => true), 'meta_update_time' => array('constraint' => 11, 'type' => 'int', 'default' => '0'), 'meta_update_user' => array('constraint' => 11, 'type' => 'int', 'default' => '0'), 'tempfieldID' => array('constraint' => 11, 'type' => 'int', 'null' => true)), array('id'), true, 'InnoDB', 'utf8_unicode_ci');
            //create indexes for hardware raid
            \DBUtil::create_index('hardware_ram', 'ram_type');
            //\DBUtil::create_index('hardware_ram', 'fieldsetID');
        }
        /*         * *********************************************************************************************
                  hardware ram data
                 * ********************************************************************************************* */
        $hardware_ram_data = \DBUtil::checkIfExist('hardware_ram_data');
        if (!$hardware_ram_data) {
            \DBUtil::create_table('hardware_ram_data', array('id' => array('constraint' => 11, 'type' => 'int', 'auto_increment' => true), 'hardware_ram' => array('constraint' => 11, 'type' => 'int'), 'model' => array('constraint' => 250, 'type' => 'varchar'), 'size' => array('constraint' => 250, 'type' => 'varchar'), 'port' => array('constraint' => 250, 'type' => 'varchar'), 'meta_update_time' => array('constraint' => 11, 'type' => 'int', 'default' => '0'), 'meta_update_user' => array('constraint' => 11, 'type' => 'int', 'default' => '0'), 'serial_number' => array('constraint' => 250, 'type' => 'varchar')), array('id'), true, 'InnoDB', 'utf8_unicode_ci');
            //create indexes for hardware ram
            \DBUtil::create_index('hardware_ram_data', 'hardware_ram');
        }
        /*         * *********************************************************************************************
                  images
                 * ********************************************************************************************* */
        $images = \DBUtil::checkIfExist('images');
        if (!$images) {
            \DBUtil::create_table('images', array('id' => array('constraint' => 11, 'type' => 'int', 'auto_increment' => true), 'name' => array('constraint' => 250, 'type' => 'varchar'), 'elementID' => array('constraint' => 11, 'type' => 'int'), 'type' => array('constraint' => 1, 'type' => 'varchar'), 'width' => array('constraint' => 11, 'type' => 'int'), 'height' => array('constraint' => 11, 'type' => 'int')), array('id'), true, 'InnoDB', 'utf8_unicode_ci');
            //create indexes for images
            \DBUtil::create_index('images', 'elementID');
        }
        /*         * *********************************************************************************************
                  network ip ports
                 * ********************************************************************************************* */
        $network_ip_ports = \DBUtil::checkIfExist('network_ip_ports');
        if (!$network_ip_ports) {
            \DBUtil::create_table('network_ip_ports', array('id' => array('constraint' => 11, 'type' => 'int', 'auto_increment' => true), 'networkID' => array('constraint' => 11, 'type' => 'int'), 'nic_name' => array('constraint' => 250, 'type' => 'varchar'), 'ipv4' => array('constraint' => 15, 'type' => 'varchar'), 'ipv6' => array('constraint' => 42, 'type' => 'varchar'), 'conn_type' => array('constraint' => 11, 'type' => 'int'), 'conn_speed' => array('constraint' => 11, 'type' => 'int'), 'type' => array('constraint' => 11, 'type' => 'int')), array('id'), true, 'InnoDB', 'utf8_unicode_ci');
            //create indexes for network ip ports
            \DBUtil::create_index('network_ip_ports', 'networkID');
            \DBUtil::create_index('network_ip_ports', 'conn_type');
            \DBUtil::create_index('network_ip_ports', 'conn_speed');
        }
        /*         * *********************************************************************************************
                  network mac ports
                 * ********************************************************************************************* */
        $network_mac_ports = \DBUtil::checkIfExist('network_mac_ports');
        if (!$network_mac_ports) {
            \DBUtil::create_table('network_mac_ports', array('id' => array('constraint' => 11, 'type' => 'int', 'auto_increment' => true), 'networkID' => array('constraint' => 11, 'type' => 'int'), 'mac_address' => array('constraint' => 18, 'type' => 'varchar'), 'conn_device' => array('constraint' => 11, 'type' => 'int'), 'vlan' => array('constraint' => 11, 'type' => 'int', 'null' => true), 'type' => array('constraint' => 2, 'type' => 'int')), array('id'), true, 'InnoDB', 'utf8_unicode_ci');
            //create indexes for network mac ports
            \DBUtil::create_index('network_mac_ports', 'networkID');
            \DBUtil::create_index('network_mac_ports', 'conn_device');
            \DBUtil::create_index('network_mac_ports', 'vlan');
        }
        /*         * *********************************************************************************************
                  network vlans
                 * ********************************************************************************************* */
        $network_vlans = \DBUtil::checkIfExist('network_vlans');
        if (!$network_vlans) {
            \DBUtil::create_table('network_vlans', array('id' => array('constraint' => 11, 'type' => 'int', 'auto_increment' => true), 'networkID' => array('constraint' => 11, 'type' => 'int'), 'name' => array('constraint' => 250, 'type' => 'varchar')), array('id'), true, 'InnoDB', 'utf8_unicode_ci');
            //create indexes for network mac ports
            \DBUtil::create_index('network_vlans', 'networkID');
        }
        /*         * *********************************************************************************************
                  notes
                 * ********************************************************************************************* */
        $notes = \DBUtil::checkIfExist('notes');
        if (!$notes) {
            \DBUtil::create_table('notes', array('id' => array('constraint' => 11, 'type' => 'int', 'auto_increment' => true), 'deviceID' => array('constraint' => 11, 'type' => 'int'), 'txt' => array('type' => 'text'), 'meta_update_time' => array('constraint' => 11, 'type' => 'int', 'default' => '0'), 'meta_update_user' => array('constraint' => 11, 'type' => 'int', 'default' => '0')), array('id'), true, 'InnoDB', 'utf8_unicode_ci');
            //create indexes for notes
            \DBUtil::create_index('notes', 'deviceID');
        }
        /*         * *********************************************************************************************
                  RAID type
                 * ********************************************************************************************* */
        $raid_type = \DBUtil::checkIfExist('raid_type');
        if (!$raid_type) {
            \DBUtil::create_table('raid_type', array('id' => array('constraint' => 11, 'type' => 'int', 'auto_increment' => true), 'name' => array('constraint' => 250, 'type' => 'varchar')), array('id'), true, 'InnoDB', 'utf8_unicode_ci');
            \DBUtil::truncate_table('raid_type');
            // insert default raid type
            list($insert_id, $rows_affected) = \DB::insert('raid_type')->columns(array('id', 'name'))->values(array('1', 'none'), array('2', 'RAID 0'), array('3', 'RAID 1'), array('4', 'RAID 2'), array('5', 'RAID 3'), array('6', 'RAID 4'), array('7', 'RAID 5'), array('8', 'RAID 6'), array('9', 'RAID 7'), array('10', 'RAID 10'), array('11', 'RAID S (parity RAID)'), array('12', 'RAID-DP'), array('13', 'Matrix RAID'), array('14', 'RAID-K'), array('15', 'RAID-Z'), array('16', 'RAID 1.5'), array('17', 'RAIDn'), array('18', 'Linux MD RAID 10'), array('19', 'IBM ServeRAID 1E'), array('20', 'ineo Complex RAID'), array('21', 'Drobo BeyondRAID'), array('22', 'nunRAID'))->execute();
        }
        /*         * *********************************************************************************************
                  RAM type
                 * ********************************************************************************************* */
        $ram_type = \DBUtil::checkIfExist('ram_type');
        if (!$ram_type) {
            \DBUtil::create_table('ram_type', array('id' => array('constraint' => 11, 'type' => 'int', 'auto_increment' => true), 'name' => array('constraint' => 250, 'type' => 'varchar')), array('id'), true, 'InnoDB', 'utf8_unicode_ci');
            \DBUtil::truncate_table('ram_type');
            // insert default ram type
            list($insert_id, $rows_affected) = \DB::insert('ram_type')->columns(array('id', 'name'))->values(array('1', 'none'), array('2', 'SDRAM'), array('3', 'RDRAM'), array('4', 'DDR1'), array('5', 'DDR2'), array('6', 'DDR3'), array('7', 'DDR4'))->execute();
        }
        /*         * *********************************************************************************************
                  room
                 * ********************************************************************************************* */
        $room = \DBUtil::checkIfExist('room');
        if (!$room) {
            \DBUtil::create_table('room', array('id' => array('constraint' => 11, 'type' => 'int', 'auto_increment' => true), 'name' => array('constraint' => 250, 'type' => 'varchar'), 'floor' => array('constraint' => 11, 'type' => 'int'), 'has_racks' => array('constraint' => 11, 'type' => 'int', 'default' => '0', 'null' => true), 'notes' => array('type' => 'text', 'null' => true), 'meta_default_data' => array('constraint' => 11, 'type' => 'int', 'default' => '0', 'null' => true), 'meta_update_time' => array('constraint' => 11, 'type' => 'int', 'default' => '0'), 'meta_update_user' => array('constraint' => 11, 'type' => 'int', 'default' => '0')), array('id'), true, 'InnoDB', 'utf8_unicode_ci');
            //create indexes for network mac ports
            \DBUtil::create_index('room', 'floor');
            //insert default room
            list($room_id, $rows_affected) = \DB::insert('room')->columns(array('id', 'name', 'floor', 'has_racks', 'notes', 'meta_default_data', 'meta_update_time', 'meta_update_user'))->values(array('1', 'Room A', $floor_id[0], '', '', '0', time(), $user['id']))->execute();
        }
        /*         * *********************************************************************************************
                  rack
                 * ********************************************************************************************* */
        $rack = \DBUtil::checkIfExist('rack');
        if (!$rack) {
            \DBUtil::create_table('rack', array('id' => array('constraint' => 11, 'type' => 'int', 'auto_increment' => true), 'name' => array('constraint' => 250, 'type' => 'varchar'), 'room' => array('constraint' => 11, 'type' => 'int'), 'room_pos' => array('constraint' => 11, 'type' => 'int', 'default' => '0'), 'hidden_rack' => array('constraint' => 11, 'type' => 'int', 'default' => '0'), 'size' => array('constraint' => 11, 'type' => 'int', 'default' => '42'), 'numbering_direction' => array('constraint' => 11, 'type' => 'int', 'default' => '0'), 'notes' => array('type' => 'text', 'null' => true), 'meta_default_data' => array('constraint' => 11, 'type' => 'int', 'default' => '0'), 'meta_update_time' => array('constraint' => 11, 'type' => 'int', 'default' => '0'), 'meta_update_user' => array('constraint' => 11, 'type' => 'int', 'default' => '0')), array('id'), true, 'InnoDB', 'utf8_unicode_ci');
            //create indexes for network mac ports
            \DBUtil::create_index('rack', 'room');
            // insert default rack
            list($rack_id, $rows_affected) = \DB::insert('rack')->columns(array('id', 'name', 'room', 'room_pos', 'hidden_rack', 'size', 'numbering_direction', 'notes', 'meta_default_data', 'meta_update_time', 'meta_update_user'))->values(array('1', 'Default Rack', $room_id[0], 0, 0, 42, 0, '', '0', time(), $user['id']))->execute();
        }
        /*         * *********************************************************************************************
                  template network ip ports
                 * ********************************************************************************************* */
        $temp_network_ip_ports = \DBUtil::checkIfExist('temp_network_ip_ports');
        if (!$temp_network_ip_ports) {
            \DBUtil::create_table('temp_network_ip_ports', array('id' => array('constraint' => 11, 'type' => 'int', 'auto_increment' => true), 'tempnetID' => array('constraint' => 11, 'type' => 'int'), 'nic_name' => array('constraint' => 250, 'type' => 'varchar', 'null' => true), 'ipv4' => array('constraint' => 15, 'type' => 'varchar', 'null' => true), 'ipv6' => array('constraint' => 42, 'type' => 'varchar', 'null' => true), 'conn_type' => array('constraint' => 11, 'type' => 'int', 'null' => true), 'conn_speed' => array('constraint' => 11, 'type' => 'int', 'null' => true), 'type' => array('constraint' => 11, 'type' => 'int')), array('id'), true, 'InnoDB', 'utf8_unicode_ci');
            //create indexes for network ip ports
            \DBUtil::create_index('temp_network_ip_ports', 'tempnetID');
            \DBUtil::create_index('temp_network_ip_ports', 'conn_type');
            \DBUtil::create_index('temp_network_ip_ports', 'conn_speed');
        }
        /*         * *********************************************************************************************
                  template network mac ports
                 * ********************************************************************************************* */
        $temp_network_mac_ports = \DBUtil::checkIfExist('temp_network_mac_ports');
        if (!$temp_network_mac_ports) {
            \DBUtil::create_table('temp_network_mac_ports', array('id' => array('constraint' => 11, 'type' => 'int', 'auto_increment' => true), 'tempnetID' => array('constraint' => 11, 'type' => 'int'), 'mac_address' => array('constraint' => 18, 'type' => 'varchar'), 'conn_device' => array('constraint' => 11, 'type' => 'int'), 'vlan' => array('constraint' => 11, 'type' => 'int', 'null' => true), 'type' => array('constraint' => 2, 'type' => 'int')), array('id'), true, 'InnoDB', 'utf8_unicode_ci');
            //create indexes for network mac ports
            \DBUtil::create_index('temp_network_mac_ports', 'tempnetID');
            \DBUtil::create_index('temp_network_mac_ports', 'conn_device');
            \DBUtil::create_index('temp_network_mac_ports', 'vlan');
        }
        /*         * *********************************************************************************************
                  template network vlans
                 * ********************************************************************************************* */
        $temp_network_vlans = \DBUtil::checkIfExist('temp_network_vlans');
        if (!$temp_network_vlans) {
            \DBUtil::create_table('temp_network_vlans', array('id' => array('constraint' => 11, 'type' => 'int', 'auto_increment' => true), 'tempnetID' => array('constraint' => 11, 'type' => 'int'), 'name' => array('constraint' => 250, 'type' => 'varchar')), array('id'), true, 'InnoDB', 'utf8_unicode_ci');
            //create indexes for network mac ports
            \DBUtil::create_index('temp_network_vlans', 'tempnetID');
        }
        /*         * *********************************************************************************************
                  template images
                 * ********************************************************************************************* */
        $temp_images = \DBUtil::checkIfExist('temp_images');
        if (!$temp_images) {
            \DBUtil::create_table('temp_images', array('id' => array('constraint' => 11, 'type' => 'int', 'auto_increment' => true), 'name' => array('constraint' => 250, 'type' => 'varchar'), 'elementID' => array('constraint' => 11, 'type' => 'int'), 'type' => array('constraint' => 1, 'type' => 'varchar'), 'width' => array('constraint' => 11, 'type' => 'int'), 'height' => array('constraint' => 11, 'type' => 'int')), array('id'), true, 'InnoDB', 'utf8_unicode_ci');
            //create indexes for images
            \DBUtil::create_index('temp_images', 'elementID');
        }
        /*         * *********************************************************************************************
                  wiki category
                 * ********************************************************************************************* */
        $wiki_categories = \DBUtil::checkIfExist('wiki_categories');
        if (!$wiki_categories) {
            \DBUtil::create_table('wiki_categories', array('id' => array('constraint' => 11, 'type' => 'int', 'auto_increment' => true), 'name' => array('constraint' => 250, 'type' => 'varchar')), array('id'), true, 'InnoDB', 'utf8_unicode_ci');
            \DBUtil::truncate_table('wiki_categories');
            // insert default connector type
            list($insert_id, $rows_affected) = \DB::insert('wiki_categories')->columns(array('id', 'name'))->values(array('1', 'General'), array('2', 'Installation'), array('3', 'Devices'), array('4', 'Maintenance'))->execute();
        }
        /*         * *********************************************************************************************
                  wiki
                 * ********************************************************************************************* */
        $wiki = \DBUtil::checkIfExist('wiki');
        if (!$wiki) {
            \DBUtil::create_table('wiki', array('id' => array('constraint' => 11, 'type' => 'int', 'auto_increment' => true), 'catID' => array('constraint' => 11, 'type' => 'int'), 'title' => array('constraint' => 250, 'type' => 'varchar'), 'content' => array('type' => 'text', 'null' => true), 'meta_update_time' => array('constraint' => 11, 'type' => 'int', 'default' => '0'), 'meta_update_user' => array('constraint' => 11, 'type' => 'int', 'default' => '0')), array('id'), true, 'InnoDB', 'utf8_unicode_ci');
            //create indexes for wiki
            \DBUtil::create_index('wiki', 'catID');
        }
        /*         * *********************************************************************************************
                  vps
                 * ********************************************************************************************* */
        $vps = \DBUtil::checkIfExist('vps');
        if (!$vps) {
            \DBUtil::create_table('vps', array('id' => array('constraint' => 11, 'type' => 'int', 'auto_increment' => true), 'masterID' => array('constraint' => 11, 'type' => 'int'), 'hostname' => array('constraint' => 250, 'type' => 'varchar'), 'cpu' => array('constraint' => 11, 'type' => 'int'), 'ram' => array('constraint' => 11, 'type' => 'int'), 'storage' => array('constraint' => 11, 'type' => 'int')), array('id'), true, 'InnoDB', 'utf8_unicode_ci');
            //create indexes for wiki
            \DBUtil::create_index('vps', 'masterID');
        }
        /*         * *********************************************************************************************
                  vps
                 * ********************************************************************************************* */
        /*
         $vps_ip_ports = \DBUtil::checkIfExist('vps_ip_ports');
         if (!$vps_ip_ports) {
         \DBUtil::create_table('vps_ip_ports', array(
         'id' => array('constraint' => 11, 'type' => 'int', 'auto_increment' => true),
         'vpsID' => array('constraint' => 11, 'type' => 'int'),
         'data' => array('constraint' => 250, 'type' => 'varchar')
         ), array('id'), true, 'InnoDB', 'utf8_unicode_ci'
         );
        
         //create indexes for wiki
         \DBUtil::create_index('vps_ip_ports', 'vpsID');
         }
        */
        /*         * *********************************************************************************************
                  FOREIGN KEYS
                 * ********************************************************************************************* */
        if (!$cables) {
            $query = \DB::query('ALTER TABLE `cables`
		ADD CONSTRAINT `cables_ibfk_1` FOREIGN KEY (`dev1`) REFERENCES `device` (`id`) 
		ON DELETE CASCADE ON UPDATE CASCADE')->execute();
            $query = \DB::query('ALTER TABLE `cables`
  		ADD CONSTRAINT `cables_ibfk_2` FOREIGN KEY (`dev2`) REFERENCES `device` (`id`) 
		ON DELETE CASCADE ON UPDATE CASCADE')->execute();
        }
        if (!$device) {
            $query = \DB::query('ALTER TABLE `device`
		ADD CONSTRAINT `device_ibfk_2` FOREIGN KEY (`rack`) REFERENCES `rack` (`id`)
			ON DELETE CASCADE ON UPDATE CASCADE')->execute();
        }
        if (!$device_fieldset) {
            $query = \DB::query('ALTER TABLE `device_fieldset` ADD CONSTRAINT `device_fieldset_ibfk_1`
		FOREIGN KEY (`deviceID`) REFERENCES `device` (`id`) 
		ON DELETE CASCADE ON UPDATE CASCADE')->execute();
        }
        if (!$device_kvm) {
            $query = \DB::query('ALTER TABLE `device_kvm`
  			ADD CONSTRAINT `device_kvm_ibfk_1` FOREIGN KEY (`fieldsetID`) 
			REFERENCES `device_fieldset` (`id`) ON DELETE CASCADE ON UPDATE CASCADE')->execute();
        }
        if (!$device_kvm_socket) {
            $query = \DB::query('ALTER TABLE `device_kvm_socket`
  			ADD CONSTRAINT `device_kvm_socket_ibfk_1` FOREIGN KEY (`kvmID`) 
			REFERENCES `device_kvm` (`id`) ON DELETE CASCADE ON UPDATE CASCADE')->execute();
        }
        if (!$device_network) {
            $query = \DB::query('ALTER TABLE `device_network` ADD CONSTRAINT `device_network_ibfk_2`
		FOREIGN KEY (`fieldsetID`) REFERENCES `device_fieldset` (`id`) 
		ON DELETE  CASCADE ON UPDATE CASCADE;')->execute();
        }
        if (!$device_power) {
            $query = \DB::query('ALTER TABLE `device_power`
  			ADD CONSTRAINT `device_power_ibfk_1` FOREIGN KEY (`fieldsetID`) 
			REFERENCES `device_fieldset` (`id`) ON DELETE CASCADE ON UPDATE CASCADE')->execute();
        }
        if (!$device_power_socket) {
            $query = \DB::query('ALTER TABLE `device_power_socket`
  			ADD CONSTRAINT `device_power_socket_ibfk_1` FOREIGN KEY (`powerID`) 
			REFERENCES `device_power` (`id`) ON DELETE CASCADE ON UPDATE CASCADE;')->execute();
        }
        if (!$device_template) {
            $query = \DB::query('ALTER TABLE `device_template` ADD CONSTRAINT `device_template_ibfk_1`
		FOREIGN KEY (`categoryID`) REFERENCES `device_category` (`id`) 
		ON DELETE CASCADE ON UPDATE CASCADE;')->execute();
        }
        if (!$device_temp_field) {
            $query = \DB::query('ALTER TABLE `device_temp_field` ADD CONSTRAINT `device_temp_field_ibfk_2`
		FOREIGN KEY (`templateID`) REFERENCES `device_template` (`id`) 
		ON DELETE CASCADE ON UPDATE CASCADE;')->execute();
        }
        if (!$device_temp_kvm) {
            $query = \DB::query('ALTER TABLE `device_temp_kvm`
  		ADD CONSTRAINT `device_temp_kvm_ibfk_1` FOREIGN KEY (`fieldsetID`) 
		REFERENCES `device_temp_field` (`id`) ON DELETE CASCADE ON UPDATE CASCADE;')->execute();
        }
        if (!$device_temp_kvm_socket) {
            $query = \DB::query('ALTER TABLE `device_temp_kvm_socket`
  		ADD CONSTRAINT `device_temp_kvm_socket_ibfk_1` FOREIGN KEY (`kvmID`) 
		REFERENCES `device_temp_kvm` (`id`) ON DELETE CASCADE ON UPDATE CASCADE;')->execute();
        }
        if (!$device_temp_network) {
            $query = \DB::query('ALTER TABLE `device_temp_network`
  		ADD CONSTRAINT `device_temp_network_ibfk_1` FOREIGN KEY (`fieldID`) 
		REFERENCES `device_temp_field` (`id`) ON DELETE CASCADE ON UPDATE CASCADE;')->execute();
        }
        if (!$device_temp_power) {
            $query = \DB::query('ALTER TABLE `device_temp_power`
  		ADD CONSTRAINT `device_temp_power_ibfk_1` FOREIGN KEY (`fieldsetID`) 
		REFERENCES `device_temp_field` (`id`) ON DELETE CASCADE ON UPDATE CASCADE')->execute();
        }
        if (!$device_temp_power_socket) {
            $query = \DB::query('ALTER TABLE `device_temp_power_socket`
  		ADD CONSTRAINT `device_temp_power_socket_ibfk_1` FOREIGN KEY (`powerID`) 
		REFERENCES `device_temp_power` (`id`) ON DELETE CASCADE ON UPDATE CASCADE')->execute();
        }
        if (!$floor) {
            $query = \DB::query('ALTER TABLE `floor` ADD CONSTRAINT `floor_ibfk_4`
		FOREIGN KEY (`building`) REFERENCES `building` (`id`) 
		ON DELETE CASCADE ON UPDATE CASCADE;')->execute();
        }
        if (!$hardware_raid) {
            $query = \DB::query('ALTER TABLE `hardware_raid`  ADD CONSTRAINT `hardware_raid_ibfk_2`
		FOREIGN KEY (`raid_type`) REFERENCES `raid_type` (`id`);')->execute();
        }
        if (!$hardware_raid_data) {
            $query = \DB::query('ALTER TABLE `hardware_raid_data` ADD CONSTRAINT `hardware_raid_data_ibfk_2`
		FOREIGN KEY (`hardware_raid`) REFERENCES `hardware_raid` (`id`) 
		ON DELETE CASCADE ON UPDATE CASCADE;')->execute();
        }
        if (!$images) {
            $query = \DB::query('ALTER TABLE `images` ADD CONSTRAINT `images_ibfk_2`
		FOREIGN KEY (`elementID`) REFERENCES `device_fieldset` (`id`) 
		ON DELETE CASCADE ON UPDATE CASCADE;')->execute();
        }
        if (!$network_ip_ports) {
            $query = \DB::query('ALTER TABLE `network_ip_ports` ADD CONSTRAINT `network_ip_ports_ibfk_4`
		FOREIGN KEY (`networkID`) REFERENCES `device_network` (`id`) 
		ON DELETE CASCADE ON UPDATE CASCADE;')->execute();
        }
        if (!$network_mac_ports) {
            $query = \DB::query('ALTER TABLE `network_mac_ports` ADD CONSTRAINT `network_mac_ports_ibfk_1`
		FOREIGN KEY (`networkID`) REFERENCES `device_network` (`id`) 
		ON DELETE CASCADE ON UPDATE CASCADE;')->execute();
        }
        if (!$network_vlans) {
            $query = \DB::query('ALTER TABLE `network_vlans` ADD CONSTRAINT `network_vlans_ibfk_3`
		FOREIGN KEY (`networkID`) REFERENCES `device_network` (`id`) 
		ON DELETE CASCADE ON UPDATE CASCADE;')->execute();
        }
        if (!$notes) {
            $query = \DB::query('ALTER TABLE `notes` ADD CONSTRAINT `notes_ibfk_1`
		FOREIGN KEY (`deviceID`) REFERENCES `device` (`id`) 
		ON DELETE CASCADE ON UPDATE CASCADE;')->execute();
        }
        if (!$rack) {
            $query = \DB::query('ALTER TABLE `rack` ADD CONSTRAINT `rack_ibfk_2`
		FOREIGN KEY (`room`) REFERENCES `room` (`id`) 
		ON DELETE CASCADE ON UPDATE CASCADE;')->execute();
        }
        if (!$room) {
            $query = \DB::query('ALTER TABLE `room` ADD CONSTRAINT `room_ibfk_2`
		FOREIGN KEY (`floor`) REFERENCES `floor` (`id`) 
		ON DELETE CASCADE ON UPDATE CASCADE;')->execute();
        }
        if (!$temp_network_ip_ports) {
            $query = \DB::query('ALTER TABLE `temp_network_ip_ports` ADD CONSTRAINT `temp_network_ip_ports_ibfk_4`
		FOREIGN KEY (`tempnetID`) REFERENCES `device_temp_network` (`id`)
		ON DELETE CASCADE ON UPDATE CASCADE;')->execute();
        }
        if (!$temp_network_mac_ports) {
            $query = \DB::query('ALTER TABLE `temp_network_mac_ports` ADD CONSTRAINT `temp_network_mac_ports_ibfk_1`
		FOREIGN KEY (`tempnetID`) REFERENCES `device_temp_network` (`id`)
		ON DELETE CASCADE ON UPDATE CASCADE;')->execute();
        }
        if (!$temp_network_vlans) {
            $query = \DB::query('ALTER TABLE `temp_network_vlans` ADD CONSTRAINT `temp_network_vlans_ibfk_3`
		FOREIGN KEY (`tempnetID`) REFERENCES `device_temp_network` (`id`)
		ON DELETE CASCADE ON UPDATE CASCADE;')->execute();
        }
        //wiki
        if (!$wiki) {
            $query = \DB::query('ALTER TABLE `wiki`
				ADD CONSTRAINT `wiki_ibfk_1` FOREIGN KEY (`catID`) REFERENCES `wiki_categories` (`id`)
				ON DELETE CASCADE ON UPDATE CASCADE')->execute();
        }
        //virtual private server
        if (!$vps) {
            $query = \DB::query('ALTER TABLE `vps`
					ADD CONSTRAINT `vps_ibfk_1` FOREIGN KEY (`masterID`) REFERENCES `device` (`id`)
					ON DELETE CASCADE ON UPDATE CASCADE')->execute();
        }
        /*
                  //ips of vps
                  if (!$vps_ip_ports) {
                  $query = \DB::query('ALTER TABLE `vps_ip_ports`
                  ADD CONSTRAINT `vps_ip_ibfk_1` FOREIGN KEY (`vpsID`) REFERENCES `vps` (`id`)
                  ON DELETE CASCADE ON UPDATE CASCADE')->execute();
                  }
        */
    }
 public function up()
 {
     \DBUtil::create_table('categories', ['id' => ['constraint' => 11, 'type' => 'int', 'auto_increment' => true, 'unsigned' => true], 'left_id' => ['constraint' => 11, 'type' => 'int'], 'right_id' => ['constraint' => 11, 'type' => 'int'], 'image_id' => ['constraint' => 11, 'type' => 'int', 'null' => true], 'name' => ['constraint' => 255, 'type' => 'varchar'], 'slug' => ['constraint' => 255, 'type' => 'varchar'], 'description' => ['type' => 'text', 'null' => true], 'status' => ['constraint' => 1, 'type' => 'tinyint', 'default' => 1], 'created_at' => ['constraint' => 11, 'type' => 'int', 'null' => true], 'updated_at' => ['constraint' => 11, 'type' => 'int', 'null' => true]], ['id']);
     \DBUtil::create_index('categories', 'left_id');
     \DBUtil::create_index('categories', 'right_id');
 }
 public function up()
 {
     \DBUtil::create_table('product_meta_options', array('id' => array('type' => 'int', 'constraint' => 11, 'unsigned' => true, 'auto_increment' => true), 'product_meta_id' => array('type' => 'int', 'constraint' => 11, 'unsigned' => true), 'value' => array('type' => 'text'), 'created_at' => array('type' => 'datetime'), 'updated_at' => array('type' => 'datetime')), array('id'));
     \DBUtil::create_index('product_meta_options', 'product_meta_id', 'product_meta_id');
 }
 public function up()
 {
     /*         * *********************************************************************************************
               ipm_subnet
              * ********************************************************************************************* */
     $ipm_subnet = \DBUtil::checkIfExist('ipm_subnet');
     if (!$ipm_subnet) {
         \DBUtil::create_table('ipm_subnet', array('id' => array('constraint' => 11, 'type' => 'int', 'auto_increment' => true), 'subnet' => array('constraint' => 250, 'type' => 'varchar'), 'alias' => array('constraint' => 250, 'type' => 'varchar'), 'size' => array('constraint' => 11, 'type' => 'int'), 'mask' => array('constraint' => 50, 'type' => 'varchar'), 'description' => array('type' => 'text', 'null' => true), 'vlan' => array('constraint' => 11, 'type' => 'int', 'null' => true), 'type' => array('constraint' => 11, 'type' => 'int', 'null' => true), 'parent' => array('constraint' => 11, 'type' => 'int'), 'meta_update_user' => array('constraint' => 11, 'type' => 'int'), 'range_from' => array('type' => 'double'), 'range_to' => array('type' => 'double')), array('id'), true, 'InnoDB', 'utf8_unicode_ci');
     }
     /*         * *********************************************************************************************
               ipm_node
              * ********************************************************************************************* */
     $ipm_node = \DBUtil::checkIfExist('ipm_node');
     if (!$ipm_node) {
         \DBUtil::create_table('ipm_node', array('id' => array('constraint' => 11, 'type' => 'int', 'auto_increment' => true), 'name' => array('constraint' => 250, 'type' => 'varchar'), 'parent' => array('constraint' => 11, 'type' => 'int'), 'meta_update_user' => array('constraint' => 11, 'type' => 'int')), array('id'), true, 'InnoDB', 'utf8_unicode_ci');
     }
     /*         * *********************************************************************************************
               ipm_location
              * ********************************************************************************************* */
     $ipm_location = \DBUtil::checkIfExist('ipm_location');
     if (!$ipm_location) {
         \DBUtil::create_table('ipm_location', array('id' => array('constraint' => 11, 'type' => 'int', 'auto_increment' => true), 'node' => array('constraint' => 11, 'type' => 'int'), 'type' => array('constraint' => 11, 'type' => 'int'), 'building' => array('constraint' => 11, 'type' => 'int'), 'floor' => array('constraint' => 11, 'type' => 'int'), 'room' => array('constraint' => 11, 'type' => 'int'), 'rack' => array('constraint' => 11, 'type' => 'int'), 'pos_from' => array('constraint' => 11, 'type' => 'int'), 'pos_to' => array('constraint' => 11, 'type' => 'int')), array('id'), true, 'InnoDB', 'utf8_unicode_ci');
         //create indexes for location
         \DBUtil::create_index('ipm_location', 'node');
         \DBUtil::create_index('ipm_location', 'building');
         \DBUtil::create_index('ipm_location', 'floor');
         \DBUtil::create_index('ipm_location', 'room');
         \DBUtil::create_index('ipm_location', 'rack');
     }
     /*         * *********************************************************************************************
               ipm_history
              * ********************************************************************************************* */
     $ipm_history = \DBUtil::checkIfExist('ipm_history');
     if (!$ipm_history) {
         \DBUtil::create_table('ipm_history', array('id' => array('constraint' => 11, 'type' => 'int', 'auto_increment' => true), 'ip_dotted' => array('constraint' => 16, 'type' => 'varchar'), 'ip_int' => array('type' => 'double'), 'time' => array('constraint' => 11, 'type' => 'int'), 'device' => array('constraint' => 11, 'type' => 'int'), 'devname' => array('constraint' => 220, 'type' => 'varchar', 'null' => true), 'user' => array('constraint' => 11, 'type' => 'int')), array('id'), true, 'InnoDB', 'utf8_unicode_ci');
         //create indexes for location
         \DBUtil::create_index('ipm_history', 'device');
         \DBUtil::create_index('ipm_history', 'ip_int');
     }
     //make subnets
     $this->updateIpv4();
     /*         * *********************************************************************************************
               monitor_source
              * *********************************************************************************************
               $monitor_source=\DBUtil::checkIfExist('monitor_source');
               if(!$monitor_source){
               \DBUtil::create_table('monitor_source',array(
               'id' => array('constraint' => 11, 'type' => 'int', 'auto_increment' => true),
               'typeID' => array('constraint' => 11, 'type' => 'int'),
               'user' => array('constraint' => 250, 'type' => 'varchar'),
               'pass' => array('constraint' => 250, 'type' => 'varchar'),
               'content' => array('type' => 'text','null'=>true),
               'meta_update_time' => array('constraint' => 11, 'type' => 'int','default'=>'0'),
               'meta_update_user' => array('constraint' => 11, 'type' => 'int','default'=>'0')
               ),
               array('id'), true, 'InnoDB', 'utf8_unicode_ci'
               );
     
               //create indexes for wiki
               \DBUtil::create_index('monitor_source', 'typeID');
               }
     
              */
 }