Add timezone. Cheap and backwards compatible.

This commit is contained in:
James Cole 2024-11-06 11:11:52 +01:00
parent d118c0d886
commit 899c72d068
No known key found for this signature in database
GPG Key ID: B49A324B7EAD6D80
2 changed files with 64 additions and 1 deletions

View File

@ -112,7 +112,7 @@ return [
],
'version' => 'develop/2024-11-04',
'api_version' => '2.1.0',
'db_version' => 24,
'db_version' => 25,
// generic settings
'maxUploadSize' => 1073741824, // 1 GB

View File

@ -0,0 +1,63 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\QueryException;
use Illuminate\Database\Schema\Blueprint;
return new class extends Migration {
private array $tables;
public function __construct()
{
$this->tables = [
'account_balances' => ['date'],
'available_budgets' => ['start_date', 'end_date'],
'bills' => ['date','end_date', 'extension_date'],
'budget_limits' => ['start_date', 'end_date'],
'currency_exchange_rates' => ['date'],
'invited_users' => ['expires'],
'limit_repetitions' => ['startdate', 'enddate'],
'piggy_bank_events' => ['date'],
'piggy_bank_repetitions' => ['startdate', 'targetdate'],
'piggy_banks' => ['startdate', 'targetdate'],
'recurrences' => ['first_date', 'repeat_until', 'latest_date'],
'tags' => ['date'],
'transaction_journals' => ['date'],
];
}
/**
* Run the migrations.
* TODO journal_meta, all date fields?
*
*/
public function up(): void
{
foreach ($this->tables as $table => $columns) {
foreach ($columns as $column) {
$newColumn = sprintf('%s_tz', $column);
if (Schema::hasColumn($table, $column) && !Schema::hasColumn($table, $newColumn)) {
try {
Schema::table(
$table,
static function (Blueprint $table) use ($column, $newColumn): void {
$table->string($newColumn, 50)->nullable()->after($column);
}
);
} catch (QueryException $e) {
app('log')->error(sprintf('Could not add column "%s" to table "%s" query: %s', $newColumn, $table, $e->getMessage()));
app('log')->error('If the column or index already exists (see error), this is not an problem. Otherwise, please open a GitHub discussion.');
}
}
}
}
}
/**
* Reverse the migrations.
*/
public function down(): void
{
//
}
};