mirror of
https://github.com/supabase/supabase.git
synced 2026-10-07 18:35:07 +03:00
* Only show new disk billing UI for AWS provider projects * Fix DiskSpaceBar autoscaling should be fixed at 90% * Change all MiB to MB and GiB to GB * Prettier
90 lines
2.9 KiB
TypeScript
90 lines
2.9 KiB
TypeScript
import { DISK_LIMITS, DISK_PRICING, DiskType, PLAN_DETAILS } from './DiskManagement.constants'
|
|
|
|
export const calculateDiskSizePrice = ({
|
|
planId,
|
|
oldSize,
|
|
oldStorageType,
|
|
newSize,
|
|
newStorageType,
|
|
}: {
|
|
planId: string
|
|
oldSize: number
|
|
oldStorageType: DiskType
|
|
newSize: number
|
|
newStorageType: DiskType
|
|
}) => {
|
|
const oldPricePerGB = DISK_PRICING[oldStorageType]?.storage ?? 0
|
|
const newPricePerGB = DISK_PRICING[newStorageType]?.storage ?? 0
|
|
const { includedDiskGB } = PLAN_DETAILS?.[planId as keyof typeof PLAN_DETAILS] ?? {}
|
|
|
|
const oldPrice = (Math.max(oldSize - includedDiskGB[oldStorageType], 0) * oldPricePerGB).toFixed(
|
|
2
|
|
)
|
|
const newPrice = (Math.max(newSize - includedDiskGB[newStorageType], 0) * newPricePerGB).toFixed(
|
|
2
|
|
)
|
|
|
|
return { oldPrice, newPrice }
|
|
}
|
|
|
|
export const calculateIOPSPrice = ({
|
|
oldStorageType,
|
|
oldProvisionedIOPS,
|
|
newStorageType,
|
|
newProvisionedIOPS,
|
|
}: {
|
|
oldStorageType: DiskType
|
|
oldProvisionedIOPS: number
|
|
newStorageType: DiskType
|
|
newProvisionedIOPS: number
|
|
}) => {
|
|
if (newStorageType === DiskType.GP3) {
|
|
const oldChargeableIOPS = Math.max(
|
|
0,
|
|
oldProvisionedIOPS - DISK_LIMITS[DiskType.GP3].includedIops
|
|
)
|
|
const newChargeableIOPS = Math.max(
|
|
0,
|
|
newProvisionedIOPS - DISK_LIMITS[DiskType.GP3].includedIops
|
|
)
|
|
const oldPrice = oldChargeableIOPS * DISK_PRICING[oldStorageType]?.iops ?? 0
|
|
const newPrice = newChargeableIOPS * DISK_PRICING[newStorageType]?.iops ?? 0
|
|
return { oldPrice: oldPrice.toFixed(2), newPrice: newPrice.toFixed(2) }
|
|
} else {
|
|
const oldPrice =
|
|
oldStorageType === 'gp3'
|
|
? (oldProvisionedIOPS - DISK_LIMITS[oldStorageType].includedIops) *
|
|
DISK_PRICING[oldStorageType].iops
|
|
: oldProvisionedIOPS * DISK_PRICING[oldStorageType]?.iops ?? 0
|
|
const newPrice = newProvisionedIOPS * DISK_PRICING[newStorageType]?.iops ?? 0
|
|
return { oldPrice: oldPrice.toFixed(2), newPrice: newPrice.toFixed(2) }
|
|
}
|
|
}
|
|
|
|
// This is only applicable for GP3 storage type, no need to consider IO2 at all
|
|
// Also assumes that disk size is > 400 GB (separate requirement to update throughput)
|
|
export const calculateThroughputPrice = ({
|
|
storageType,
|
|
newThroughput,
|
|
oldThroughput,
|
|
}: {
|
|
storageType: DiskType
|
|
newThroughput: number
|
|
oldThroughput: number
|
|
}) => {
|
|
if (storageType === DiskType.GP3 && newThroughput) {
|
|
const oldChargeableThroughput = Math.max(
|
|
0,
|
|
oldThroughput - DISK_LIMITS[DiskType.GP3].includedThroughput
|
|
)
|
|
const newChargeableThroughput = Math.max(
|
|
0,
|
|
newThroughput - DISK_LIMITS[DiskType.GP3].includedThroughput
|
|
)
|
|
const oldPrice = (oldChargeableThroughput * DISK_PRICING[DiskType.GP3].throughput).toFixed(2)
|
|
const newPrice = (newChargeableThroughput * DISK_PRICING[DiskType.GP3].throughput).toFixed(2)
|
|
return { oldPrice, newPrice }
|
|
}
|
|
return { oldPrice: '0.00', newPrice: '0.00' }
|
|
}
|