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

Question about multiple schemas in postgres sql db #20

Open
AlaaZenji opened this issue Jun 24, 2024 · 1 comment
Open

Question about multiple schemas in postgres sql db #20

AlaaZenji opened this issue Jun 24, 2024 · 1 comment

Comments

@AlaaZenji
Copy link

When having multiple schemas in the same db, brick will add the name of the schema to the model's name in this format <schema_name>::<table_name>. Is there a way to bypass that and generate table names without those schema names before them?

@AlaaZenji AlaaZenji changed the title Question about multiple schemas in same db Question about multiple schemas in postgres sql db Jun 24, 2024
@lorint
Copy link
Owner

lorint commented Jul 1, 2024

Heya Alaa --

Been looking into this one pretty closely to see what is possible that would also be reliable and maintainable. It can get tricky if you try to blanketly disregard schemas in Postgres. So to keep things consistent, I see a couple approaches -- either set the Postgres search_path to include all your desired schemas, or to pick one "main" one and have Brick not put models for that schema into their own module. I think the latter offers the most consistency.

One reason schemas exist is to avoid naming conflicts that could arise when migrating a set of table structure from somewhere else into an existing database. If there happens to be table name clashes then it's no big deal when the new stuff is placed into its own different schema. Quite similar to the way that modules namespace things in Ruby, schemas end up namespacing things in Postres. So it makes good sense to have these align.

A new feature I'll add to Brick is the ability to set a default schema, like this:

Brick.default_schema = 'sales'

Then all tables in that sales schema will not end up creating models inside a module. And tables from other schemas will still have their models namespaced under modules. Probably one more day or so of testing this thing, and it will be released.

Thanks for reaching out!

-Lorin

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants