Skip to content

Commit c445ac4

Browse files
committed
Add a binary that uses a Postgres backend
Building of this binary is controlled with features, allowing downstream users to build just the SQLite version and not be concerned with the tokio-postgres dependency tree (which includes links to OpenSSL and other details). The Postgres version is disabled by default. This does not change the binary name for the SQLite build, just to avoid confusion for people upgrading to the new version.
1 parent 6e8c72b commit c445ac4

File tree

15 files changed

+579
-446
lines changed

15 files changed

+579
-446
lines changed

.github/workflows/checks.yml

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,13 @@ jobs:
6666
uses: actions-rs/[email protected]
6767
with:
6868
command: rustdoc
69-
args: -p taskchampion-sync-server --all-features -- -Z unstable-options --check -Dwarnings
69+
args: -p taskchampion-sync-server --bin taskchampion-sync-server --all-features -- -Z unstable-options --check -Dwarnings
70+
71+
- name: taskchampion-sync-server-postgres
72+
uses: actions-rs/[email protected]
73+
with:
74+
command: rustdoc
75+
args: -p taskchampion-sync-server --bin taskchampion-sync-server-postgres --all-features -- -Z unstable-options --check -Dwarnings
7076

7177
- name: taskchampion-sync-server-core
7278
uses: actions-rs/[email protected]
@@ -80,6 +86,12 @@ jobs:
8086
command: rustdoc
8187
args: -p taskchampion-sync-server-storage-sqlite --all-features -- -Z unstable-options --check -Dwarnings
8288

89+
- name: taskchampion-sync-server-storage-postgres
90+
uses: actions-rs/[email protected]
91+
with:
92+
command: rustdoc
93+
args: -p taskchampion-sync-server-storage-postgres --all-features -- -Z unstable-options --check -Dwarnings
94+
8395
fmt:
8496
runs-on: ubuntu-latest
8597
name: "Formatting"

Cargo.lock

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

README.md

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ for more on how to use this project.
1717

1818
## Repository Guide
1919

20-
The repository is comprised of three crates:
20+
The repository is comprised of four crates:
2121

2222
- `taskchampion-sync-server-core` implements the core of the protocol
2323
- `taskchampion-sync-server-storage-sqlite` implements an SQLite backend for the core
@@ -60,16 +60,34 @@ cargo build --release
6060
After build the binary is located in
6161
`target/release/taskchampion-sync-server`.
6262

63-
### Building the Container
63+
#### Building the Postgres backend
6464

65-
To build the container, execute the following commands.
65+
The storage backend is controlled by Cargo features `postres` and `sqlite`.
66+
By default, only the `sqlite` feature is enabled.
67+
To enable building the Postgres backend, add `--features postgres`.
68+
The Postgres binary is located in
69+
`target/release/taskchampion-sync-server-postgres`.
6670

71+
### Building the Docker Images
72+
73+
To build the images, execute the following commands.
74+
75+
SQLite:
76+
```sh
77+
source .env
78+
docker build \
79+
--build-arg RUST_VERSION=${RUST_VERSION} \
80+
--build-arg ALPINE_VERSION=${ALPINE_VERSION} \
81+
-t taskchampion-sync-server docker/sqlite
82+
```
83+
84+
Postgres:
6785
```sh
6886
source .env
6987
docker build \
7088
--build-arg RUST_VERSION=${RUST_VERSION} \
7189
--build-arg ALPINE_VERSION=${ALPINE_VERSION} \
72-
-t taskchampion-sync-server .
90+
-t taskchampion-sync-server-postgres docker/postgres
7391
```
7492

7593
Now to run it, simply exec.

postgres/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
//! An external application may:
2222
//! - Add additional tables to the database
2323
//! - Add additional columns to the `clients` table. If those columns do not have default
24-
//! values, calls to [`Txn::new_client`] will fail. It is possible to configure
24+
//! values, calls to `Txn::new_client` will fail. It is possible to configure
2525
//! `taskchampion-sync-server` to never call this method.
2626
//! - Insert rows into the `clients` table, using default values for all columns except
2727
//! `client_id` and application-specific columns.

server/Cargo.toml

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,25 @@ authors = ["Dustin J. Mitchell <[email protected]>"]
55
edition = "2021"
66
publish = false
77

