diff --git a/inference-gateway/migrations/20240626175841_fdw.sql b/inference-gateway/migrations/20240626175841_fdw.sql new file mode 100644 index 000000000..482a33d8f --- /dev/null +++ b/inference-gateway/migrations/20240626175841_fdw.sql @@ -0,0 +1,30 @@ +CREATE EXTENSION IF NOT EXISTS postgres_fdw; +CREATE EXTENSION IF NOT EXISTS pg_cron; + +CREATE SERVER IF NOT EXISTS cp_queue_server +FOREIGN DATA WRAPPER postgres_fdw +OPTIONS (host 'localhost', port '5432', dbname 'postgres'); + +CREATE USER MAPPING IF NOT EXISTS FOR postgres +SERVER cp_queue_server +OPTIONS (user 'postgres', password 'postgres'); + +CREATE FOREIGN TABLE IF NOT EXISTS fdw_paid_organizations ( + organization_id text NOT NULL, + has_cc boolean not null default false, + last_updated_at timestamp with time zone not null default now() +) +SERVER cp_queue_server +OPTIONS (schema_name 'billing', table_name 'paid_organizations'); + +SELECT cron.schedule('refresh-validations', '* * * * *', $$ + BEGIN; + TRUNCATE inference.org_validation; + INSERT INTO inference.org_validation + SELECT + organization_id as org_id, + has_cc as valid, + now() as last_updated_at + FROM fdw_paid_organizations; + COMMIT; +$$); diff --git a/inference-gateway/src/main.rs b/inference-gateway/src/main.rs index 91537dee5..82893e61f 100644 --- a/inference-gateway/src/main.rs +++ b/inference-gateway/src/main.rs @@ -5,6 +5,7 @@ use std::time::Duration; #[actix_web::main] async fn main() { env_logger::init(); + let cfg = gateway::config::Config::new().await; let startup_configs = gateway::server::webserver_startup_config(cfg).await; let server_port = startup_configs.cfg.server_port;