calculation
This commit is contained in:
@@ -259,6 +259,13 @@ final class SchemaManager
|
||||
$this->upgradePurchasedMinerReferenceColumns();
|
||||
$applied[] = 'purchased_miner_reference_columns';
|
||||
}
|
||||
if ($this->tableExists($this->prefix . 'purchased_miners') && (
|
||||
!$this->columnExists($this->prefix . 'purchased_miners', 'settled_value_amount') ||
|
||||
!$this->columnExists($this->prefix . 'purchased_miners', 'settled_value_currency')
|
||||
)) {
|
||||
$this->upgradePurchasedMinerSettlementColumns();
|
||||
$applied[] = 'purchased_miner_settlement_columns';
|
||||
}
|
||||
if ($this->tableExists($this->prefix . 'targets') && $this->tableExists($this->prefix . 'miner_offers')) {
|
||||
$this->ensureTargetOfferForeignKey();
|
||||
$applied[] = 'target_offer_foreign_key';
|
||||
@@ -401,6 +408,13 @@ final class SchemaManager
|
||||
$this->upgradePurchasedMinerReferenceColumns();
|
||||
$applied[] = 'purchased_miner_reference_columns';
|
||||
}
|
||||
if ($this->tableExists($this->prefix . 'purchased_miners') && (
|
||||
!$this->columnExists($this->prefix . 'purchased_miners', 'settled_value_amount') ||
|
||||
!$this->columnExists($this->prefix . 'purchased_miners', 'settled_value_currency')
|
||||
)) {
|
||||
$this->upgradePurchasedMinerSettlementColumns();
|
||||
$applied[] = 'purchased_miner_settlement_columns';
|
||||
}
|
||||
if ($this->tableExists($this->prefix . 'targets') && $this->tableExists($this->prefix . 'miner_offers')) {
|
||||
$this->ensureTargetOfferForeignKey();
|
||||
$applied[] = 'target_offer_foreign_key';
|
||||
@@ -754,6 +768,12 @@ final class SchemaManager
|
||||
if (!$this->tableExists($this->prefix . 'purchased_miners')) {
|
||||
$upgrades[] = 'purchased_miners_table';
|
||||
}
|
||||
if ($this->tableExists($this->prefix . 'purchased_miners') && (
|
||||
!$this->columnExists($this->prefix . 'purchased_miners', 'settled_value_amount') ||
|
||||
!$this->columnExists($this->prefix . 'purchased_miners', 'settled_value_currency')
|
||||
)) {
|
||||
$upgrades[] = 'purchased_miner_settlement_columns';
|
||||
}
|
||||
if ($this->tableExists($this->prefix . 'targets') && !$this->columnExists($this->prefix . 'targets', 'miner_offer_id')) {
|
||||
$upgrades[] = 'target_offer_column';
|
||||
}
|
||||
@@ -1502,6 +1522,33 @@ final class SchemaManager
|
||||
}
|
||||
}
|
||||
|
||||
private function upgradePurchasedMinerSettlementColumns(): void
|
||||
{
|
||||
$table = $this->prefix . 'purchased_miners';
|
||||
$statements = $this->driver === 'pgsql'
|
||||
? [
|
||||
'ALTER TABLE ' . $table . ' ADD COLUMN IF NOT EXISTS settled_value_amount NUMERIC(20,8)',
|
||||
'ALTER TABLE ' . $table . ' ADD COLUMN IF NOT EXISTS settled_value_currency VARCHAR(10)',
|
||||
"UPDATE " . $table . " SET settled_value_amount = CASE WHEN reference_price_amount IS NOT NULL AND NULLIF(BTRIM(reference_price_currency), '') IS NOT NULL AND UPPER(reference_price_currency) <> UPPER(currency) THEN reference_price_amount ELSE total_cost_amount * 0.07 END, settled_value_currency = CASE WHEN reference_price_amount IS NOT NULL AND NULLIF(BTRIM(reference_price_currency), '') IS NOT NULL AND UPPER(reference_price_currency) <> UPPER(currency) THEN reference_price_currency ELSE 'EUR' END WHERE UPPER(currency) IN ('ADA','ARB','BNB','BTC','DAI','DOGE','DOT','ETH','LINK','LTC','SOL','USDC','USDT','XRP') AND settled_value_amount IS NULL",
|
||||
]
|
||||
: [
|
||||
'ALTER TABLE `' . $table . '` ADD COLUMN settled_value_amount DECIMAL(20,8) NULL',
|
||||
'ALTER TABLE `' . $table . '` ADD COLUMN settled_value_currency VARCHAR(10) NULL',
|
||||
"UPDATE `" . $table . "` SET settled_value_amount = CASE WHEN reference_price_amount IS NOT NULL AND NULLIF(TRIM(reference_price_currency), '') IS NOT NULL AND UPPER(reference_price_currency) <> UPPER(currency) THEN reference_price_amount ELSE total_cost_amount * 0.07 END, settled_value_currency = CASE WHEN reference_price_amount IS NOT NULL AND NULLIF(TRIM(reference_price_currency), '') IS NOT NULL AND UPPER(reference_price_currency) <> UPPER(currency) THEN reference_price_currency ELSE 'EUR' END WHERE UPPER(currency) IN ('ADA','ARB','BNB','BTC','DAI','DOGE','DOT','ETH','LINK','LTC','SOL','USDC','USDT','XRP') AND settled_value_amount IS NULL",
|
||||
];
|
||||
|
||||
foreach ($statements as $statement) {
|
||||
try {
|
||||
$this->executeUpgradeStatements([$statement], 'Schema-Upgrade fuer die feste Krypto-Bewertung fehlgeschlagen.');
|
||||
} catch (\Throwable $exception) {
|
||||
if ($this->driver === 'mysql' && str_contains(strtolower($exception->getMessage()), 'duplicate column')) {
|
||||
continue;
|
||||
}
|
||||
throw $exception;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private function upgradeServerDailyCostColumns(): void
|
||||
{
|
||||
foreach ([$this->prefix . 'cost_plans', $this->prefix . 'purchased_miners'] as $table) {
|
||||
|
||||
Reference in New Issue
Block a user