This commit also contains the sqlc.yaml file, the `make sqlc` command
and the script for generating sqlc code. This must be done in this
commit as the script only works if there are queries to generate from.
This takes over two more settings we have in the lnd repo. The first is
to cancel existing CI runs for the same PR if it is pushed again before
the previous run has completed.
The second is just for consistency, to make sure all shells are bash
shells.
This attempts to fix the following error that sometimes occurs on the
GitHub runners:
go: github.com/lightninglabs/lightning-terminal imports
github.com/lightningnetwork/lnd/kvdb imports
github.com/lightningnetwork/lnd/kvdb/etcd imports
go.etcd.io/etcd/server/v3/embed: mkdir /home/runner/go/pkg/mod/cache/download/go.etcd.io/etcd/server: permission denied
The suspicion is that the lint step that runs as root within docker
changes the permissions of some of the module cache directories.
So by simply changing the order of operations, this should be fixed.
Apparently the %d formatting directive implicitly uses `int` as its data
type, which on i386 systems is int32. So the value math.MaxInt64
overflows that value, which causes the compilation to fail.
We remove the last few calls to UpdateAccount from the
TestAccountService test. Previously, the UpdateAccount call was used in
this test to also _insert_ new accounts and to force the account ID to
be set to specific values. So here we need to instead call the store's
NewAccount method to insert a new account, then we get the AccountID
from the returned value and we need to then use this returned ID (which
is no longer forceable) in the remainder of the tests.
In our mission to replace UpdateAccount, we need
UpdatAccountBalanceAndExpiry to take a negative balance so that we can
use it to replace the behaviour of UpdateAccount as it stands today.
In this commit, we remove one call to the UpdateAccount store method and
replace it with a call to a new UpdateAccountBalanceAndExpiry method
which updates an accounts balance and/or expiry fields and finds the
account via the given ID. This method signature is more appropriate for
a SQL backend than the UpdateAccount method.
In preparation for when we have a SQL DB implementation, we want our
unit tests to run smoothly against all DB backends and have the same
results. To achieve this, we need to turn some errors into global error
variables that can be matched against instead.
In this commit, we do this for the unique constraint violation of the
account label.
In later commits, we will use this `storeAccount` helper quite often.
Instead of needing to remember to update the timestamp outside the call,
it make sense to instead update the timestamp within the function. Yes
this does mean that sometimes we make no overall changes but do update
the timestamp but this is a pretty standard pattern that a "last
updated" timestamp is updated at any point that we re-write a record
(even if it does not have a net change).
This commit adds two new test helpers, NewTestDB and NewTestDBFromPath
in a file that is only built when the test_db_postgres and
test_db_sqlite build flags are not set. When we add sql backends, we
will add helpers with the same names for each new backend. We will then
use the appropriate build flags to run our unit tests against all
backends.
We want to be able to pass different DB implementations to NewService.
In preparation for this, we make it implementation agnostic by letting
it take a `Store` instead of constructing one itself.
This this change, we also let LiT handle the closing of the accounts
Store instead of the accounts service
Update the accounts `Store` and `Service` interfaces take a context.
This is in preparation for when the backend DB of the accounts service
is a SQL store which will have methods that take a context.
We rename the `store.go` file to `store_kvdb.go` to indicate that this
file contains the kvdb implementation of the accounts DB. This is in
preparation for adding a sql-backed implementation later on.
We do this early on in the PR so that any changes that need to be made
during the review process can be easily addressed with fix-up commits
that edit the newly named file.