Author: david
Date: Wed May  2 16:40:38 2012
New Revision: 11591

Log:
Start work on a SQL based data migration tool

Added:
   trunk/lib/task/migrate/arUpgradeSqlTask.class.php   (contents, props changed)

Added: trunk/lib/task/migrate/arUpgradeSqlTask.class.php
==============================================================================
--- /dev/null   00:00:00 1970   (empty, because file is newly added)
+++ trunk/lib/task/migrate/arUpgradeSqlTask.class.php   Wed May  2 16:40:38 
2012        (r11591)
@@ -0,0 +1,104 @@
+<?php
+
+/*
+ * This file is part of Qubit Toolkit.
+ *
+ * Qubit Toolkit is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * Qubit Toolkit is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Qubit Toolkit.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+/**
+ * Migrate qubit data model via direct SQL calls
+ *
+ * @package    qubit
+ * @subpackage migration
+ * @version    svn: $Id$
+ * @author     David Juhasz <[email protected]>
+ */
+class arMigrateSqlTask extends sfBaseTask
+{
+  protected
+    $initialVersion,
+    $targetVersion;
+
+  /**
+   * @see sfBaseTask
+   */
+  protected function configure()
+  {
+    $this->namespace = 'tools';
+    $this->name = 'upgrade-sql';
+    $this->briefDescription = 'Migrate the database schema and existing data 
for compatibility with a newer version of Qubit.';
+    $this->detailedDescription = <<<EOF
+The [tools:migrate|INFO] task modifies the SQL data structure for 
compatibility with later versions of the application:
+
+  [./symfony tools:upgrade-sql|INFO]
+EOF;
+
+    $this->addArguments(array(
+      new sfCommandArgument('target', sfCommandArgument::OPTIONAL, 'Target 
version')
+    ));
+
+    $this->addOptions(array(
+      new sfCommandOption('application', null, 
sfCommandOption::PARAMETER_OPTIONAL, 'The application name', true),
+      new sfCommandOption('env', null, sfCommandOption::PARAMETER_REQUIRED, 
'The environment', 'cli'),
+      new sfCommandOption('connection', null, 
sfCommandOption::PARAMETER_REQUIRED, 'The connection name', 'propel'),
+      new sfCommandOption('no-confirmation', null, 
sfCommandOption::PARAMETER_OPTIONAL, 'Skip confirmation', null),
+    ));
+  }
+
+  /**
+   * @see sfBaseTask
+   */
+  protected function execute($arguments = array(), $options = array())
+  {
+    $this->getInitalVersion();
+
+    // Use old migration script for versions before 75
+    if (null == $this->initialVersion || 75 > $this->initialVersion)
+    {
+      $this->logSection('upgrade-sql', 'Please use the propel:migrate task for
+        upgrading from Qubit releases before Release 1.2.');
+
+      return 1;
+    }
+
+    // Confirm update
+    if (!$options['no-confirmation']
+      &&
+      !$this->askConfirmation(array(
+          'WARNING: This upgrade can not be undone.'.
+          "\n\n".
+          'Are you sure you want to proceed? (y/N)',
+        ), 'QUESTION_LARGE', false)
+    )
+    {
+      $this->logSection('upgrade-sql', 'Ugrade aborted!');
+
+      return 1;
+    }
+
+    // TODO Version 75 check
+    // TODO Dump database
+    // TODO Do upgrade
+  }
+
+  protected function getInitialVersion
+  {
+    $sql = 'SELECT value AS version
+      FROM setting JOIN setting_i18n ON setting.id = setting_i18n.id
+      WHERE name="version";';
+
+    $this->initialVersion = QubitPdo::fetchColumn($sql);
+  }
+}

-- 
You received this message because you are subscribed to the Google Groups 
"Qubit Toolkit Commits" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/qubit-commits?hl=en.

Reply via email to