ysdsad
This commit is contained in:
@@ -178,6 +178,19 @@ final class SchemaManager
|
||||
$applied[] = 'cost_plan_columns';
|
||||
}
|
||||
}
|
||||
if (
|
||||
($this->tableExists($this->prefix . 'cost_plans') && (
|
||||
!$this->columnExists($this->prefix . 'cost_plans', 'daily_cost_amount') ||
|
||||
!$this->columnExists($this->prefix . 'cost_plans', 'daily_cost_currency')
|
||||
)) ||
|
||||
($this->tableExists($this->prefix . 'purchased_miners') && (
|
||||
!$this->columnExists($this->prefix . 'purchased_miners', 'daily_cost_amount') ||
|
||||
!$this->columnExists($this->prefix . 'purchased_miners', 'daily_cost_currency')
|
||||
))
|
||||
) {
|
||||
$this->upgradeServerDailyCostColumns();
|
||||
$applied[] = 'server_daily_cost_columns';
|
||||
}
|
||||
|
||||
$settingsColumns = $this->existingColumns($this->prefix . 'settings', ['preferred_currencies', 'report_currency', 'crypto_currency', 'display_timezone', 'fx_max_age_hours', 'module_theme_mode', 'module_theme_accent']);
|
||||
if (!in_array('preferred_currencies', $settingsColumns, true) || !in_array('report_currency', $settingsColumns, true) || !in_array('crypto_currency', $settingsColumns, true) || !in_array('display_timezone', $settingsColumns, true) || !in_array('fx_max_age_hours', $settingsColumns, true) || !in_array('module_theme_mode', $settingsColumns, true) || !in_array('module_theme_accent', $settingsColumns, true)) {
|
||||
@@ -665,6 +678,19 @@ final class SchemaManager
|
||||
}
|
||||
}
|
||||
|
||||
foreach ([$this->prefix . 'cost_plans', $this->prefix . 'purchased_miners'] as $serverTable) {
|
||||
if (
|
||||
in_array($serverTable, $presentTables, true) &&
|
||||
(
|
||||
!$this->columnExists($serverTable, 'daily_cost_amount') ||
|
||||
!$this->columnExists($serverTable, 'daily_cost_currency')
|
||||
)
|
||||
) {
|
||||
$upgrades[] = 'server_daily_cost_columns';
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if ($this->tableExists($this->prefix . 'settings')) {
|
||||
$requiredSettingsColumns = ['preferred_currencies', 'report_currency', 'crypto_currency', 'display_timezone', 'fx_max_age_hours', 'module_theme_mode', 'module_theme_accent'];
|
||||
$existingSettingsColumns = $this->existingColumns($this->prefix . 'settings', $requiredSettingsColumns);
|
||||
@@ -1252,6 +1278,8 @@ final class SchemaManager
|
||||
usd_reference_amount NUMERIC(20,8),
|
||||
reference_price_amount NUMERIC(20,8),
|
||||
reference_price_currency VARCHAR(10),
|
||||
daily_cost_amount NUMERIC(20,10),
|
||||
daily_cost_currency VARCHAR(10),
|
||||
auto_renew BOOLEAN NOT NULL DEFAULT FALSE,
|
||||
note TEXT,
|
||||
is_active BOOLEAN NOT NULL DEFAULT TRUE,
|
||||
@@ -1278,6 +1306,8 @@ final class SchemaManager
|
||||
usd_reference_amount DECIMAL(20,8) NULL,
|
||||
reference_price_amount DECIMAL(20,8) NULL,
|
||||
reference_price_currency VARCHAR(10) NULL,
|
||||
daily_cost_amount DECIMAL(20,10) NULL,
|
||||
daily_cost_currency VARCHAR(10) NULL,
|
||||
auto_renew TINYINT(1) NOT NULL DEFAULT 0,
|
||||
note TEXT,
|
||||
is_active TINYINT(1) NOT NULL DEFAULT 1,
|
||||
@@ -1451,6 +1481,40 @@ final class SchemaManager
|
||||
}
|
||||
}
|
||||
|
||||
private function upgradeServerDailyCostColumns(): void
|
||||
{
|
||||
foreach ([$this->prefix . 'cost_plans', $this->prefix . 'purchased_miners'] as $table) {
|
||||
if (!$this->tableExists($table)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$statements = $this->driver === 'pgsql'
|
||||
? [
|
||||
'ALTER TABLE ' . $table . ' ADD COLUMN IF NOT EXISTS daily_cost_amount NUMERIC(20,10)',
|
||||
'ALTER TABLE ' . $table . ' ADD COLUMN IF NOT EXISTS daily_cost_currency VARCHAR(10)',
|
||||
'UPDATE ' . $table . ' SET daily_cost_amount = ROUND((total_cost_amount / NULLIF(runtime_months * 30.4375, 0))::numeric, 10) WHERE daily_cost_amount IS NULL AND total_cost_amount IS NOT NULL AND runtime_months IS NOT NULL AND runtime_months > 0',
|
||||
'UPDATE ' . $table . ' SET daily_cost_currency = COALESCE(daily_cost_currency, currency) WHERE currency IS NOT NULL',
|
||||
]
|
||||
: [
|
||||
'ALTER TABLE `' . $table . '` ADD COLUMN daily_cost_amount DECIMAL(20,10) NULL',
|
||||
'ALTER TABLE `' . $table . '` ADD COLUMN daily_cost_currency VARCHAR(10) NULL',
|
||||
'UPDATE `' . $table . '` SET daily_cost_amount = ROUND(total_cost_amount / NULLIF(runtime_months * 30.4375, 0), 10) WHERE daily_cost_amount IS NULL AND total_cost_amount IS NOT NULL AND runtime_months IS NOT NULL AND runtime_months > 0',
|
||||
'UPDATE `' . $table . '` SET daily_cost_currency = COALESCE(daily_cost_currency, currency) WHERE currency IS NOT NULL',
|
||||
];
|
||||
|
||||
foreach ($statements as $statement) {
|
||||
try {
|
||||
$this->executeUpgradeStatements([$statement], 'Schema-Upgrade fuer Server-Tageskosten fehlgeschlagen.');
|
||||
} catch (\Throwable $exception) {
|
||||
if ($this->driver === 'mysql' && str_contains(strtolower($exception->getMessage()), 'duplicate column')) {
|
||||
continue;
|
||||
}
|
||||
throw $exception;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private function upgradeTargetOfferColumn(): void
|
||||
{
|
||||
$table = $this->prefix . 'targets';
|
||||
|
||||
Reference in New Issue
Block a user