···1-# This file contains settings for `cargo hakari`.
2-# See https://docs.rs/cargo-hakari/latest/cargo_hakari/config for a full list of options.
3-4-hakari-package = "weaver-workspace-hack"
5-6-# Format version for hakari's output. Version 4 requires cargo-hakari 0.9.22 or above.
7-dep-format-version = "4"
8-9-# Setting workspace.resolver = "2" in the root Cargo.toml is HIGHLY recommended.
10-# Hakari works much better with the new feature resolver.
11-# For more about the new feature resolver, see:
12-# https://blog.rust-lang.org/2021/03/25/Rust-1.51.0.html#cargos-new-feature-resolver
13-resolver = "2"
14-15-# Add triples corresponding to platforms commonly used by developers here.
16-# https://doc.rust-lang.org/rustc/platform-support.html
17-platforms = [
18- # "x86_64-unknown-linux-gnu",
19- # "x86_64-apple-darwin",
20- # "x86_64-pc-windows-msvc",
21-]
22-23-# Write out exact versions rather than a semver range. (Defaults to false.)
24-# exact-versions = true
···32chrono = { version = "0.4" }
33serde_json = "1.0"
3400000000035[target.'cfg(target_arch = "wasm32")'.dependencies]
36time = { version = "0.3", features = ["wasm-bindgen"] }
37console_error_panic_hook = "0.1"
···32chrono = { version = "0.4" }
33serde_json = "1.0"
3435+diesel = { version = "2.3", features = ["sqlite", "returning_clauses_for_sqlite_3_35", "chrono", "serde_json"] }
36+diesel_migrations = { version = "2.3", features = ["sqlite"] }
37+38+39+[target.'cfg(all(target_family = "wasm", target_os = "unknown"))'.dependencies]
40+sqlite-wasm-rs = { version = "0.4", features = ["relaxed-idb"] }
41+42+43+44[target.'cfg(target_arch = "wasm32")'.dependencies]
45time = { version = "0.3", features = ["wasm-bindgen"] }
46console_error_panic_hook = "0.1"
+9
crates/weaver-app/diesel.toml
···000000000
···1+# For documentation on how to configure this file,
2+# see https://diesel.rs/guides/configuring-diesel-cli
3+4+[print_schema]
5+file = "src/schema.rs"
6+custom_type_derives = ["diesel::query_builder::QueryId", "Clone", "std::fmt::Debug", "jacquard::IntoStatic"]
7+8+[migrations_directory]
9+dir = "/home/orual/Projects/weaver.sh/crates/weaver-app/migrations"
+13
crates/weaver-common/Cargo.toml
···50markdown-weaver-escape = { workspace = true, features = ["std"] }
51mime-sniffer = "^0.1"
5200000000000005354[dev-dependencies]
55tokio = { version = "1", features = ["macros", "rt"] }
···1--- This file was automatically created by Diesel to setup helper functions
2--- and other internal bookkeeping. This file is safe to edit, any future
3--- changes will be added to existing projects as new migrations.
4-5-DROP FUNCTION IF EXISTS diesel_manage_updated_at(_tbl regclass);
6-DROP FUNCTION IF EXISTS diesel_set_updated_at();
···1--- This file was automatically created by Diesel to setup helper functions
2--- and other internal bookkeeping. This file is safe to edit, any future
3--- changes will be added to existing projects as new migrations.
4-5-6-7-8--- Sets up a trigger for the given table to automatically set a column called
9--- `updated_at` whenever the row is modified (unless `updated_at` was included
10--- in the modified columns)
11---
12--- # Example
13---
14--- ```sql
15--- CREATE TABLE users (id SERIAL PRIMARY KEY, updated_at TIMESTAMP NOT NULL DEFAULT NOW());
16---
17--- SELECT diesel_manage_updated_at('users');
18--- ```
19-CREATE OR REPLACE FUNCTION diesel_manage_updated_at(_tbl regclass) RETURNS VOID AS $$
20-BEGIN
21- EXECUTE format('CREATE TRIGGER set_updated_at BEFORE UPDATE ON %s
22- FOR EACH ROW EXECUTE PROCEDURE diesel_set_updated_at()', _tbl);
23-END;
24-$$ LANGUAGE plpgsql;
25-26-CREATE OR REPLACE FUNCTION diesel_set_updated_at() RETURNS trigger AS $$
27-BEGIN
28- IF (
29- NEW IS DISTINCT FROM OLD AND
30- NEW.updated_at IS NOT DISTINCT FROM OLD.updated_at
31- ) THEN
32- NEW.updated_at := current_timestamp;
33- END IF;
34- RETURN NEW;
35-END;
36-$$ LANGUAGE plpgsql;
···1create table if not exists registrations (
2- id serial primary key,
3 domain text not null unique,
4 did text not null,
5 secret text not null,
6- created timestamp
7- with
8- time zone not null default (now () at time zone 'utc'),
9- registered text
10);
1112create table if not exists public_keys (
13- id serial primary key,
14 did text not null,
15 name text not null,
16 key_contents text not null,
17 rkey text not null,
18- created timestamp
19- with
20- time zone not null default (now () at time zone 'utc'),
21- unique (did, name, key_contents)
22);
2324create table if not exists follows (
25 user_did text not null,
26 subject_did text not null,
27 rkey text not null,
28- followed_at timestamp
29- with
30- time zone not null default (now () at time zone 'utc'),
31- primary key (user_did, subject_did),
32 check (user_did <> subject_did)
33);
3435create table if not exists _jetstream (
36- id serial primary key,
37 last_time_us integer not null
38);
3940create table if not exists emails (
41- id serial primary key,
42 did text not null,
43 email text not null,
44- verified integer not null default 0,
45 verification_code text not null,
46- last_sent timestamp
47- with
48- time zone not null default (now () at time zone 'utc'),
49- is_primary integer not null default 0,
50- created timestamp
51- with
52- time zone not null default (now () at time zone 'utc'),
53- unique (did, email)
54);
5556create table if not exists profile (
57 -- id
58- id serial primary key,
59 did text not null,
60 -- data
61 avatar text,
···63 include_bluesky boolean not null default false,
64 include_tangled boolean not null default false,
65 location text,
66- pinned_post jsonb,
67- created_at timestamp
68- with
69- time zone default (now () at time zone 'utc'),
70- -- constraints
71- unique (did)
72);
7374create table if not exists profile_links (
75 -- id
76- id serial primary key,
77 did text not null,
78 -- data
79 link text not null,
···8384create table if not exists profile_pronouns (
85 -- id
86- id serial primary key,
87 did text not null,
88 -- data
89 pronoun text not null,
···9394-- OAuth sessions table for jacquard ClientSessionData
95create table if not exists oauth_sessions (
96- id serial primary key,
97 -- Extracted from ClientSessionData for indexing
98 did text not null,
99 session_id text not null,
100- -- Full ClientSessionData as jsonb
101- session_data jsonb not null,
102- created_at timestamp with time zone not null default (now() at time zone 'utc'),
103- updated_at timestamp with time zone not null default (now() at time zone 'utc'),
104 unique (did, session_id)
105);
106107-- OAuth authorization requests table for jacquard AuthRequestData
108create table if not exists oauth_auth_requests (
109- id serial primary key,
110 -- Extracted from AuthRequestData for indexing
111 state text not null unique,
112 -- Optional DID if known at auth request time
113 account_did text,
114- -- Full AuthRequestData as jsonb
115- auth_req_data jsonb not null,
116- created_at timestamp with time zone not null default (now() at time zone 'utc'),
117- expires_at timestamp with time zone not null default ((now() at time zone 'utc') + interval '10 minutes')
118);
119120-- Index for quick session lookups
···1create table if not exists registrations (
2+ id integer not null primary key autoincrement,
3 domain text not null unique,
4 did text not null,
5 secret text not null,
6+ created timestamp not null default (datetime('now')),
7+ registered text
008);
910create table if not exists public_keys (
11+ id integer not null primary key autoincrement,
12 did text not null,
13 name text not null,
14 key_contents text not null,
15 rkey text not null,
16+ created timestamp not null default (datetime('now')),
17+ unique (did, name, key_contents)
0018);
1920create table if not exists follows (
21 user_did text not null,
22 subject_did text not null,
23 rkey text not null,
24+ followed_at timestamp not null default (datetime('now')),
25+ primary key (user_did, subject_did),
0026 check (user_did <> subject_did)
27);
2829create table if not exists _jetstream (
30+ id integer not null primary key autoincrement,
31 last_time_us integer not null
32);
3334create table if not exists emails (
35+ id integer not null primary key autoincrement,
36 did text not null,
37 email text not null,
38+ verified boolean not null default false,
39 verification_code text not null,
40+ last_sent timestamp not null default (datetime('now')),
41+ is_primary boolean not null default false,
42+ created timestamp not null default (datetime('now')),
43+ unique (did, email)
000044);
4546create table if not exists profile (
47 -- id
48+ id integer not null primary key autoincrement,
49 did text not null,
50 -- data
51 avatar text,
···53 include_bluesky boolean not null default false,
54 include_tangled boolean not null default false,
55 location text,
56+ pinned_post text,
57+ created_at timestamp default (datetime('now')),
58+ -- constraints
59+ unique (did)
0060);
6162create table if not exists profile_links (
63 -- id
64+ id integer not null primary key autoincrement,
65 did text not null,
66 -- data
67 link text not null,
···7172create table if not exists profile_pronouns (
73 -- id
74+ id integer not null primary key autoincrement,
75 did text not null,
76 -- data
77 pronoun text not null,
···8182-- OAuth sessions table for jacquard ClientSessionData
83create table if not exists oauth_sessions (
84+ id integer not null primary key autoincrement,
85 -- Extracted from ClientSessionData for indexing
86 did text not null,
87 session_id text not null,
88+ -- Full ClientSessionData as JSON
89+ session_data blob not null,
90+ created_at timestamp not null default (datetime('now')),
91+ updated_at timestamp not null default (datetime('now')),
92 unique (did, session_id)
93);
9495-- OAuth authorization requests table for jacquard AuthRequestData
96create table if not exists oauth_auth_requests (
97+ id integer not null primary key autoincrement,
98 -- Extracted from AuthRequestData for indexing
99 state text not null unique,
100 -- Optional DID if known at auth request time
101 account_did text,
102+ -- Full AuthRequestData as JSON
103+ auth_req_data blob not null,
104+ created_at timestamp not null default (datetime('now')),
105+ expires_at timestamp not null default (datetime('now', '+10 minutes'))
106);
107108-- Index for quick session lookups
+8-4
crates/weaver-index/src/db.rs
···4use diesel_async::RunQueryDsl;
5use diesel_async::pooled_connection::AsyncDieselConnectionManager;
6use diesel_async::pooled_connection::deadpool::Pool;
078#[derive(Clone)]
9pub struct Db {
10- pub pool: Pool<diesel_async::AsyncPgConnection>,
11}
1213impl Db {
···20 } else {
21 std::env::var("DATABASE_URL").expect("DATABASE_URL must be set")
22 };
23- let config =
24- AsyncDieselConnectionManager::<diesel_async::AsyncPgConnection>::new(database_url);
025 let pool = Pool::builder(config)
26 .build()
27 .expect("Failed to create pool");
···37 } else {
38 std::env::var("DATABASE_URL").expect("DATABASE_URL must be set")
39 };
40- let mut connection = PgConnection::establish(&database_url)
41 .unwrap_or_else(|_| panic!("Error connecting to {}", database_url));
42 // This will run the necessary migrations.
43 //
···57 }
58 Ok(())
59}
00
···4use diesel_async::RunQueryDsl;
5use diesel_async::pooled_connection::AsyncDieselConnectionManager;
6use diesel_async::pooled_connection::deadpool::Pool;
7+use diesel_async::sync_connection_wrapper::SyncConnectionWrapper;
89#[derive(Clone)]
10pub struct Db {
11+ pub pool: Pool<SyncConnectionWrapper<SqliteConnection>>,
12}
1314impl Db {
···21 } else {
22 std::env::var("DATABASE_URL").expect("DATABASE_URL must be set")
23 };
24+ let config = AsyncDieselConnectionManager::<SyncConnectionWrapper<SqliteConnection>>::new(
25+ database_url,
26+ );
27 let pool = Pool::builder(config)
28 .build()
29 .expect("Failed to create pool");
···39 } else {
40 std::env::var("DATABASE_URL").expect("DATABASE_URL must be set")
41 };
42+ let mut connection = SqliteConnection::establish(&database_url)
43 .unwrap_or_else(|_| panic!("Error connecting to {}", database_url));
44 // This will run the necessary migrations.
45 //
···59 }
60 Ok(())
61}
62+63+pub struct Runtime;