Scalable and distributed custom feed generator, ott - on that topic

Add db setup

+106 -3
+24 -2
crates/Cargo.lock
··· 1760 1760 "tokio", 1761 1761 "tokio-rustls", 1762 1762 "tower-service", 1763 - "webpki-roots", 1763 + "webpki-roots 1.0.2", 1764 1764 ] 1765 1765 1766 1766 [[package]] ··· 2484 2484 version = "0.2.0" 2485 2485 source = "registry+https://github.com/rust-lang/crates.io-index" 2486 2486 checksum = "04744f49eae99ab78e0d5c0b603ab218f515ea8cfe5a456d7629ad883a3b6e7d" 2487 + 2488 + [[package]] 2489 + name = "ott-db-migration" 2490 + version = "0.1.0" 2491 + dependencies = [ 2492 + "anyhow", 2493 + "sqlx", 2494 + "tokio", 2495 + "tracing", 2496 + "tracing-subscriber", 2497 + ] 2487 2498 2488 2499 [[package]] 2489 2500 name = "ott-embed" ··· 3051 3062 "wasm-bindgen", 3052 3063 "wasm-bindgen-futures", 3053 3064 "web-sys", 3054 - "webpki-roots", 3065 + "webpki-roots 1.0.2", 3055 3066 ] 3056 3067 3057 3068 [[package]] ··· 3605 3616 "native-tls", 3606 3617 "once_cell", 3607 3618 "percent-encoding", 3619 + "rustls", 3608 3620 "serde", 3609 3621 "serde_json", 3610 3622 "sha2", ··· 3614 3626 "tokio-stream", 3615 3627 "tracing", 3616 3628 "url", 3629 + "webpki-roots 0.26.11", 3617 3630 ] 3618 3631 3619 3632 [[package]] ··· 4428 4441 dependencies = [ 4429 4442 "js-sys", 4430 4443 "wasm-bindgen", 4444 + ] 4445 + 4446 + [[package]] 4447 + name = "webpki-roots" 4448 + version = "0.26.11" 4449 + source = "registry+https://github.com/rust-lang/crates.io-index" 4450 + checksum = "521bc38abb08001b01866da9f51eb7c5d647a19260e00054a8c7fd5f9e57f7a9" 4451 + dependencies = [ 4452 + "webpki-roots 1.0.2", 4431 4453 ] 4432 4454 4433 4455 [[package]]
+1 -1
crates/Cargo.toml
··· 1 1 [workspace] 2 2 resolver = "3" 3 - members = ["ott-types", "ott-filter", "ott-embed", "ott-xrpc"] 3 + members = ["ott-types", "ott-filter", "ott-embed", "ott-xrpc", "ott-db-migration"]
+11
crates/ott-db-migration/Cargo.toml
··· 1 + [package] 2 + name = "ott-db-migration" 3 + version = "0.1.0" 4 + edition = "2024" 5 + 6 + [dependencies] 7 + anyhow = "1.0.100" 8 + sqlx = { version = "0.8.6", features = ["runtime-tokio-rustls", "postgres", "migrate"] } 9 + tokio = { version = "1.47.1", features = ["full"] } 10 + tracing = "0.1.41" 11 + tracing-subscriber = { version = "0.3.20", features = ["env-filter"] }
+1
crates/ott-db-migration/README.md
··· 1 + Small bin to make sure the db schema is up to date
+3
crates/ott-db-migration/build.rs
··· 1 + fn main() { 2 + println!("cargo:rerun-if-changed=migrations"); 3 + }
+5
crates/ott-db-migration/migrations/001_enble_extensions.sql
··· 1 + -- Enable required extensions 2 + 3 + CREATE EXTENSION IF NOT EXISTS pg_partman; 4 + CREATE EXTENSION IF NOT EXISTS vector; 5 + CREATE EXTENSION IF NOT EXISTS pg_cron;
+9
crates/ott-db-migration/migrations/002_create_partionened_table.sql
··· 1 + -- Create the partitioned table 2 + 3 + CREATE TABLE vectors ( 4 + id BIGSERIAL, 5 + uri VARCHAR NOT NULL, 6 + vector vector, 7 + created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(), 8 + PRIMARY KEY (id, created_at) 9 + ) PARTITION BY RANGE (created_at);
+19
crates/ott-db-migration/migrations/003_configure_pgpartman.sql
··· 1 + -- Configure pg_partman for the table 2 + 3 + -- Configure pg_partman for the table 4 + SELECT create_parent( 5 + p_parent_table => 'public.vectors', 6 + p_control => 'created_at', 7 + p_interval => '30 minutes', 8 + p_type => 'range', 9 + p_premake => 8 10 + ); 11 + 12 + -- Configure retention policy 13 + UPDATE part_config 14 + SET 15 + retention_keep_table = false, 16 + retention = '2 hours', 17 + infinite_time_partitions = true, 18 + automatic_maintenance = 'on' 19 + WHERE parent_table = 'public.vectors';
+4
crates/ott-db-migration/migrations/004_setup_cron.sql
··· 1 + -- setup cron for running pgpartman maintenance 2 + 3 + SELECT cron.schedule('pgpartman-maintenance', '*/5 * * * *', 4 + 'CALL run_maintenance_proc()');
+25
crates/ott-db-migration/src/main.rs
··· 1 + use anyhow::Result; 2 + use sqlx::postgres::PgPoolOptions; 3 + use tracing::info; 4 + use tracing_subscriber::EnvFilter; 5 + 6 + #[tokio::main] 7 + async fn main() -> Result<()> { 8 + tracing_subscriber::fmt() 9 + .with_ansi(true) // Colors enabled (default) 10 + .with_env_filter(EnvFilter::from_default_env()) 11 + .init(); 12 + 13 + let database_url = std::env::var("DATABASE_URL").expect("DATABASE_URL must be set"); 14 + 15 + let pool = PgPoolOptions::new() 16 + .max_connections(5) 17 + .connect(&database_url) 18 + .await?; 19 + 20 + info!("Starting db migration"); 21 + sqlx::migrate!("./migrations").run(&pool).await?; 22 + 23 + info!("Migrations completed successfully!"); 24 + Ok(()) 25 + }
+4
helm/ott/templates/pg_cluster.yaml
··· 7 7 imageName: {{ .Values.postgresql.imageName }} 8 8 storage: 9 9 size: 10Gi 10 + enableSuperuserAccess: true 11 + postgresql: 12 + shared_preload_libraries: 13 + - pg_cron