storj/satellite/satellitedb
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
..
dbx satellite/satellitedb: add burst_limit for project 2021-09-28 13:25:03 -04:00
satellitedbtest satellite/satellitedb: prepare to remove big.Float from db 2021-09-29 00:23:44 +00:00
testdata satellite/satellitedb: add burst_limit for project 2021-09-28 13:25:03 -04:00
apikeys.go private/lrucache: import from common 2021-08-16 10:04:32 +00:00
attribution.go satellite/accounting/tally: use objects iterator instead metaloop 2021-07-20 15:52:18 +00:00
audithistory.go satellite/satellitedb: remove referrence to audit information in 2021-08-13 21:11:28 +00:00
bucketsdb.go satellite/metabase: move package one level higher 2021-04-21 15:54:22 +03:00
coinpaymentstxs.go satellite/satellitedb: prepare to remove big.Float from db 2021-09-29 00:23:44 +00:00
compensation.go satellite/compensation: smaller txns for RecordPeriod 2021-03-02 20:14:25 +00:00
consoledb_test.go satellite/satellitedb/satellitedbtest: pass ctx as an argument 2020-01-20 16:35:42 +02:00
consoledb.go private/lrucache: import from common 2021-08-16 10:04:32 +00:00
containment.go satellite/audit: migrate to new segment_pending_audit table 2021-06-28 13:19:49 +02:00
coupons.go web/satellite: Allow users to see coupon in billing area 2021-08-14 16:09:54 -05:00
customers.go satellite/billing: make stripe invoice generation work with multiregion satellites 2021-05-06 11:51:03 -06:00
database.go private/lrucache: import from common 2021-08-16 10:04:32 +00:00
gracefulexit.go satellite/gracefulexit: stop using gracefulexit_transfer_queue 2021-09-14 11:52:34 +00:00
invoiceprojectrecords.go satellite/payments: delete credits and credits_spendings db tables 2020-07-30 12:19:57 +03:00
migrate_gen.go private/dbutil: use dbutil and tagsql from storj.io/private 2021-04-23 14:36:52 +03:00
migrate_test.go satellite/satellitedb: drop audit reputation score related columns from 2021-09-14 16:41:02 +00:00
migrate.go satellite/satellitedb: add burst_limit for project 2021-09-28 13:25:03 -04:00
migratez.go satellite/satellitedb: add burst_limit for project 2021-09-28 13:25:03 -04:00
nodeapiversion.go ci: fix lint errors 2021-05-17 13:37:31 +00:00
nodeselection.go satellite/{metabase,satellitedb}: deduplicate AS OF SYSTEM TIME code 2021-05-11 12:40:36 +03:00
orders.go satellite/satellitedb: removing usage of project_bandwidth_rollups table 2021-06-02 05:58:38 +00:00
overlaycache.go satellite/satellitedb: remove referrence to audit information in 2021-08-13 21:11:28 +00:00
payouts.go satellite/compensation: smaller txns for RecordPeriod 2021-03-02 20:14:25 +00:00
peeridentities.go all: fix dots 2020-07-16 14:58:28 +00:00
projectaccounting.go satellite/accounting/tally: use objects iterator instead metaloop 2021-07-20 15:52:18 +00:00
projectmembers_test.go web/satellite: project members sorting fixed (#3231) 2019-10-15 15:24:53 +03:00
projectmembers.go all: fix linter complaints 2020-10-13 15:59:01 +03:00
projects_test.go satellite/satellitedb/dbx: name the package dbx 2020-01-15 15:16:39 -07:00
projects.go satellite/metainfo: separate burst limit from rate limit config 2021-09-28 22:47:41 +00:00
regtokens.go all: fix dots 2020-07-16 14:58:28 +00:00
repairqueue.go satellite/repair: migrate to new repair_queue table 2021-06-30 17:12:24 +02:00
reputations.go satellite/satellitedb: improve Update query for reputation 2021-08-10 13:06:13 +00:00
resetpasstokens.go all: fix dots 2020-07-16 14:58:28 +00:00
revocation.go private/lrucache: import from common 2021-08-16 10:04:32 +00:00
storagenodeaccounting.go satellite/{metabase,satellitedb}: deduplicate AS OF SYSTEM TIME code 2021-05-11 12:40:36 +03:00
stripecoinpaymentsdb.go satellite/payments: delete credits and credits_spendings db tables 2020-07-30 12:19:57 +03:00
users_test.go satellite/satellitedb/dbx: name the package dbx 2020-01-15 15:16:39 -07:00
users.go satellite/console: Implement MFA backend 2021-07-26 16:37:05 +00:00