-
Notifications
You must be signed in to change notification settings - Fork 68
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
FolderMigrationHelper throws DatabaseException when using PostgreSQL #443
Comments
@TBurleigh Thanks! I've created a custom class and overrode it with Injector: CustomFolderMigrationHelper.php: <?php
use SilverStripe\Core\Convert;
use SilverStripe\Assets\Folder;
use SilverStripe\ORM\DataObject;
use SilverStripe\Versioned\Versioned;
use SilverStripe\Core\Injector\Injector;
use SilverStripe\Assets\Dev\Tasks\FolderMigrationHelper;
use SilverStripe\ORM\DataQuery;
class CustomFolderMigrationHelper extends FolderMigrationHelper
{
/**
* Get list of File dataobjects to import
*
* @return DataList
*/
protected function getQuery()
{
$versionedExtension = Injector::inst()->get(Versioned::class);
$schema = DataObject::getSchema();
$baseDataClass = $schema->baseDataClass(Folder::class);
$baseDataTable = $schema->tableName($baseDataClass);
$liveDataTable = $versionedExtension->stageTable($baseDataTable, Versioned::LIVE);
$query = Folder::get()->leftJoin(
$liveDataTable,
sprintf('"Live"."ID" = %s."ID"', Convert::symbol2sql($baseDataTable)),
'Live'
)->alterDataQuery(static function (DataQuery $q) {
$q->selectField('"Filename"'); // used later for logging processed folders
$q->selectField('"Live"."ID"', 'LiveID'); // needed for having clause to work
$q->where(['"Live"."ID" IS NULL']); // filters all folders without a record in the live table
});
return $query;
}
} injector.yaml: SilverStripe\Core\Injector\Injector:
SilverStripe\Assets\Dev\Tasks\FolderMigrationHelper:
class: CustomFolderMigrationHelper and it works in our project. |
HAVING actually has performance drawbacks as it does not use the index and is applied after the GROUP BY. I guess there could be cases where it changes the result. I just cannot think of how you would require it for that, because you could always do a sub query which I believe is simpler to think of. |
So you could delete this line: $q->selectField('"Live"."ID"', 'LiveID'); // needed for having clause to work |
@TBurleigh would you be happy to open a PR fixing this? |
I'm migrating a SS 3.7 site which is using silverstripe/postgresql to SS 4.7.2.
A DatabaseException is thrown when I run /dev/tasks/MigrateFileTask
PostgreSQL doesn't allow HAVING clauses to reference columns from the SELECT part of the query
A work around is to change FolderMigrationHelper.php#L157
From
$q->having(['"LiveID" IS NULL']); // filters all folders without a record in the live table
To
$q->where(['"Live"."ID" IS NULL']);
The text was updated successfully, but these errors were encountered: