15
15
namespace PKP \migration \upgrade \v3_5_0 ;
16
16
17
17
use DateInterval ;
18
+ use Illuminate \Database \PostgresConnection ;
18
19
use Illuminate \Database \Schema \Blueprint ;
19
20
use Illuminate \Support \Facades \Cache ;
20
21
use Illuminate \Support \Facades \DB ;
@@ -36,6 +37,7 @@ public function up(): void
36
37
/**
37
38
* Update/add locale arrays
38
39
*/
40
+ $ isPostgres = DB ::connection () instanceof PostgresConnection;
39
41
40
42
$ insert = function (object $ localeId , string $ settingName , string $ settingValue ): void {
41
43
DB ::table ($ this ->getContextSettingsTable ())->insert (
@@ -102,10 +104,15 @@ public function up(): void
102
104
});
103
105
104
106
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
+ });
109
116
}
110
117
}
111
118
0 commit comments