refactor: simplify pricing tables to USD-only

- Remove KRW pricing calculations from all pricing tables
- Simplify pricing table to store only wholesale USD prices
- Simplify anvil_pricing to store only retail USD prices
- Remove KRW environment variables (KRW_EXCHANGE_RATE, KRW_MARGIN_RATE)
- Remove KRW functions from constants.ts
- Update GPU/G8/VPU pricing repositories to match
- Add Anvil tables and repositories for branded product support

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
kappa
2026-01-25 21:16:25 +09:00
parent a2133ae5c9
commit 9f3d3a245a
21 changed files with 1952 additions and 197 deletions

View File

@@ -4,9 +4,9 @@
*/
import { BaseRepository } from './base';
import { G8Pricing, G8PricingInput, RepositoryError, ErrorCodes, Env } from '../types';
import { G8Pricing, G8PricingInput, RepositoryError, ErrorCodes } from '../types';
import { createLogger } from '../utils/logger';
import { calculateKRWHourly, calculateKRWMonthly } from '../constants';
import { calculateRetailHourly, calculateRetailMonthly } from '../constants';
export class G8PricingRepository extends BaseRepository<G8Pricing> {
protected tableName = 'g8_pricing';
@@ -16,13 +16,13 @@ export class G8PricingRepository extends BaseRepository<G8Pricing> {
'region_id',
'hourly_price',
'monthly_price',
'hourly_price_krw',
'monthly_price_krw',
'hourly_price_retail',
'monthly_price_retail',
'currency',
'available',
];
constructor(db: D1Database, private env?: Env) {
constructor(db: D1Database) {
super(db);
}
@@ -85,20 +85,21 @@ export class G8PricingRepository extends BaseRepository<G8Pricing> {
try {
const statements = pricingData.map((pricing) => {
const hourlyKrw = calculateKRWHourly(pricing.hourly_price, this.env);
const monthlyKrw = calculateKRWMonthly(pricing.monthly_price, this.env);
const hourlyRetail = calculateRetailHourly(pricing.hourly_price);
const monthlyRetail = calculateRetailMonthly(pricing.monthly_price);
return this.db.prepare(
`INSERT INTO g8_pricing (
g8_instance_id, region_id, hourly_price, monthly_price,
hourly_price_krw, monthly_price_krw, currency, available
hourly_price_retail, monthly_price_retail,
currency, available
) VALUES (?, ?, ?, ?, ?, ?, ?, ?)
ON CONFLICT(g8_instance_id, region_id)
DO UPDATE SET
hourly_price = excluded.hourly_price,
monthly_price = excluded.monthly_price,
hourly_price_krw = excluded.hourly_price_krw,
monthly_price_krw = excluded.monthly_price_krw,
hourly_price_retail = excluded.hourly_price_retail,
monthly_price_retail = excluded.monthly_price_retail,
currency = excluded.currency,
available = excluded.available,
updated_at = datetime('now')`
@@ -107,21 +108,21 @@ export class G8PricingRepository extends BaseRepository<G8Pricing> {
pricing.region_id,
pricing.hourly_price,
pricing.monthly_price,
hourlyKrw,
monthlyKrw,
hourlyRetail,
monthlyRetail,
pricing.currency,
pricing.available
);
});
const results = await this.db.batch(statements);
const successCount = results.filter((r) => r.success).length;
const results = await this.executeBatch(statements);
this.logger.info('upsertMany completed', {
total: pricingData.length,
success: successCount,
});
const successCount = results.reduce(
(sum, result) => sum + (result.meta.changes ?? 0),
0
);
this.logger.info('Upserted G8 pricing records', { count: successCount });
return successCount;
} catch (error) {
this.logger.error('upsertMany failed', {