8+
[features]
9+
# By default, only build the SQLite backend.
10+
default = ["sqlite"]
11+
sqlite = ["dep:taskchampion-sync-server-storage-sqlite"]
12+
postgres = ["dep:taskchampion-sync-server-storage-postgres"]
13+
14+
[[bin]]
15+
# The simple binary name is the SQLite build.
16+
name = "taskchampion-sync-server"
17+
required-features = ["sqlite"]
18+
19+
[[bin]]
20+
name = "taskchampion-sync-server-postgres"
21+
required-features = ["postgres"]
22+
823
[dependencies]
924
taskchampion-sync-server-core = { path = "../core" }
10-
taskchampion-sync-server-storage-sqlite = { path = "../sqlite" }
25+
taskchampion-sync-server-storage-sqlite = { path = "../sqlite", optional = true }
26+
taskchampion-sync-server-storage-postgres = { path = "../postgres", optional = true }
1127
uuid.workspace = true
1228
actix-web.workspace = true
1329
anyhow.workspace = true

server/src/api/add_snapshot.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,10 @@ pub(crate) async fn service(
5656

5757
#[cfg(test)]
5858
mod test {
59-
use crate::WebServer;
60-
use crate::{api::CLIENT_ID_HEADER, WebConfig};
59+
use crate::{
60+
api::CLIENT_ID_HEADER,
61+
web::{WebConfig, WebServer},
62+
};
6163
use actix_web::{http::StatusCode, test, App};
6264
use pretty_assertions::assert_eq;
6365
use taskchampion_sync_server_core::{InMemoryStorage, ServerConfig, Storage, NIL_VERSION_ID};

server/src/api/add_version.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,10 @@ pub(crate) async fn service(
101101

102102
#[cfg(test)]
103103
mod test {
104-
use crate::WebServer;
105-
use crate::{api::CLIENT_ID_HEADER, WebConfig};
104+
use crate::{
105+
api::CLIENT_ID_HEADER,
106+
web::{WebConfig, WebServer},
107+
};
106108
use actix_web::{http::StatusCode, test, App};
107109
use pretty_assertions::assert_eq;
108110
use taskchampion_sync_server_core::{InMemoryStorage, ServerConfig, Storage};

server/src/api/get_child_version.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,10 @@ pub(crate) async fn service(
4949

5050
#[cfg(test)]
5151
mod test {
52-
use crate::WebServer;
53-
use crate::{api::CLIENT_ID_HEADER, WebConfig};
52+
use crate::{
53+
api::CLIENT_ID_HEADER,
54+
web::{WebConfig, WebServer},
55+
};
5456
use actix_web::{http::StatusCode, test, App};
5557
use pretty_assertions::assert_eq;
5658
use taskchampion_sync_server_core::{InMemoryStorage, ServerConfig, Storage, NIL_VERSION_ID};

server/src/api/get_snapshot.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,10 @@ pub(crate) async fn service(
3434

3535
#[cfg(test)]
3636
mod test {
37-
use crate::WebServer;
38-
use crate::{api::CLIENT_ID_HEADER, WebConfig};
37+
use crate::{
38+
api::CLIENT_ID_HEADER,
39+
web::{WebConfig, WebServer},
40+
};
3941
use actix_web::{http::StatusCode, test, App};
4042
use chrono::{TimeZone, Utc};
4143
use pretty_assertions::assert_eq;

server/src/api/mod.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use actix_web::{error, web, HttpRequest, Result, Scope};
22
use taskchampion_sync_server_core::{ClientId, Server, ServerError};
33

4-
use crate::WebConfig;
4+
use crate::web::WebConfig;
55

66
mod add_snapshot;
77
mod add_version;
@@ -89,6 +89,7 @@ mod test {
8989
web_config: WebConfig {
9090
client_id_allowlist: None,
9191
create_clients: true,
92+
..WebConfig::default()
9293
},
9394
};
9495
let req = actix_web::test::TestRequest::default()
@@ -106,6 +107,7 @@ mod test {
106107
web_config: WebConfig {
107108
client_id_allowlist: Some([client_id_ok].into()),
108109
create_clients: true,
110+
..WebConfig::default()
109111
},
110112
};
111113
let req = actix_web::test::TestRequest::default()

0 commit comments

Comments
 (0)