[DATABASE] Re-introduce PostgreSQL support

This commit is contained in:
Alexei Sorokin
2019-09-11 14:14:40 +03:00
parent 644b417f6c
commit ee7f0a2016
22 changed files with 606 additions and 410 deletions

View File

@@ -605,14 +605,26 @@ function fixupFileThumbnailUrlhash()
{
printfnq("Setting urlhash for File_thumbnail entries: ");
switch (common_config('db', 'type')) {
case 'pgsql':
$url_sha256 = 'encode(sha256(CAST("url" AS bytea)), \'hex\')';
break;
case 'mysql':
$url_sha256 = 'sha2(`url`, 256)';
break;
default:
throw new Exception('Unknown DB type selected.');
}
$thumb = new File_thumbnail();
$thumb->query(sprintf(
'UPDATE %1$s ' .
'SET urlhash = sha2(url, 256) ' .
'SET urlhash = %2$s ' .
'WHERE url IS NOT NULL ' . // find all entries with a url value
"AND url <> '' " . // precaution against non-null empty strings
'AND urlhash IS NULL', // but don't touch those we've already calculated
$thumb->escapedTableName()
$thumb->escapedTableName(),
$url_sha256
));
printfnq("DONE.\n");