Introduce cdk-sql-common #890
No reviewers
Labels
No labels
DB & Storage
Deployment
Error Handling & Logging
Maintenance
Payment Backend
backport
backport v0.13.x
backport v0.14.x
backport v0.15.x
bindings
blocked
bug
cdk-sql
ci
cli
deps
documentation
duplicate
enhancement
good first issue
help wanted
invalid
keep-open
ldk-node-ui
migrations
mint
mutation-testing
needs rebase
needs review
new nut
nut change
question
ready
rust-version
rustfmt
stacked hold
stale
testing
wallet
weekly-report
wontfix
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
cashubtc/cdk!890
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "feature/sql-base"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Description
The primary purpose of this new crate is to have a common and shared codebase for all SQL storage systems. It would force us to write standard SQL using best practices for all databases.
This crate has been extracted from #878
Notes to the reviewers
Suggested CHANGELOG Updates
CHANGED
ADDED
REMOVED
FIXED
Checklist
just final-checkbefore committingNice work. I like that the sql is abstracted into a common place where we will not have to maintain two versions for sqlite and postgres. Though I have a question on this are we limited to sqlite feature set. The first one that comes to mint is row locks, to prevent race conditions in places like proof state updates we currently have the db locked in a transaction but in postgres we could use a row lock to only lock the specific proofs involved. Can we still do this?
The idea is to use the correct SQL, even if the driver does not support that. The example is SELECT FOR UPDATE , which is standard, but SQLite does not support it, because semantically it makes no sense, since TRANSACTION locks the database exclusively. So any changes are rewritten by the driver
Although RAW SQL is written, it is vaguely parsed to extract placeholders, because we use named arguments for readability but some drivers use position placeholders.
The bits that are missing that can be a follow-up are:
bind_vec@ -0,0 +1,44 @@use crate::database::DatabaseExecutor;If the names match, we should remove the prefix from the names. Otherwise, this will cause all migrations to be rerun because they were moved to a new subdirectory.
Alternatively, we could remove the path from all
pub static MIGRATIONS.@ -0,0 +25,4 @@tracing.workspace = trueserde.workspace = trueserde_json.workspace = truelightning-invoice.workspace = truethis is unused
@ -0,0 +25,4 @@tracing.workspace = trueserde.workspace = trueserde_json.workspace = truelightning-invoice.workspace = truegreat catch. I'll fix it.
@ -0,0 +25,4 @@tracing.workspace = trueserde.workspace = trueserde_json.workspace = truelightning-invoice.workspace = trueFixed in e1cc72ecff76d801e2299d548002e5a4a955d9c7
@ -0,0 +1,44 @@use crate::database::DatabaseExecutor;Isn't e1cc72ecff76d801e2299d548002e5a4a955d9c7 a better solution?
@ -0,0 +1,44 @@use crate::database::DatabaseExecutor;That should do the job. Thanks 👍 I had something similar in mind like using the
file_name()function on the path.@ -0,0 +27,4 @@/// Trait to manage resourcespub trait ResourceManager: Debug {/// The resource to be pooledtype Resource: Debug;Im not sure why we need that
still_validhere. It seems like we always create the resource in valid state true.The timeout should be moved to the configuration.
@ -0,0 +27,4 @@/// Trait to manage resourcespub trait ResourceManager: Debug {/// The resource to be pooledtype Resource: Debug;still_validis used to signal the resource manager if the current resource is stale and it should be dropped (and a be eventually replaced with a new one).This makes no sense for SQLite but it does for pgsql, to reconnect stale connections.
@ -0,0 +27,4 @@/// Trait to manage resourcespub trait ResourceManager: Debug {/// The resource to be pooledtype Resource: Debug;I acknowledge that the name is not very descriptive; a better name could be used. Any suggestions?
@ -0,0 +27,4 @@/// Trait to manage resourcespub trait ResourceManager: Debug {/// The resource to be pooledtype Resource: Debug;OK gotcha. That makes sense. I haven’t looked into the psql implementation yet.
Perhaps we should simply call it
staleand negate the drop condition?Do we need this as a parameter to the
new_resourcefunction?New resources might always be valid (or not stale)
@ -0,0 +27,4 @@/// Trait to manage resourcespub trait ResourceManager: Debug {/// The resource to be pooledtype Resource: Debug;I love it. I will rename it and document the behaviour, thanks for the feedback
@ -0,0 +27,4 @@/// Trait to manage resourcespub trait ResourceManager: Debug {/// The resource to be pooledtype Resource: Debug;is it better in cd066415c53ef2e0e9ac0c4eef3421bbeaa6c6b0 /cc @asmogo ?
Overall I think this looks good I am just getting a runtime error that needs to be addressed. I am getting the Error: Duplicate entry when i restart the mint. This happened when I did not have a mint db created one by starting the mint, then stopping the mint and attempting to restart.
@ -0,0 +1,44 @@use crate::database::DatabaseExecutor;Our code style says we should use match here https://github.com/cashubtc/cdk/blob/main/CODE_STYLE.md#if-let.
@ -0,0 +27,4 @@/// Trait to manage resourcespub trait ResourceManager: Debug {/// The resource to be pooledtype Resource: Debug;@ -0,0 +1,359 @@//! Stataments modJust add some logging instead of ignoring the error
using
path.file_name()in the builder:Not sure if this has further implications. Current master also uses the file_name function (but with
to_string_lossy).@ -0,0 +1,44 @@use crate::database::DatabaseExecutor;removing the base name and using the name variable as bind parameter solves the issue mentioned in https://github.com/cashubtc/cdk/pull/890#pullrequestreview-3058149066. This was introduced due to a previous change request.
Maybe we should consider removing the path from the name while creating the MIGRATIONS in build.rs.
The path (database engine) is still referenced by file location.
@ -0,0 +27,4 @@/// Trait to manage resourcespub trait ResourceManager: Debug {/// The resource to be pooledtype Resource: Debug;Yep. Thanks!
@ -0,0 +1,44 @@use crate::database::DatabaseExecutor;Is it better in fc7adba0?
ACK fc7adba067b8aa518690ec56704211ab6f86b220
@asmogo Anything outstanding in your view on this pr?
ACK. Didn’t test https://github.com/cashubtc/cdk/pull/890/commits/0041c135f7872cb9dda7e68c1adfad8d013672c8 explicitly but it seems ok.