mirror of
https://github.com/friendica/friendica
synced 2025-04-24 00:30:11 +00:00
DBStructure enhancements (#5437)
* Adding DBStructure enhancements - Added DBStructure::rename() - Added DBStructure::existTable() - Added DBStructure::existColumn() (cherry picked from commit 4ae06ec) * Adding `pre_update_1279` method - Added DBStructure::rename() - Added DBStructure::existTable() - Added DBStructure::existColumn() (cherry picked from commit 8496d84) * code standards (cherry picked from commit 551d09b) * simplify to `empty` instead `is_null` (cherry picked from commit ce68835)
This commit is contained in:
parent
303aef34f0
commit
c5cbf565d9
5 changed files with 249 additions and 1 deletions
68
tests/src/Database/DBStructureTest.php
Normal file
68
tests/src/Database/DBStructureTest.php
Normal file
|
@ -0,0 +1,68 @@
|
|||
<?php
|
||||
|
||||
namespace Friendica\Test\Database;
|
||||
|
||||
use Friendica\BaseObject;
|
||||
use Friendica\Core\Config;
|
||||
use Friendica\Database\DBStructure;
|
||||
use Friendica\Test\DatabaseTest;
|
||||
|
||||
class DBStructureTest extends DatabaseTest
|
||||
{
|
||||
public function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
// Reusable App object
|
||||
$this->app = BaseObject::getApp();
|
||||
|
||||
// Default config
|
||||
Config::set('config', 'hostname', 'localhost');
|
||||
Config::set('system', 'throttle_limit_day', 100);
|
||||
Config::set('system', 'throttle_limit_week', 100);
|
||||
Config::set('system', 'throttle_limit_month', 100);
|
||||
Config::set('system', 'theme', 'system_theme');
|
||||
}
|
||||
|
||||
/**
|
||||
* @small
|
||||
*/
|
||||
public function testExists() {
|
||||
$this->assertTrue(DBStructure::existsTable('config'));
|
||||
|
||||
$this->assertFalse(DBStructure::existsTable('notatable'));
|
||||
|
||||
$this->assertTrue(DBStructure::existsColumn('config', ['k']));
|
||||
$this->assertFalse(DBStructure::existsColumn('config', ['nonsense']));
|
||||
$this->assertFalse(DBStructure::existsColumn('config', ['k', 'nonsense']));
|
||||
}
|
||||
|
||||
/**
|
||||
* @small
|
||||
*/
|
||||
public function testRename() {
|
||||
$fromColumn = 'k';
|
||||
$toColumn = 'key';
|
||||
$fromType = 'varbinary(255) not null';
|
||||
$toType = 'varbinary(255) not null comment \'Test To Type\'';
|
||||
|
||||
$this->assertTrue(DBStructure::rename('config', [ $fromColumn => [ $toColumn, $toType ]]));
|
||||
$this->assertTrue(DBStructure::existsColumn('config', [ $toColumn ]));
|
||||
$this->assertFalse(DBStructure::existsColumn('config', [ $fromColumn ]));
|
||||
|
||||
$this->assertTrue(DBStructure::rename('config', [ $toColumn => [ $fromColumn, $fromType ]]));
|
||||
$this->assertTrue(DBStructure::existsColumn('config', [ $fromColumn ]));
|
||||
$this->assertFalse(DBStructure::existsColumn('config', [ $toColumn ]));
|
||||
}
|
||||
|
||||
/**
|
||||
* @small
|
||||
*/
|
||||
public function testChangePrimaryKey() {
|
||||
$oldID = 'client_id';
|
||||
$newID = 'pw';
|
||||
|
||||
$this->assertTrue(DBStructure::rename('clients', [ $newID ], DBStructure::RENAME_PRIMARY_KEY));
|
||||
$this->assertTrue(DBStructure::rename('clients', [ $oldID ], DBStructure::RENAME_PRIMARY_KEY));
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue