Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for overriding pg schema #396

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/build_and_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ jobs:
POSTGRES_PASSWORD: testing
POSTGRES_DB: envio-dev
POSTGRES_USER: postgres
POSTGRES_SCHEMA: public
# Set health checks to wait until postgres has started
options: >-
--health-cmd pg_isready
Expand Down
1 change: 1 addition & 0 deletions codegenerator/cli/npm/envio/src/bindings/Postgres.res
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ type poolConfig = {
database?: string, // Name of database to connect to (default: '')
username?: string, // Username of database user (default: '')
password?: string, // Password of database user (default: '')
schema?: string, // Name of schema to connect to (default: 'public')
ssl?: sslOptions, // true, prefer, require, tls.connect options (default: false)
max?: int, // Max number of connections (default: 10)
maxLifetime?: option<int>, // Max lifetime in seconds (more info below) (default: null)
Expand Down
5 changes: 3 additions & 2 deletions codegenerator/cli/src/persisted_state/db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@ async fn get_pg_pool() -> Result<PgPool, sqlx::Error> {
let user = get_env_with_default("ENVIO_PG_USER", "postgres");
let password = get_env_with_default("ENVIO_POSTGRES_PASSWORD", "testing");
let database = get_env_with_default("ENVIO_PG_DATABASE", "envio-dev");
let schema = get_env_with_default("ENVIO_PG_SCHEMA", "public");

let connection_url = format!("postgres://{user}:{password}@{host}:{port}/{database}");
let connection_url = format!("postgres://{user}:{password}@{host}:{port}/{database}?currentSchema={schema}");

PgPoolOptions::new().connect(&connection_url).await
}
Expand All @@ -27,7 +28,7 @@ impl PersistedState {
async fn upsert_to_db_with_pool(&self, pool: &PgPool) -> Result<PgQueryResult, sqlx::Error> {
sqlx::query(
r#"
INSERT INTO public.persisted_state (
INSERT INTO persisted_state (
id,
envio_version,
config_hash,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ services:
POSTGRES_PASSWORD: ${ENVIO_POSTGRES_PASSWORD:-testing}
POSTGRES_USER: ${ENVIO_PG_USER:-postgres}
POSTGRES_DB: ${ENVIO_PG_DATABASE:-envio-dev}
POSTGRES_SCHEMA: ${ENVIO_PG_SCHEMA:-public}
networks:
- my-proxy-net
graphql-engine:
Expand Down
1 change: 1 addition & 0 deletions codegenerator/cli/templates/static/codegen/src/Env.res
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ module Db = {
let user = envSafe->EnvSafe.get("ENVIO_PG_USER", S.string, ~devFallback="postgres")
let password = envSafe->EnvSafe.get("ENVIO_POSTGRES_PASSWORD", S.string, ~devFallback="testing")
let database = envSafe->EnvSafe.get("ENVIO_PG_DATABASE", S.string, ~devFallback="envio-dev")
let schema = envSafe->EnvSafe.get("ENVIO_PG_SCHEMA", S.string, ~devFallback="public")
pavlovdog marked this conversation as resolved.
Show resolved Hide resolved
let ssl = envSafe->EnvSafe.get(
"ENVIO_PG_SSL_MODE",
Postgres.sslOptionsSchema,
Expand Down
1 change: 1 addition & 0 deletions codegenerator/cli/templates/static/codegen/src/db/Db.res
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ let config: Postgres.poolConfig = {
username: Env.Db.user,
password: Env.Db.password,
database: Env.Db.database,
schema: Env.Db.schema,
ssl: Env.Db.ssl,
// TODO: think how we want to pipe these logs to pino.
onnotice: ?(Env.userLogLevel == #warn || Env.userLogLevel == #error ? None : Some(_str => ())),
Expand Down