storj/satellite/payments
paul cannon c053bdbd70 satellite/satellitedb: prepare to remove big.Float from db
Why: big.Float is not an ideal type for dealing with monetary amounts,
because no matter how high the precision, some non-integer decimal
values can not be represented exactly in base-2 floating point. Also,
storing gob-encoded big.Float values in the database makes it very hard
to use those values in meaningful queries, making it difficult to do
any sort of analysis on billing.

Now that we have amounts represented using monetary.Amount, we can
simply store them in the database using integers (as given by the
.BaseUnits() method on monetary.Amount).

We should move toward storing the currency along with any monetary
amount, wherever we are storing amounts, because satellites might want
to deal with currencies other than STORJ and USD. Even better, it
becomes much clearer what currency each monetary value is _supposed_ to
be in (I had to dig through code to find that out for our current
monetary columns).

Deployment
----------

Getting rid of the big.Float columns will take multiple deployment
steps. There does not seem to be any way to make the change in a way
that lets existing queries continue to work on CockroachDB (it could be
done with rules and triggers and a stored procedure that knows how to
gob-decode big.Float objects, but CockroachDB doesn't have rules _or_
triggers _or_ stored procedures). Instead, in this first step, we make
no changes to the database schema, but add code that knows how to deal
with the planned changes to the schema when they are made in a future
"step 2" deployment. All functions that deal with the
coinbase_transactions table have been taught to recognize the "undefined
column" error, and when it is seen, to call a separate "transition shim"
function to accomplish the task. Once all the services are running this
code, and the step 2 deployment makes breaking changes to the schema,
any services that are still running and connected to the database will
keep working correctly because of the fallback code included here. The
step 2 deployment can be made without these transition shims included,
because it will apply the database schema changes before any of its code
runs.

Step 1:

    No schema changes; just include code that recognizes the
    "undefined column" error when dealing with the
    coinbase_transactions or stripecoinpayments_tx_conversion_rates
    tables, and if found, assumes that the column changes from Step
    2 have already been made.

Step 2:

    In coinbase_transactions:

     * change the names of the 'amount' and 'received' columns to
       'amount_gob' and 'received_gob' respectively
     * add new 'amount_numeric' and 'received_numeric' columns with
       INT8 type.

    In stripecoinpayments_tx_conversion_rates:

     * change the name of the 'rate' column to 'rate_gob'
     * add new 'rate_numeric' column with NUMERIC(8, 8) type

    Code reading from either of these tables must query both the X_gob
    and X_numeric columns. If X_numeric is not null, its value should
    be used; otherwise, the gob-encoded big.Float in X_gob should be
    used. A chore might be included in this step that transitions values
    from X_gob to X_numeric a few rows at a time.

Step 3:

    Once all prod satellites have no values left in the _gob columns, we
    can drop those columns and add NOT NULL constraints to the _numeric
    columns.

Change-Id: Id6db304b404e6fde44f5a8c23cdaeeaaa2324f20
2021-09-29 00:23:44 +00:00
..
coinpayments satellite/payments: specialized type for monetary amounts 2021-09-28 23:27:44 +00:00
monetary satellite/payments: specialized type for monetary amounts 2021-09-28 23:27:44 +00:00
paymentsconfig web,satellite: Remove paywall-related functionality 2021-06-29 02:47:48 +02:00
stripecoinpayments satellite/satellitedb: prepare to remove big.Float from db 2021-09-29 00:23:44 +00:00
account.go web,satellite: Remove paywall-related functionality 2021-06-29 02:47:48 +02:00
balance.go satellite: account balance divided into Free Credits and Coins 2020-05-18 14:25:26 +00:00
charges.go satellite/console: add credit card charges to billing history 2020-01-03 17:34:59 +02:00
coupons_test.go satellite/payments: fix invoice generation to include the last day of 2021-08-31 16:25:18 +00:00
coupons.go satellite/payments: fix invoice generation to include the last day of 2021-08-31 16:25:18 +00:00
creditcards.go satellite/{payments,admin}: add deletion of user creditcards on account deletion 2020-08-27 10:18:19 +00:00
credits.go all: switch to storj.io/common/uuid 2020-03-31 19:16:41 +03:00
invoices.go satellite/admin: add user deletion 2020-07-14 11:37:00 +00:00
projectcharges.go all: switch to storj.io/common/uuid 2020-03-31 19:16:41 +03:00
tokens.go satellite/payments: specialized type for monetary amounts 2021-09-28 23:27:44 +00:00