/** * Upgrade the database when the database version stored is lower than the one in source * @todo Make more db-independent */ public function upgrade_db() { if (Options::get('db_upgrading')) { // quit with an error message. $this->display_currently_upgrading(); } // don't allow duplicate upgrades. Options::set('db_upgrading', true); // This database-specific code needs to be moved into the schema-specific functions list($schema, $remainder) = explode(':', Config::get('db_connection')->connection_string); switch ($schema) { case 'sqlite': $db_name = ''; break; case 'mysql': case 'pgsql': $pairs = $this->parse_dsn($remainder); $db_name = $pairs['dbname']; break; } Cache::purge(); // get the current db version $version = Options::get('db_version'); // do some pre-dbdelta ad-hoc hacky hack code $this->upgrade_db_pre($version); // run schema-specific upgrade scripts for before dbdelta DB::upgrade_pre($version); // Get the queries for this database and apply the changes to the structure $queries = $this->get_create_table_queries($schema, Config::get('db_connection')->prefix, $db_name); DB::dbdelta($queries); // Apply data changes to the database based on version, call the db-specific upgrades, too. $this->upgrade_db_post($version); // run schema-specific upgrade scripts for after dbdelta DB::upgrade_post($version); Version::save_dbversion(); Options::delete('db_upgrading'); }
/** * Upgrade the database when the database version stored is lower than the one in source * @todo Make more db-independent */ public function upgrade_db() { // This database-specific code needs to be moved into the schema-specific functions list($schema, $remainder) = explode(':', Config::get('db_connection')->connection_string); switch ($schema) { case 'sqlite': $db_name = ''; break; case 'mysql': list($host, $name) = explode(';', $remainder); list($discard, $db_name) = explode('=', $name); break; case 'pgsql': list($host, $name) = explode(' ', $remainder); list($discard, $db_name) = explode('=', $name); break; } // get the current db version $version = Options::get('db_version'); // do some pre-dbdelta ad-hoc hacky hack code $this->upgrade_db_pre($version); // run schema-specific upgrade scripts for before dbdelta DB::upgrade_pre($version); // Get the queries for this database and apply the changes to the structure $queries = $this->get_create_table_queries($schema, Config::get('db_connection')->prefix, $db_name); DB::dbdelta($queries); // Apply data changes to the database based on version, call the db-specific upgrades, too. $this->upgrade_db_post($version); // run schema-specific upgrade scripts for after dbdelta DB::upgrade_post($version); Version::save_dbversion(); }