storj/satellite/satellitedb/dbx/billing.dbx
Egon Elbre 1688e4965b satellite/satellitedb/dbx: split into multiple files
The current satellitedb.dbx has grown quite big over time.
Split the single file into multiple smaller ones.

Change-Id: I8d6ca851b834ac60820aff565906f04aab661875
2023-01-09 16:24:31 +02:00

238 lines
5.7 KiB
Plaintext

//--- satellite payments ---//
model stripe_customer (
key user_id
unique customer_id
field user_id blob
field customer_id text
field created_at timestamp ( autoinsert )
)
create stripe_customer ( )
read one (
select stripe_customer.customer_id
where stripe_customer.user_id = ?
)
read limitoffset (
select stripe_customer
where stripe_customer.created_at <= ?
orderby desc stripe_customer.created_at
)
model billing_balance (
key user_id
field user_id blob
field balance int64 ( updatable )
field last_updated timestamp ( autoinsert, autoupdate )
)
create billing_balance ( noreturn )
update billing_balance (
where billing_balance.user_id = ?
where billing_balance.balance = ?
)
read one (
select billing_balance.balance
where billing_balance.user_id = ?
)
model billing_transaction (
key id
field id serial64
field user_id blob
field amount int64
field currency text
field description text
field source text
field status text ( updatable )
field type text
field metadata json ( updatable )
field timestamp timestamp
field created_at timestamp ( autoinsert )
index ( fields timestamp)
)
create billing_transaction ( )
update billing_transaction (
where billing_transaction.id = ?
noreturn
)
read one (
select billing_transaction.metadata
where billing_transaction.id = ?
)
read all (
select billing_transaction
where billing_transaction.user_id = ?
orderby desc billing_transaction.timestamp
)
read first (
select billing_transaction
where billing_transaction.source = ?
where billing_transaction.type = ?
orderby ( desc billing_transaction.created_at)
)
model storjscan_wallet (
key user_id wallet_address
field user_id blob
field wallet_address blob
field created_at timestamp ( autoinsert )
index ( fields wallet_address )
)
create storjscan_wallet ( noreturn )
read one (
select storjscan_wallet.user_id
where storjscan_wallet.wallet_address = ?
)
read one (
select storjscan_wallet.wallet_address
where storjscan_wallet.user_id = ?
)
read all (
select storjscan_wallet
)
model coinpayments_transaction (
key id
field id text
field user_id blob
field address text
field amount_numeric int64
field received_numeric int64 ( updatable )
field status int ( updatable )
field key text
field timeout int
field created_at timestamp ( autoinsert )
)
create coinpayments_transaction ()
update coinpayments_transaction ( where coinpayments_transaction.id = ? )
read all (
select coinpayments_transaction
where coinpayments_transaction.user_id = ?
orderby desc coinpayments_transaction.created_at
)
model stripecoinpayments_apply_balance_intent (
key tx_id
field tx_id coinpayments_transaction.id cascade
field state int ( updatable )
field created_at timestamp ( autoinsert )
)
model stripecoinpayments_invoice_project_record (
key id
unique project_id period_start period_end
field id blob
field project_id blob
field storage float64
field egress int64
field objects int64 ( nullable )
field segments int64 ( nullable )
field period_start timestamp
field period_end timestamp
field state int ( updatable )
field created_at timestamp ( autoinsert )
)
create stripecoinpayments_invoice_project_record ()
update stripecoinpayments_invoice_project_record (
where stripecoinpayments_invoice_project_record.id = ?
)
read one (
select stripecoinpayments_invoice_project_record
where stripecoinpayments_invoice_project_record.project_id = ?
where stripecoinpayments_invoice_project_record.period_start = ?
where stripecoinpayments_invoice_project_record.period_end = ?
)
read limitoffset (
select stripecoinpayments_invoice_project_record
where stripecoinpayments_invoice_project_record.period_start = ?
where stripecoinpayments_invoice_project_record.period_end = ?
where stripecoinpayments_invoice_project_record.state = ?
)
model stripecoinpayments_tx_conversion_rate (
key tx_id
field tx_id text
field rate_numeric float64
field created_at timestamp ( autoinsert )
)
create stripecoinpayments_tx_conversion_rate ()
read one (
select stripecoinpayments_tx_conversion_rate
where stripecoinpayments_tx_conversion_rate.tx_id = ?
)
model storjscan_payment (
key block_hash log_index
index (fields block_number log_index)
field block_hash blob
field block_number int64
field transaction blob
field log_index int
field from_address blob
field to_address blob
field token_value int64
field usd_value int64
field status text
field timestamp timestamp
field created_at timestamp ( autoinsert )
)
create storjscan_payment (
noreturn
)
read all (
select storjscan_payment
orderby ( asc storjscan_payment.block_number, asc storjscan_payment.log_index )
)
read limitoffset (
select storjscan_payment
where storjscan_payment.to_address = ?
orderby ( desc storjscan_payment.block_number, desc storjscan_payment.log_index )
)
read first (
select storjscan_payment.block_number
where storjscan_payment.status = ?
orderby ( desc storjscan_payment.block_number, desc storjscan_payment.log_index )
)
delete storjscan_payment (
where storjscan_payment.status = ?
)