<?php if (CM_Db_Db::existsTable('cm_model_location_city_ip') && !CM_Db_Db::existsTable('cm_model_location_ip')) { CM_Db_Db::exec('RENAME TABLE `cm_model_location_city_ip` TO `cm_model_location_ip`'); } if (CM_Db_Db::existsTable('cm_model_location_ip')) { if (CM_Db_Db::existsIndex('cm_model_location_ip', 'cityId')) { CM_Db_Db::exec('DROP INDEX `cityId` ON `cm_model_location_ip`'); } if (CM_Db_Db::existsColumn('cm_model_location_ip', 'cityId') && !CM_Db_Db::existsColumn('cm_model_location_ip', 'id')) { CM_Db_Db::exec('ALTER TABLE `cm_model_location_ip` CHANGE COLUMN `cityId` `id` int(10) unsigned NOT NULL '); } if (!CM_Db_Db::existsColumn('cm_model_location_ip', 'level')) { CM_Db_Db::exec('ALTER TABLE `cm_model_location_ip` ADD COLUMN `level` int(10) unsigned NOT NULL AFTER `id`'); } if (CM_Db_Db::existsColumn('cm_model_location_ip', 'level')) { CM_Db_Db::update('cm_model_location_ip', array('level' => CM_Model_Location::LEVEL_CITY), array('level' => 0)); } if (CM_Db_Db::existsTable('cm_model_location_country_ip')) { $result = CM_Db_Db::select('cm_model_location_country_ip', array('countryId', 'ipStart', 'ipEnd')); foreach ($result->fetchAll() as $row) { CM_Db_Db::insert('cm_model_location_ip', array('id' => $row['countryId'], 'level' => CM_Model_Location::LEVEL_COUNTRY, 'ipStart' => $row['ipStart'], 'ipEnd' => $row['ipEnd'])); } CM_Db_Db::exec('DROP TABLE `cm_model_location_country_ip`'); } }
<?php if (!CM_Db_Db::existsTable('`cm_tmp_location_coordinates`')) { CM_Db_Db::exec('CREATE TABLE IF NOT EXISTS `cm_tmp_location_coordinates` ( `level` tinyint(4) NOT NULL, `id` int(10) unsigned NOT NULL, `coordinates` point NOT NULL, PRIMARY KEY (`level`,`id`), SPATIAL KEY `coordinates_spatial` (`coordinates`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8;'); CM_Db_Db::exec('INSERT INTO `cm_tmp_location_coordinates` (`level`,`id`,`coordinates`) SELECT `level`, `id`, POINT(lat, lon) FROM `cm_tmp_location` WHERE `lat` IS NOT NULL AND `lon` IS NOT NULL'); }
<?php if (!CM_Db_Db::existsTable('cm_model_currency')) { CM_Db_Db::exec("CREATE TABLE `cm_model_currency` (\n `id` int(10) unsigned NOT NULL AUTO_INCREMENT,\n `code` varchar(3) NOT NULL DEFAULT '',\n `abbreviation` varchar(3) NOT NULL DEFAULT '',\n PRIMARY KEY (`id`),\n UNIQUE KEY `code` (`code`),\n UNIQUE KEY `string` (`abbreviation`)\n ) ENGINE=MyISAM DEFAULT CHARSET=utf8;"); } if (!CM_Db_Db::existsTable('cm_model_currency_country')) { CM_Db_Db::exec("CREATE TABLE `cm_model_currency_country` (\n `currencyId` int(10) NOT NULL,\n `countryId` int(10) NOT NULL,\n UNIQUE KEY `countryId` (`countryId`)\n ) ENGINE=MyISAM DEFAULT CHARSET=utf8;"); } if (!CM_Db_Db::existsColumn('cm_user', 'currencyId')) { CM_Db_Db::exec("ALTER TABLE `cm_user` ADD `currencyId` INT(10) UNSIGNED DEFAULT NULL"); }
<?php foreach (array('cm_locationZip' => 'cm_model_location_zip', 'cm_locationCity' => 'cm_model_location_city', 'cm_locationState' => 'cm_model_location_state', 'cm_locationCountry' => 'cm_model_location_country', 'cm_locationCityIp' => 'cm_model_location_city_ip', 'cm_locationCountryIp' => 'cm_model_location_country_ip') as $tableOld => $tableNew) { if (CM_Db_Db::existsTable($tableOld)) { CM_Db_Db::exec('RENAME TABLE `' . $tableOld . '` TO `' . $tableNew . '`'); } }
public function testReplaceTable() { $this->assertInstanceOf('CM_Db_Exception', $this->catchException(function () { CM_Db_Db::replaceTable('test', 'test_new'); })); CM_Db_Db::exec('CREATE TABLE `test_new` (`id` INT(10) UNSIGNED NOT NULL)'); CM_Db_Db::insert('test_new', ['id' => 123]); CM_Db_Db::replaceTable('test', 'test_new'); $this->assertSame([['id' => '123']], CM_Db_Db::select('test', '*')->fetchAll()); $this->assertSame(false, CM_Db_Db::existsTable('test_new')); }
<?php if (CM_Db_Db::existsTable('cm_language')) { CM_Db_Db::exec('RENAME TABLE cm_language TO cm_model_language'); } if (CM_Db_Db::existsTable('cm_languageKey')) { CM_Db_Db::exec('RENAME TABLE cm_languageKey TO cm_model_languagekey'); }
<?php if (!CM_Db_Db::existsTable('cm_streamchannel_thumbnail')) { CM_Db_Db::exec("CREATE TABLE `cm_streamchannel_thumbnail` (\n `id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,\n `channelId` INT(10) UNSIGNED NOT NULL,\n `createStamp` INT(10) UNSIGNED NOT NULL,\n PRIMARY KEY (`id`),\n KEY `channelId-createStamp` (`channelId`, `createStamp`)\n ) ENGINE=MyISAM DEFAULT CHARSET=utf8;"); } if (CM_Db_Db::existsColumn('cm_streamChannel_media', 'thumbnailCount')) { CM_Db_Db::exec("ALTER TABLE cm_streamChannel_media DROP thumbnailCount, DROP `data`"); } if (CM_Db_Db::existsColumn('cm_streamChannelArchive_media', 'thumbnailCount')) { CM_Db_Db::exec("ALTER TABLE cm_streamChannelArchive_media DROP thumbnailCount, DROP `data`"); }
<?php if (!CM_Db_Db::existsTable('cm_tmp_classType')) { CM_Db_Db::exec("\n CREATE TABLE `cm_tmp_classType` (\n `type` int(10) unsigned NOT NULL,\n `className` varchar(255) NOT NULL,\n PRIMARY KEY (`type`)\n ) ENGINE=MyISAM DEFAULT CHARSET=utf8;\n "); }
<?php if (!CM_Db_Db::existsTable('cm_requestClientCounter')) { CM_Db_Db::exec(' CREATE TABLE `cm_requestClientCounter` ( `counter` int(10) unsigned NOT NULL, PRIMARY KEY (`counter`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8; '); CM_Db_Db::insert('cm_requestClientCounter', array('counter' => 0)); } if (CM_Db_Db::existsTable('cm_requestClient')) { $highestEntry = (int) CM_Db_Db::select('cm_requestClient', 'id', null, array('id' => 'DESC'))->fetchColumn(); CM_Db_Db::update('cm_requestClientCounter', array('counter' => $highestEntry)); CM_Db_Db::exec('DROP TABLE IF EXISTS `cm_requestClient`;'); }
<?php if (!CM_Db_Db::existsTable('cm_cli_command_manager_process')) { CM_Db_Db::exec(' CREATE TABLE `cm_cli_command_manager_process` ( `commandName` varchar(100) NOT NULL, `hostId` int(10) unsigned NOT NULL, `processId` int(10) unsigned DEFAULT NULL, `timeoutStamp` int(10) unsigned NOT NULL, PRIMARY KEY (`commandName`), KEY `hostId` (`hostId`), KEY `timeoutStamp` (`timeoutStamp`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8'); }
<?php if (!CM_Db_Db::existsColumn('cm_languageKey', 'variables')) { CM_Db_Db::exec("ALTER TABLE `cm_languageKey` ADD `variables` text CHARACTER SET utf8 COLLATE utf8_bin DEFAULT NULL AFTER name"); } if (CM_Db_Db::existsTable('cm_languageKey_variable')) { $results = CM_Db_Db::select('cm_languageKey_variable', '*')->fetchAll(); $variableList = array(); foreach ($results as $result) { $variableList[$result['languageKeyId']][] = $result['name']; } foreach ($variableList as $languageKeyId => $variables) { CM_Db_Db::update('cm_languageKey', array('variables' => json_encode($variables)), array('id' => $languageKeyId)); } CM_Db_Db::exec('DROP TABLE `cm_languageKey_variable`'); }
<?php if (!CM_Db_Db::existsTable('cm_jobdistribution_delayedqueue')) { CM_Db_Db::exec(' CREATE TABLE `cm_jobdistribution_delayedqueue` ( `id` int(10) unsigned NOT NULL AUTO_INCREMENT, `className` varchar(255) NOT NULL, `params` text NOT NULL, `executeAt` int(10) unsigned NOT NULL, PRIMARY KEY (`id`), KEY `executeAt` (`executeAt`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8; '); } if (CM_Db_Db::existsColumn('cm_user_online', 'offlineStamp')) { CM_Db_Db::exec('ALTER TABLE `cm_user_online` DROP `offlineStamp`'); }
<?php if (CM_Db_Db::existsTable('cm_streamChannel_video')) { CM_Db_Db::exec('RENAME TABLE cm_streamChannel_video TO cm_streamChannel_media'); } if (CM_Db_Db::existsColumn('cm_streamChannel_media', 'width') && CM_Db_Db::existsColumn('cm_streamChannel_media', 'height')) { CM_Db_Db::exec('ALTER TABLE cm_streamChannel_media DROP COLUMN `width`, DROP COLUMN `height`'); } if (!CM_Db_Db::existsColumn('cm_streamChannel_media', 'data')) { CM_Db_Db::exec('ALTER TABLE cm_streamChannel_media ADD COLUMN `data` VARCHAR(255) NOT NULL DEFAULT \'\' '); } if (CM_Db_Db::existsTable('cm_streamChannelArchive_video')) { CM_Db_Db::exec('RENAME TABLE cm_streamChannelArchive_video TO cm_streamChannelArchive_media'); } if (CM_Db_Db::existsColumn('cm_streamChannelArchive_media', 'width') && CM_Db_Db::existsColumn('cm_streamChannelArchive_media', 'height')) { CM_Db_Db::exec('ALTER TABLE cm_streamChannelArchive_media DROP COLUMN `width`, DROP COLUMN `height`'); } if (!CM_Db_Db::existsColumn('cm_streamChannelArchive_media', 'data')) { CM_Db_Db::exec('ALTER TABLE cm_streamChannelArchive_media ADD COLUMN `data` VARCHAR(255) NOT NULL DEFAULT \'\' '); }
public function testExistsTable() { $this->assertSame(true, CM_Db_Db::existsTable('test')); $this->assertSame(false, CM_Db_Db::existsTable('foo')); }
<?php if (CM_Db_Db::existsTable('cm_smileySet')) { CM_Db_Db::exec('DROP TABLE `cm_smileySet`;'); } if (!CM_Db_Db::existsIndex('cm_smiley', 'code')) { CM_Db_Db::exec('ALTER TABLE `cm_smiley` ADD UNIQUE KEY (`code`);'); } if (CM_Db_Db::existsColumn('cm_smiley', 'setId')) { CM_Db_Db::exec('ALTER TABLE `cm_smiley` DROP `setId`'); } if (CM_Db_Db::existsTable('cm_smiley')) { CM_Db_Db::exec('RENAME TABLE `cm_smiley` TO `cm_emoticon`'); } if (!CM_Db_Db::existsColumn('cm_emoticon', 'codeAdditional')) { CM_Db_Db::exec('ALTER TABLE `cm_emoticon` ADD `codeAdditional` varchar(50) AFTER `code`'); }
<?php if (CM_Db_Db::existsTable('cm_emoticon')) { CM_Db_Db::exec("DROP TABLE cm_emoticon"); }