/** * Update the local schema to handle multiple records versus the prior architecture * of storing a single version. In addition take all existing migration files * and register them in our new table, as they have already been executed. */ public function update_schema_for_timestamps() { //only create the table if it doesnt already exist $this->_adapter->create_schema_version_table(); //insert all existing records into our new table $migrator_util = new Ruckusing_Util_Migrator($this->_adapter); $files = $migrator_util->get_migration_files($this->migrations_directories(), 'up'); foreach ($files as $file) { if ((int) $file['version'] >= PHP_INT_MAX) { //its new style like '20081010170207' so its not a candidate continue; } //query old table, if it less than or equal to our max version, then its a candidate for insertion $query_sql = sprintf("SELECT version FROM %s WHERE version >= %d", RUCKUSING_SCHEMA_TBL_NAME, $file['version']); $existing_version_old_style = $this->_adapter->select_one($query_sql); if (count($existing_version_old_style) > 0) { //make sure it doesnt exist in our new table, who knows how it got inserted? $new_vers_sql = sprintf("SELECT version FROM %s WHERE version = %d", $this->_adapter->get_schema_version_table_name(), $file['version']); $existing_version_new_style = $this->_adapter->select_one($new_vers_sql); if (empty($existing_version_new_style)) { // use sprintf & %d to force it to be stripped of any leading zeros, we *know* this represents an old version style // so we dont have to worry about PHP and integer overflow $insert_sql = sprintf("INSERT INTO %s (version) VALUES (%d)", $this->_adapter->get_schema_version_table_name(), $file['version']); $this->_adapter->query($insert_sql); } } } }
/** * Execute a query * * @param string $sql the query to run * * @return boolean */ public function query($sql) { return $this->_adapter->query($sql); }