Skip to content

Commit 4f48a7f

Browse files
committed
feat: db migrations
1 parent fe53ac3 commit 4f48a7f

File tree

7 files changed

+85
-5
lines changed

7 files changed

+85
-5
lines changed

Makefile

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -302,12 +302,19 @@ proof_aggregator_install: ## Install the aggregation mode with proving enabled
302302
proof_aggregator_write_program_ids: ## Write proof aggregator zkvm programs ids
303303
@cd aggregation_mode/proof_aggregator && ./scripts/build_programs.sh
304304

305-
agg_mode_batcher_start_local:
305+
agg_mode_docker_up:
306306
@cd aggregation_mode && docker-compose up -d
307+
308+
agg_mode_docker_down:
309+
@cd aggregation_mode && docker-compose down
310+
311+
agg_mode_run_migrations: agg_mode_docker_up
312+
cargo run --manifest-path ./aggregation_mode/Cargo.toml --release --bin migrate -- postgres://postgres:postgres@localhost:5435/
313+
314+
agg_mode_batcher_start_local: agg_mode_run_migrations
307315
cargo run --manifest-path ./aggregation_mode/Cargo.toml --release --bin agg_mode_batcher -- config-files/config-agg-mode-batcher.yaml
308316

309-
agg_mode_batcher_start_ethereum_package:
310-
@cd aggregation_mode && docker-compose up -d
317+
agg_mode_batcher_start_ethereum_package: agg_mode_run_migrations
311318
cargo run --manifest-path ./aggregation_mode/Cargo.toml --release --bin agg_mode_batcher -- config-files/config-agg-mode-batcher-ethereum-package.yaml
312319

313320
__AGGREGATOR__: ## ____

aggregation_mode/Cargo.lock

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

aggregation_mode/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[workspace]
22
resolver = "2"
3-
members = ["./batcher", "./proof_aggregator"]
3+
members = ["./batcher", "./proof_aggregator", "./db"]
44

55
[workspace.package]
66
version = "0.1.0"

aggregation_mode/db/Cargo.toml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
[package]
2+
name = "agg_mode_db"
3+
version = "0.1.0"
4+
edition = "2021"
5+
6+
[dependencies]
7+
tokio = { version = "1"}
8+
# TODO: enable tls
9+
sqlx = { version = "0.8", features = [ "runtime-tokio", "postgres", "migrate" ] }
10+
11+
12+
[[bin]]
13+
name = "migrate"
14+
path = "cmd/migrate.rs"

aggregation_mode/db/cmd/migrate.rs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
use sqlx::postgres::PgPoolOptions;
2+
3+
fn read_db_conn_from_args() -> String {
4+
let args: Vec<String> = std::env::args().collect();
5+
if args.len() < 2 {
6+
panic!(
7+
"You mus provide a config file. Usage: {} <config-file-path>",
8+
args[0]
9+
);
10+
}
11+
12+
args[1].clone()
13+
}
14+
15+
#[tokio::main]
16+
async fn main() {
17+
let db_connection_url = read_db_conn_from_args();
18+
let pool = PgPoolOptions::new()
19+
.connect(&db_connection_url)
20+
.await
21+
.expect("To connect to db");
22+
23+
sqlx::migrate!("./migrations")
24+
.run(&pool)
25+
.await
26+
.expect("Migrations to run correctly")
27+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
CREATE TYPE task_status AS ENUM ('pending', 'verified');
2+
3+
CREATE TABLE tasks (
4+
task_id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
5+
status task_status
6+
);
7+
8+
CREATE TABLE proofs (
9+
proof_id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
10+
address CHAR(42),
11+
proving_system_id INT,
12+
vm_program_code BYTEA,
13+
proof BYTEA,
14+
public_inputs BYTEA,
15+
proof_commitment BYTEA,
16+
task_id UUID REFERENCES tasks(task_id)
17+
);
18+
19+
CREATE TABLE payment_events (
20+
payment_event_id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
21+
address CHAR(42),
22+
started_at INTEGER,
23+
valid_until INTEGER
24+
);

aggregation_mode/docker-compose.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,4 @@ services:
2020
depends_on:
2121
- postgres
2222
ports:
23-
- 8090:8090
23+
- 8090:8080

0 commit comments

Comments
 (0)