/**
  * 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:version]: \n";
     if (!$this->_adapter->table_exists(RUCKUSING_TS_SCHEMA_TBL_NAME)) {
         //it doesnt exist, create it
         $output .= "\tSchema version table (" . RUCKUSING_TS_SCHEMA_TBL_NAME . ") does not exist. Do you need to run 'db:setup'?";
     } else {
         //it exists, read the version from it
         // We only want one row but we cannot assume that we are using MySQL and use a LIMIT statement
         // as it is not part of the SQL standard. Thus we have to select all rows and use PHP to return
         // the record we need
         $versions_nested = $this->_adapter->select_all(sprintf("SELECT version FROM %s", RUCKUSING_TS_SCHEMA_TBL_NAME));
         $versions = array();
         foreach ($versions_nested as $v) {
             $versions[] = $v['version'];
         }
         $num_versions = count($versions);
         if ($num_versions > 0) {
             sort($versions);
             //sorts lowest-to-highest (ascending)
             $version = (string) $versions[$num_versions - 1];
             $output .= sprintf("\tCurrent version: %s", $version);
         } else {
             $output .= sprintf("\tNo migrations have been executed.");
         }
     }
     $output .= "\n\nFinished: " . date('Y-m-d g:ia T') . "\n\n";
     return $output;
 }
Example #2
0
 /**
  * Primary task entry point
  *
  * @param array $args The current supplied options.
  */
 public function execute($args)
 {
     $this->_return .= "Started: " . date('Y-m-d g:ia T') . "\n\n";
     $this->_return .= "[db:schema]: \n";
     //write to disk
     $schema_file = $this->db_dir() . '/schema.txt';
     $schema = $this->_adapter->schema($schema_file);
     $this->_return .= "\tSchema written to: {$schema_file}\n\n";
     $this->_return .= "\n\nFinished: " . date('Y-m-d g:ia T') . "\n\n";
     return $this->_return;
 }
 /**
  * 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);
             }
         }
     }
 }
Example #5
0
 /**
  * @param array $dsn
  * @param $logger
  */
 public function __construct($dsn, $logger)
 {
     parent::__construct($dsn);
     $this->connect($dsn);
     $this->set_logger($logger);
     $this->_in_transaction = false;
 }
 /**
  * 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);
     }
 }
 /**
  * Query the database and return a list of migration versions that *have* been executed
  *
  * @return array
  */
 private function executed_migrations()
 {
     $query_sql = sprintf('SELECT version FROM %s', RUCKUSING_TS_SCHEMA_TBL_NAME);
     $versions = $this->_adapter->select_all($query_sql);
     $executed = array();
     foreach ($versions as $v) {
         $executed[] = $v['version'];
     }
     sort($executed);
     return $executed;
 }
 /**
  * Query the database and return a list of migration versions that *have* been executed
  *
  * @return array
  */
 private function executed_migrations()
 {
     $query_sql = sprintf('SELECT version FROM %s', $this->_adapter->get_schema_version_table_name());
     $versions = $this->_adapter->select_all($query_sql);
     $executed = array();
     foreach ($versions as $v) {
         $executed[] = $v['version'];
     }
     sort($executed);
     return $executed;
 }
Example #9
0
 /**
  * Creates an instance of Ruckusing_Adapter_PgSQL_Base
  *
  * @param array                 $dsn    The current dsn being used
  * @param Ruckusing_Util_Logger $logger the current logger
  *
  * @return Ruckusing_Adapter_PgSQL_Base
  */
 public function __construct($dsn, $logger)
 {
     parent::__construct($dsn);
     $this->connect($dsn);
     $this->set_logger($logger);
 }
 /**
  * sql version
  *
  * @return string
  */
 private function sql_type()
 {
     return $this->_adapter->type_to_sql($this->type, $this->_options);
 }
Example #11
0
 /**
  * Quote a string
  *
  * @param string $str the string to quote
  *
  * @return string
  */
 public function quote_string($str)
 {
     return $this->_adapter->quote_string($str);
 }