Files
ubicloud/demo/init_db.sh
Burak Yucesoy b8c4e08439 Introduce billing records
This is the primary source of truth for billing. One very critical aspect of
billing records, that is not handled by this commit, is that ensuring freshness
of the information we keep. Billing records needs to duplicate some information
such as usage amount or billing rate id. However, these information can change;
for example when user scales up a VM from 2 cores to 4 cores. Since we are
duplicating these information, billing records needs to be updated as well when
the resource is updated. We cannot simply refer to the original information,
as we have to keep the record of the old information as well.

There are two scenarios where data staleness can occur;
- As we add new functionality, such as scale up/down, we might forget to add
necessary logic to update usage records.
- During manual operations, such as when customer opens a ticket for moving
resource to another region, operator might forget to update billing records.

Both are possible, but the former is less likely as we had chance to catch
such cases during code review. However, it is not failsafe.

Since billing is very critical, it is warranted to build a failsafe mechanism
to keep usage records fresh. However that comes with all sorts of challenges,
primarily due to each product requiring slightly different validation mechanism.
How we build the validations for VM would be different than egress billing,
which would be different that database product. I evaluated different options
such as foreign keys, triggers, check constraints, having sync in Progs,
alerting in case of discrepancy etc. None of them provide clear-cut solution.
Also our knowledge regarding how would we design our future products is
non-existent, so trying build a generalist solution is futile. Thus, I'm
leaving data freshess problem to be visited later on as we gather more info.

For VMs specifically, which is the only resource that we currently charge for,
all billing record related operations are done in Nexus instead of API, which
significantly reduces the risk of scenario #2.
2023-08-07 10:52:22 +03:00

7 lines
464 B
Bash
Executable File

psql -U postgres -c "CREATE ROLE clover PASSWORD '${POSTGRES_PASSWORD}' LOGIN"
psql -U postgres -c "CREATE ROLE clover_password PASSWORD '${POSTGRES_PASSWORD}' LOGIN"
psql -U postgres -c "GRANT CREATE ON SCHEMA public TO clover" "${POSTGRES_DB}"
psql -U postgres -c "GRANT CREATE ON SCHEMA public TO clover_password" "${POSTGRES_DB}"
psql -U postgres -c "CREATE EXTENSION citext" "${POSTGRES_DB}"
psql -U postgres -c "CREATE EXTENSION btree_gist" "${POSTGRES_DB}"