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 Schema to postgres connections #737

Closed
1 task
josephmancuso opened this issue Jun 25, 2022 · 2 comments · Fixed by #745
Closed
1 task

Add Schema to postgres connections #737

josephmancuso opened this issue Jun 25, 2022 · 2 comments · Fixed by #745
Labels
enhancement A feature that exists, works as intended but needs to be improved

Comments

@josephmancuso
Copy link
Member

Describe the feature as you'd like to see it
Should be able to specify a schema at the connection level (which would then be able to be modified on the fly)

What do we currently have to do now?
We actually cannot specify the schema at all. It will always default to the default schema

Additional context
In the future this will need to be changed via a middleware so schemas can change based on he hostname or something

  • Is this a breaking change? - no should not be
@josephmancuso josephmancuso added the enhancement A feature that exists, works as intended but needs to be improved label Jun 25, 2022
@josephmancuso
Copy link
Member Author

josephmancuso commented Jul 3, 2022

A few different use cases for this:

  • 1. Changing the schema on the fly. Will need to be done using a set_schema on the model / query builder
User.set_schema("schema2").get()
  • 2. Changing the schema to use a single schema in the config:
"postgres": {
        "driver": "postgres",
        "host": os.getenv("POSTGRES_DATABASE_HOST"),
        "..",
        "schema": "schema2",
    },
  • 3. On the migrations it need to be able to set a schema to migrate to a specific schema
  • Be able to set the search path during a request on the middleware

@josephmancuso
Copy link
Member Author

  1. would need a middleware to switch the schema for each subdomain request
  2. would need a table on the public schema that would store all the tenants
  3. would need a custom migration command to fetch all tenants in the tenant table and run the migrations for each schema

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement A feature that exists, works as intended but needs to be improved
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant