Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add postgres support in addition to sqlite for recon #302

Closed
wants to merge 13 commits into from

Conversation

dav1do
Copy link
Contributor

@dav1do dav1do commented Apr 5, 2024

All Store tests run with postgres and sqlite. Postgres tests no-op unless PG_TESTS=1, so that cargo test still passes even if you haven't set up a docker postgres image. In CI we can run them all in order to make sure the postgres type/query handling is valid. The make check-migrations-ci command handles setting up the dbs, applying migrations, running tests (will duplicate some tests with the current make tests command but tries to use the same parameters to avoid rebuildling things), and then cleaning up.

The database can be specified with ceramic-one daemon --database-url $DB_URL or CERAMIC_ONE_DATABASE_URL="..." ceramic-one daemon. Postgres or sqlite will be chosen based on the URL prefix, and defaults to putting a sqlite file in the "default directory" (see DaemonOpts::default_directory).

I also added put() to the iron_bitswap::Store trait as we were going through the concrete struct before. I couldn't get away from using concrete types, so I select the database and then use generics to bind them to the flavors of trait we need. We should be able to simplify/consolidate some of these traits now that we rely on &self rather than &mut self in recon::Store, but this PR is already big.

Copy link

linear bot commented Apr 5, 2024

Base automatically changed from feat/ws1-1543-delivery-order to main April 5, 2024 19:02
@dav1do dav1do force-pushed the feat/ws1-1544-postgres branch 2 times, most recently from 6c5c588 to 60edf7e Compare April 6, 2024 01:54
@dav1do dav1do temporarily deployed to github-tests-2024 April 6, 2024 02:03 — with GitHub Actions Inactive
@dav1do dav1do requested a review from 3benbox April 10, 2024 19:47
 - a bunch of sql modules now...
- stopped using query! macros as they don't work for 2 backends.
- refactored things try to share queries but still a lot of pg/sqlite specific stuff. tried to keep it in one place so it was easier to reason about.
 - pushed some store checks up to the callers (e.g. is left > right fencepost)
Some ugly macro use (hack-ro?) to run a test for all databases. The postgres tests only run if `PG_TESTS=1`. The intention being that we don't want `cargo test` to fail generally, but in CI we want to start a db and make sure things pass

I also updated the bitswap Store trait to include put, as we were going to the blockstore directly before
Still need to sort out the concrete types bound to daemon in c1. Should be able to get a database trait to work, but the many bounds on sqlx has made it super tedious..

If I really can't get it right, we could move some setup to run() and branch building concrete pg/sql store instances so the types can be inferred rather than declared. Or we could use Box<dyn Store> etc and use dynamic lookup
@dav1do dav1do temporarily deployed to github-tests-2024 April 10, 2024 20:36 — with GitHub Actions Inactive
@dav1do dav1do marked this pull request as ready for review April 12, 2024 18:34
@dav1do dav1do temporarily deployed to github-tests-2024 April 12, 2024 18:47 — with GitHub Actions Inactive
@dav1do
Copy link
Contributor Author

dav1do commented Apr 16, 2024

I attempted to get the postgres tests/docker running in CI and didn't get the networking right, so I reverted this branch back to where it was and I'm going to make a new branch to follow up with that.

@dav1do dav1do temporarily deployed to github-tests-2024 April 16, 2024 13:09 — with GitHub Actions Inactive
@dav1do
Copy link
Contributor Author

dav1do commented Apr 16, 2024

I attempted to get the postgres tests/docker running in CI and didn't get the networking right, so I reverted this branch back to where it was and I'm going to make a new branch to follow up with that.

#308 handles this.

also increased sql connection timeout
The services section will start the database and migrations will be applied when connecting.
We could use the script someday if we use query! macros but we likely never will given we have multiple backends.
@dav1do
Copy link
Contributor Author

dav1do commented Apr 16, 2024

I attempted to get the postgres tests/docker running in CI and didn't get the networking right, so I reverted this branch back to where it was and I'm going to make a new branch to follow up with that.

#308 handles this.

Which has now been incorporated into this branch... along with one more change to capture store related metrics on the API side.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant