Skip to content

Commit

Permalink
Use raw SQL queries
Browse files Browse the repository at this point in the history
  • Loading branch information
MikailBag committed Apr 18, 2020
1 parent 38b4071 commit 8d3f054
Show file tree
Hide file tree
Showing 19 changed files with 477 additions and 428 deletions.
100 changes: 44 additions & 56 deletions Cargo.lock

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

3 changes: 0 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,3 @@ debug = 1

[workspace]
members=["src/*"]

[patch.crates-io]
diesel_derives = { git = "https://github.com/diesel-rs/diesel", rev = "537eb5d" }
3 changes: 2 additions & 1 deletion basic-setup-profile.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ problems:
sources:
- path: "/opt/jjs/pkg/problems.tgz"
pki:
create-ca: true
create-ca: true
toolchains: {}
15 changes: 8 additions & 7 deletions src/db/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,20 @@ edition = "2018"
[dependencies]
serde = { version = "1.0.106", features = ["derive"] }
uuid = { version = "0.8.1", features = ["serde", "v4"] }
r2d2 = "0.8.8"
invoker-api = {path = "../invoker-api"}
bincode = "1.2.1"
anyhow = "1.0.28"
serde_json = "1.0.51"
redis = {version = "0.15.1", default-features = false, features = []}
async-trait = "0.1.30"
futures = "0.3.4"
tokio = { version = "0.2.18", features = ["rt-threaded", "blocking"] }
tokio = { version = "0.2.18", features = [] }
chrono = { version = "0.4.11", features = ["serde"] }
tokio-postgres = { version = "0.5.3", optional = true }
postgres-types = { version = "0.1.1", optional = true, features = ["derive", "with-uuid-0_8", "with-serde_json-1", "with-chrono-0_4"] }
bb8 = { version = "0.4.1", optional = true }
bb8-postgres = { version = "0.4.0", optional = true }

[dependencies.diesel]
git = "https://github.com/diesel-rs/diesel"
rev = "537eb5d"
default-features = false
features = ["postgres", "uuid", "r2d2", "serde_json", "chrono"]
[features]
postgres = ["tokio-postgres", "postgres-types", "bb8", "bb8-postgres"]
default = ["postgres"]
11 changes: 4 additions & 7 deletions src/db/migrations/2019-02-13-163254_initial/up.sql
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
CREATE DOMAIN unsigned_integer AS INTEGER
CHECK (VALUE >= 0);

-- Users table

CREATE SEQUENCE user_id_seq START WITH 0 MINVALUE 0;
Expand Down Expand Up @@ -29,10 +26,10 @@ CREATE SEQUENCE run_id_seq START WITH 0 MINVALUE 0;

CREATE TABLE runs
(
id unsigned_integer DEFAULT nextval('run_id_seq') PRIMARY KEY NOT NULL,
id INTEGER DEFAULT nextval('run_id_seq') PRIMARY KEY NOT NULL,
toolchain_id VARCHAR(100) NOT NULL,
problem_id VARCHAR(100) NOT NULL,
rejudge_id unsigned_integer NOT NULL,
rejudge_id INTEGER NOT NULL,
user_id UUID REFERENCES users (id) NOT NULL,
contest_id VARCHAR(100) NOT NULL
);
Expand All @@ -45,8 +42,8 @@ CREATE SEQUENCE inv_id_seq START WITH 0 MINVALUE 0;

CREATE table invocations
(
id unsigned_integer DEFAULT nextval('inv_id_seq') UNIQUE PRIMARY KEY NOT NULL,
run_id unsigned_integer REFERENCES runs(id) NOT NULL,
id INTEGER DEFAULT nextval('inv_id_seq') UNIQUE PRIMARY KEY NOT NULL,
run_id INTEGER REFERENCES runs(id) NOT NULL,
-- This is serialized `InvokeTask`. See `invoker-api` for its definition
invoke_task bytea NOT NULL,
-- see InvocationStatus
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ CREATE SEQUENCE participations_id_seq START WITH 0 MINVALUE 0;

CREATE TABLE participations
(
id unsigned_integer DEFAULT nextval('participations_id_seq') UNIQUE PRIMARY KEY NOT NULL,
id INTEGER DEFAULT nextval('participations_id_seq') UNIQUE PRIMARY KEY NOT NULL,
user_id UUID REFERENCES users(id) NOT NULL,
contest_id VARCHAR NOT NULL,
phase SMALLINT NOT NULL,
Expand Down
2 changes: 1 addition & 1 deletion src/db/src/conn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use anyhow::{Context as _, Result};
#[derive(Debug)]
pub struct DbConn {
pub(crate) mem: crate::repo::MemoryRepo,
pub(crate) pg: Option<crate::repo::DieselRepo>,
pub(crate) pg: Option<crate::repo::PgRepo>,
pub(crate) redis: Option<crate::repo::RedisRepo>,
}

Expand Down
6 changes: 4 additions & 2 deletions src/db/src/connect.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::{
repo::{DieselRepo, MemoryRepo, RedisRepo},
repo::{MemoryRepo, PgRepo, RedisRepo},
DbConn,
};
use anyhow::{Context, Result};
Expand Down Expand Up @@ -28,7 +28,9 @@ pub async fn connect(options: ConnectOptions) -> Result<DbConn> {
let mem = MemoryRepo::new();
let pg = match options.pg {
Some(pg_conn_str) => {
let conn = DieselRepo::new(&pg_conn_str).context("cannot connect to postgres")?;
let conn = PgRepo::new(&pg_conn_str)
.await
.context("cannot connect to postgres")?;
Some(conn)
}
None => None,
Expand Down
4 changes: 2 additions & 2 deletions src/db/src/repo.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
mod diesel_pg;
mod memory;
mod pg;
mod redis;

pub use self::redis::RedisRepo;
pub use diesel_pg::DieselRepo;
pub use memory::MemoryRepo;
pub use pg::PgRepo;

use crate::schema::*;
use anyhow::{bail, Result};
Expand Down
Loading

0 comments on commit 8d3f054

Please sign in to comment.