public function getMigrationQueries(Updater $updater) { $dbSettings = new Db\Settings(); $engine = $dbSettings->getEngine(); $table = Common::prefixTable('site_setting'); $sqlarray = array("DROP TABLE IF EXISTS `{$table}`" => false, "CREATE TABLE `{$table}` (\n idsite INTEGER(10) UNSIGNED NOT NULL AUTO_INCREMENT,\n `setting_name` VARCHAR(255) NOT NULL,\n `setting_value` LONGTEXT NOT NULL,\n PRIMARY KEY(idsite, setting_name)\n ) ENGINE={$engine} DEFAULT CHARSET=utf8" => 1050); return $sqlarray; }
/** * @return string */ private static function addCreateSequenceTableQuery($sql) { $dbSettings = new Db\Settings(); $engine = $dbSettings->getEngine(); $table = self::getSequenceTableName(); $query = "CREATE TABLE `{$table}` (\n `name` VARCHAR(120) NOT NULL,\n `value` BIGINT(20) UNSIGNED NOT NULL,\n PRIMARY KEY(`name`)\n ) ENGINE={$engine} DEFAULT CHARSET=utf8"; $sql[$query] = 1050; return $sql; }
/** * Return SQL to be executed in this update. * * SQL queries should be defined here, instead of in `doUpdate()`, since this method is used * in the `core:update` command when displaying the queries an update will run. If you execute * queries directly in `doUpdate()`, they won't be displayed to the user. * * @param Updater $updater * @return array ``` * array( * 'ALTER .... ' => '1234', // if the query fails, it will be ignored if the error code is 1234 * 'ALTER .... ' => false, // if an error occurs, the update will stop and fail * // and user will have to manually run the query * ) * ``` */ public function getMigrationQueries(Updater $updater) { $tableOld = Common::prefixTable('usage_measurement_events'); $tableNew = Common::prefixTable('usage_measurement_profiles'); $dbSettings = new Settings(); $engine = $dbSettings->getEngine(); $newTableSql = sprintf("CREATE TABLE IF NOT EXISTS `%s` (\n `creation_date` datetime NOT NULL ,\n `category` VARCHAR(200) NOT NULL ,\n `name` VARCHAR(200) NOT NULL ,\n `action` VARCHAR(200) NOT NULL,\n `count` INT UNSIGNED NOT NULL DEFAULT 0 ,\n `wall_time` BIGINT UNSIGNED NOT NULL DEFAULT 0 ,\n PRIMARY KEY(`category`, `name`, `action`)) ENGINE=%s DEFAULT CHARSET=utf8", $tableNew, $engine); $sqls = array("DROP TABLE IF EXISTS " . $tableOld => false, $newTableSql => false); return $sqls; }
/** * Constructor. * @param Db\Settings $dbSettings * @param string $table Prefixed table name * @param string|string[] $columnNames array(columnName => columnValue) * @param string|string[] $primaryKey one or multiple columns that define the primary key */ public function __construct(Db\Settings $dbSettings, $table, $columnNames, $primaryKey) { $columns = array(); foreach ($columnNames as $column => $type) { $columns[] = sprintf('`%s` %s', $column, $type); } if (!empty($primaryKey)) { $columns[] = sprintf('PRIMARY KEY ( `%s` )', implode('`, `', $primaryKey)); } $sql = sprintf('CREATE TABLE `%s` (%s) ENGINE=%s DEFAULT CHARSET=utf8', $table, implode(', ', $columns), $dbSettings->getEngine()); parent::__construct($sql, static::ERROR_CODE_TABLE_EXISTS); }