Skip to content

Commit

Permalink
Merge pull request #35 from dhensby/pulls/db-index-update
Browse files Browse the repository at this point in the history
Update module to work with new stricter index definitions
  • Loading branch information
Damian Mooyman authored Oct 12, 2017
2 parents 8d25343 + c00a11c commit acaaf95
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 36 deletions.
32 changes: 18 additions & 14 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,30 +1,34 @@
# See https://github.com/silverstripe-labs/silverstripe-travis-support for setup details
language: php

sudo: false
dist: precise

language: php
sudo: false

php:
- 5.5
- 5.6
- 7.0
- 7.1

env:
- DB=SQLITE CORE_RELEASE=master PDO=1
- DB=SQLITE CORE_RELEASE=4 PDO=1

matrix:
fast_finish: true
include:
- php: 5.6
env: DB=SQLITE CORE_RELEASE=master PDO=0
allow_failures:
- php: 7.0
env: DB=SQLITE CORE_RELEASE=4 PDO=0

before_script:
- composer self-update || true
- git clone git://github.com/silverstripe-labs/silverstripe-travis-support.git ~/travis-support
- php ~/travis-support/travis_setup.php --source `pwd` --target ~/builds/ss
- cd ~/builds/ss
- composer install
# Init PHP
- printf "\n" | pecl install imagick
- phpenv rehash
- phpenv config-rm xdebug.ini
- echo 'memory_limit = 2048M' >> ~/.phpenv/versions/$(phpenv version-name)/etc/conf.d/travis.ini

# Install composer dependencies
- composer validate
- composer require symfony/config:^3.2 silverstripe/framework:4.0.x-dev silverstripe/cms:4.0.x-dev silverstripe/siteconfig:4.0.x-dev silverstripe/config:1.0.x-dev silverstripe/admin:1.0.x-dev silverstripe/assets:1.0.x-dev silverstripe/versioned:1.0.x-dev --no-update
- composer install --prefer-dist --no-interaction --no-progress --no-suggest --optimize-autoloader --verbose --profile

script:
- vendor/bin/phpunit framework/tests
- vendor/bin/phpunit vendor/silverstripe/framework/tests
28 changes: 7 additions & 21 deletions code/SQLite3SchemaManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

use SilverStripe\Control\Director;
use SilverStripe\Dev\Debug;
use SilverStripe\Dev\SapphireTest;
use SilverStripe\ORM\Connect\DBSchemaManager;
use Exception;

Expand Down Expand Up @@ -210,7 +209,7 @@ public function checkAndRepairTable($tableName = null)
{
$ok = true;

if (!SapphireTest::using_temp_db() && !self::$checked_and_repaired) {
if (!self::$checked_and_repaired) {
$this->alterationMessage("Checking database integrity", "repaired");

// Check for any tables with failed integrity
Expand Down Expand Up @@ -370,10 +369,9 @@ public function fieldList($table)
*/
public function createIndex($tableName, $indexName, $indexSpec)
{
$parsedSpec = $this->parseIndexSpec($indexName, $indexSpec);
$sqliteName = $this->buildSQLiteIndexName($tableName, $indexName);
$columns = $parsedSpec['value'];
$unique = ($parsedSpec['type'] == 'unique') ? 'UNIQUE' : '';
$columns = $this->implodeColumnList($indexSpec['columns']);
$unique = ($indexSpec['type'] == 'unique') ? 'UNIQUE' : '';
$this->query("CREATE $unique INDEX IF NOT EXISTS \"$sqliteName\" ON \"$tableName\" ($columns)");
}

Expand Down Expand Up @@ -402,18 +400,6 @@ protected function buildSQLiteIndexName($tableName, $indexName)
return "{$tableName}_{$indexName}";
}

protected function parseIndexSpec($name, $spec)
{
$spec = parent::parseIndexSpec($name, $spec);

// Only allow index / unique index types
if (!in_array($spec['type'], array('index', 'unique'))) {
$spec['type'] = 'index';
}

return $spec;
}

public function indexKey($table, $index, $spec)
{
return $this->buildSQLiteIndexName($table, $index);
Expand All @@ -437,11 +423,11 @@ public function indexList($table)
}

// Safely encode this spec
$indexList[$indexName] = $this->parseIndexSpec($indexName, array(
$indexList[$indexName] = array(
'name' => $indexName,
'value' => $this->implodeColumnList($list),
'type' => $indexType
));
'columns' => $list,
'type' => $indexType,
);
}

return $indexList;
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"silverstripe/vendor-plugin": "^1.0"
},
"require-dev": {
"phpunit/phpunit": "~4.8"
"phpunit/phpunit": "^5.7"
},
"extra": {
"branch-alias": {
Expand Down
16 changes: 16 additions & 0 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<phpunit bootstrap="vendor/silverstripe/cms/tests/bootstrap.php" colors="true">

<testsuite name="Default">
<directory>tests</directory>
</testsuite>

<filter>
<whitelist addUncoveredFilesFromWhitelist="true">
<directory suffix=".php">.</directory>
<exclude>
<directory suffix=".php">tests/</directory>
</exclude>
</whitelist>
</filter>

</phpunit>

0 comments on commit acaaf95

Please sign in to comment.