/** * Primary task entry point * * @param array $args The current supplied options. */ public function execute($args) { $output = "Started: " . date('Y-m-d g:ia T') . "\n\n"; $output .= "[db:setup]: \n"; //it doesnt exist, create it if (!$this->_adapter->table_exists(RUCKUSING_TS_SCHEMA_TBL_NAME)) { $output .= sprintf("\tCreating table: %s", RUCKUSING_TS_SCHEMA_TBL_NAME); $this->_adapter->create_schema_version_table(); $output .= "\n\tDone.\n"; } else { $output .= sprintf("\tNOTICE: table '%s' already exists. Nothing to do.", RUCKUSING_TS_SCHEMA_TBL_NAME); } $output .= "\n\nFinished: " . date('Y-m-d g:ia T') . "\n\n"; return $output; }
/** * 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); } } } }
/** * Create the schema * * @return boolean */ private function auto_create_schema_info_table() { try { $this->_return .= sprintf("\n\tCreating schema version table: %s", RUCKUSING_TS_SCHEMA_TBL_NAME . "\n\n"); $this->_adapter->create_schema_version_table(); return true; } catch (Exception $e) { throw new Ruckusing_Exception("\nError auto-creating 'schema_info' table: " . $e->getMessage() . "\n\n", Ruckusing_Exception::MIGRATION_FAILED); } }