Skip to content

Commit

Permalink
feat: database (#17)
Browse files Browse the repository at this point in the history
* feat: database

* fix: test CI

* fix: timeout
  • Loading branch information
zk-steve authored Dec 13, 2024
1 parent e0765c8 commit 35cf132
Show file tree
Hide file tree
Showing 46 changed files with 1,571 additions and 848 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/rust-ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ jobs:
test-and-coverage:
name: Test and Coverage
runs-on: ubuntu-latest
timeout-minutes: 10
timeout-minutes: 20
steps:
- uses: actions/checkout@v4
with:
Expand All @@ -59,4 +59,4 @@ jobs:
- name: Set PKG_CONFIG_PATH
run: echo "PKG_CONFIG_PATH=/usr/lib/pkgconfig" >> $GITHUB_ENV
- name: Run tests
run: cargo tarpaulin --all-features --verbose --tests --skip-clean
run: cargo tarpaulin --all-features --verbose --tests --skip-clean --engine llvm
159 changes: 156 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 5 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,12 @@ axum = { version = "0.8.0-alpha.1" }
bincode = { version = "1.3.3" }
clap = { version = "4.5.17" }
config = { version = "0.14.0" }
deadpool-diesel = { version = "0.6.1" }
diesel = { version = "2.2.6" }
diesel_migrations = { version = "2.2.0" }
glob = { version = "0.3.1" }
graphile_worker = { version = "0.8.0" }
itertools = { version = "0.13.0" }
lazy_static = { version = "1.5.0" }
log = { version = "0.4.22" }
opentelemetry = { version = "0.27.0" }
opentelemetry-otlp = { version = "0.27.0" }
Expand All @@ -46,8 +48,10 @@ test-log = { version = "0.2.16" }
testcontainers-modules = { version = "0.11.3" }
thiserror = { version = "2.0.3" }
tokio = { version = "1.39.3" }
tower = { version = "0.5.1" }
tower-http = { version = "0.6.1" }
tracing = { version = "0.1.40" }
tracing-bunyan-formatter = { version = "0.3.9" }
tracing-opentelemetry = { version = "0.28.0" }
tracing-subscriber = { version = "0.3.18" }
uuid = { version = "1.11.0" }
17 changes: 17 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
POSTGRES_DIR="./crates/adapter/src/postgres"
DATABASE_URL="postgres://postgres:[email protected]:5432/postgrest"
PKG_NAME=zksteve/frog
BUILD_VERSION=$(shell git describe --long)
BUILD_RELEASE=$(shell git describe --tags --abbrev=0)
Expand All @@ -21,3 +23,18 @@ push:
docker push $(PKG_NAME)-server:$(BUILD_VERSION) && \
docker push $(PKG_NAME)-client:$(BUILD_VERSION) && \
docker push $(PKG_NAME)-worker:$(BUILD_VERSION)

setup-db:
diesel setup --database-url ${DATABASE_URL} \
--migration-dir ${POSTGRES_DIR}/migrations \
--config-file ${POSTGRES_DIR}/diesel.toml

migrate:
diesel migration run --database-url ${DATABASE_URL} \
--migration-dir ${POSTGRES_DIR}/migrations \
--config-file ${POSTGRES_DIR}/diesel.toml

migrate-redo:
diesel migration redo --database-url ${DATABASE_URL} \
--migration-dir ${POSTGRES_DIR}/migrations \
--config-file ${POSTGRES_DIR}/diesel.toml
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@ Learn more about the system's architecture [here](docs/architecture.md).
## Future Plans

- [ ] Finalize Docker and Kurtosis configurations to simplify deployment on Docker or Kubernetes.
- [ ] Complete the implementation of the worker service and database (currently, the server processes tasks and stores
data locally).
- [ ] Complete the implementation of the worker service ~~and database (currently, the server processes tasks and stores
data locally)~~.
- [ ] Develop a toolkit similar to [Ignite](https://github.com/ignite/cli) to streamline the development process with a
CLI for scaffolding and managing projects.
- [ ] Smarter way to handle common params.
- [ ] Add more documentation and comments in the codebase to enhance maintainability and usability.
12 changes: 12 additions & 0 deletions crates/adapter/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,17 @@ edition = "2021"

[dependencies]
async-trait = { workspace = true }
bincode = { workspace = true }
deadpool-diesel = { workspace = true, features = ["postgres", "serde"] }
diesel = { workspace = true, features = [
"postgres",
"postgres_backend",
"uuid",
"serde_json",
] }
diesel_migrations = { workspace = true }
frog_core = { workspace = true }
log = { workspace = true }
reqwest = { workspace = true }
serde = { workspace = true, features = ["derive"] }
uuid = { workspace = true }
4 changes: 2 additions & 2 deletions crates/adapter/src/in_memory/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,13 @@ impl SessionPort for SessionInMemoryRepository {
Ok(session_id)
}

async fn delete(&self, session_id: SessionId) -> Result<SessionId, CoreError> {
async fn delete(&self, session_id: SessionId) -> Result<(), CoreError> {
self.inner_state
.write()
.unwrap()
.sessions
.remove(&session_id)
.ok_or(CoreError::NotFound)?;
Ok(session_id)
Ok(())
}
}
1 change: 1 addition & 0 deletions crates/adapter/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
pub mod http;
pub mod in_memory;
pub mod postgres;
7 changes: 7 additions & 0 deletions crates/adapter/src/postgres/config.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
use serde::Deserialize;

#[derive(Deserialize, Debug, Clone)]
pub struct DBConfig {
pub url: String,
pub max_size: usize,
}
9 changes: 9 additions & 0 deletions crates/adapter/src/postgres/diesel.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# For documentation on how to configure this file,
# see https://diesel.rs/guides/configuring-diesel-cli

[print_schema]
custom_type_derives = ["diesel::query_builder::QueryId"]
file = "schema.rs"

[migrations_directory]
dir = "migrations"
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
-- This file was automatically created by Diesel to setup helper functions
-- and other internal bookkeeping. This file is safe to edit, any future
-- changes will be added to existing projects as new migrations.

DROP FUNCTION IF EXISTS diesel_manage_updated_at(_tbl regclass);
DROP FUNCTION IF EXISTS diesel_set_updated_at();
Loading

0 comments on commit 35cf132

Please sign in to comment.