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

Option to have different schemas in separate files, with separate Base #40

Open
leppikallio opened this issue Nov 9, 2022 · 4 comments

Comments

@leppikallio
Copy link
Contributor

leppikallio commented Nov 9, 2022

It would be really nice and helpful if it were possible to have SQLAlchemy model "split" in to separate, schema specific, files with a schema specific Base.

As an example, if a DDL had something like

CREATE SCHEMA schema1;
CREATE SCHEMA schema2;
CREATE TABLE schema1.table1 (
...
);
CREATE TABLE schema2.table2 (
...
);

the -m sqlalchemy in combination with a new option would produce two model files,

schema1.py
schema2.py

with

import sqlalchemy as sa
from sqlalchemy.ext.declarative import declarative_base

Schema1Base = declarative_base()
class Table1(Schema1Base):

    __tablename__ = "table1"
    __table_args__ = {"schema": "schema1"}

and

import sqlalchemy as sa
from sqlalchemy.ext.declarative import declarative_base

Schema2Base = declarative_base()
class Table2(Schema2Base):

    __tablename__ = "table2"
    __table_args__ = {"schema": "schema2"}

respectively. This would be amazingly helpful & useful feature as it would make it possible to really separate the schemas.

@xnuinside
Copy link
Owner

@leppikallio hi! thanks for reporting the issue. I can implement it on weekend

@leppikallio
Copy link
Contributor Author

To be clear, this is not that much an issue, rather an extension to already brilliant tool. But it would be amazing if this would be possible.

@peterdudfield
Copy link
Contributor

Did this get done? I'm happy to try and give it a go if you want

@xnuinside
Copy link
Owner

@peterdudfield nope, I didn't start work on it, you can take care about it, if you want

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

3 participants