Skip to content

Commit

Permalink
The primary keys haven't been autoincrement fields traditionally.
Browse files Browse the repository at this point in the history
And specifying autoincrements this way doesn't work either.
  • Loading branch information
yunosh committed Nov 25, 2016
1 parent ceee2fb commit 95bff4f
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 3 deletions.
6 changes: 3 additions & 3 deletions vilma/migration/1_vilma_base_tables.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public function up()
$tableList = $this->tables();

if (!in_array('vilma_domains', $tableList)) {
$t = $this->createTable('vilma_domains', array('autoincrementKey' => 'domain_id'));
$t = $this->createTable('vilma_domains', array('autoincrementKey' => false));
$t->column('domain_id', 'integer', array('null' => false));
$t->column('domain_name', 'string', array('limit' => 128, 'null' => false));
$t->column('domain_transport', 'string', array('limit' => 128, 'null' => false));
Expand All @@ -34,7 +34,7 @@ public function up()
}

if (!in_array('vilma_users', $tableList)) {
$t = $this->createTable('vilma_users', array('autoincrementKey' => 'user_id'));
$t = $this->createTable('vilma_users', array('autoincrementKey' => false));
$t->column('user_id', 'integer', array('null' => false));
$t->column('user_name', 'string', array('limit' => 255, 'null' => false));
$t->column('user_clear', 'string', array('limit' => 255, 'null' => false));
Expand All @@ -54,7 +54,7 @@ public function up()
}

if (!in_array('vilma_virtuals', $tableList)) {
$t = $this->createTable('vilma_virtuals', array('autoincrementKey' => 'virtual_id'));
$t = $this->createTable('vilma_virtuals', array('autoincrementKey' => false));
$t->column('virtual_id', 'integer', array('null' => false));
$t->column('virtual_email', 'string', array('limit' => 128, 'null' => false));
$t->column('virtual_destination', 'string', array('limit' => 128, 'null' => false));
Expand Down
49 changes: 49 additions & 0 deletions vilma/migration/3_vilma_upgrade_autoincrement.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?php
/**
* Adds autoincrement flags
*
* Copyright 2010-2016 Horde LLC (http://www.horde.org/)
*
* See the enclosed file LICENSE for license information (BSD). If you did not
* did not receive this file, see http://www.horde.org/licenses/bsd.
*
* @author Jan Schneider <jan@horde.org>
* @category Horde
* @license http://www.horde.org/licenses/gpl GPL
* @package Vilma
*/
class VilmaUpgradeAutoIncrement extends Horde_Db_Migration_Base
{
/**
* Upgrade.
*/
public function up()
{
$this->changeColumn('vilma_domains', 'domain_id', 'autoincrementKey');
$this->changeColumn('vilma_users', 'user_id', 'autoincrementKey');
$this->changeColumn('vilma_virtuals', 'virtual_id', 'autoincrementKey');
try {
$this->dropTable('vilma_domains_seq');
} catch (Horde_Db_Exception $e) {
}
try {
$this->dropTable('vilma_users_seq');
} catch (Horde_Db_Exception $e) {
}
try {
$this->dropTable('vilma_virtuals_seq');
} catch (Horde_Db_Exception $e) {
}
}

/**
* Downgrade
*/
public function down()
{
$this->changeColumn('vilma_domains', 'domain_id', 'integer', array('null' => false));
$this->changeColumn('vilma_users', 'user_id', 'integer', array('null' => false));
$this->changeColumn('vilma_virtuals', 'virtual_id', 'integer', array('null' => false));
}

}
2 changes: 2 additions & 0 deletions vilma/package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@
<dir name="migration">
<file name="1_vilma_base_tables.php" role="horde" />
<file name="2_vilma_drop_domainkey.php" role="horde" />
<file name="3_vilma_upgrade_autoincrement.php" role="horde" />
</dir> <!-- /migration -->
<dir name="templates">
<dir name="domains">
Expand Down Expand Up @@ -230,6 +231,7 @@
<install as="vilma/locale/lv/LC_MESSAGES/vilma.po" name="locale/lv/LC_MESSAGES/vilma.po" />
<install as="vilma/migration/1_vilma_base_tables.php" name="migration/1_vilma_base_tables.php" />
<install as="vilma/migration/2_vilma_drop_domainkey.php" name="migration/2_vilma_drop_domainkey.php" />
<install as="vilma/migration/3_vilma_upgrade_autoincrement.php" name="migration/3_vilma_upgrade_autoincrement.php" />
<install as="vilma/templates/.htaccess" name="templates/.htaccess" />
<install as="vilma/templates/domains/index.html" name="templates/domains/index.html" />
<install as="vilma/templates/users/index.html" name="templates/users/index.html" />
Expand Down

0 comments on commit 95bff4f

Please sign in to comment.