Skip to content

Commit 0fdfc75

Browse files
committed
#9425 Fix default values on upgrade for PostgreSQL
1 parent 470ab04 commit 0fdfc75

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

classes/migration/upgrade/v3_5_0/I9425_SeparateUIAndSubmissionLocales.php

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
namespace PKP\migration\upgrade\v3_5_0;
1616

1717
use DateInterval;
18+
use Illuminate\Database\PostgresConnection;
1819
use Illuminate\Database\Schema\Blueprint;
1920
use Illuminate\Support\Facades\Cache;
2021
use Illuminate\Support\Facades\DB;
@@ -36,6 +37,7 @@ public function up(): void
3637
/**
3738
* Update/add locale arrays
3839
*/
40+
$isPostgres = DB::connection() instanceof PostgresConnection;
3941

4042
$insert = function (object $localeId, string $settingName, string $settingValue): void {
4143
DB::table($this->getContextSettingsTable())->insert(
@@ -102,10 +104,15 @@ public function up(): void
102104
});
103105

104106
foreach ($tableLocaleColumns as $tableName => $localeColumns) {
105-
$localeColumns->each(
106-
fn ($column) =>
107-
Schema::table($tableName, fn (Blueprint $table) => $table->string($column['name'], 28)->nullable($column['nullable'])->default($column['default'])->change())
108-
);
107+
$localeColumns->each(function ($column) use ($tableName, $isPostgres) {
108+
$default = match($isPostgres) {
109+
// PostgreSQL describes defaults in terms like: 'en'::character varying
110+
// If there is a '-delimited string part, fetch and use it.
111+
true => empty($column['default']) ? null : strtok($column['default'], "'"),
112+
false => $column['default'],
113+
};
114+
Schema::table($tableName, fn (Blueprint $table) => $table->string($column['name'], 28)->nullable($column['nullable'])->default($default)->change());
115+
});
109116
}
110117
}
111118

0 commit comments

Comments
 (0)