omymodels icon indicating copy to clipboard operation
omymodels copied to clipboard

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

Open leppikallio opened this issue 3 years ago • 4 comments

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.

leppikallio avatar Nov 09 '22 10:11 leppikallio

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

xnuinside avatar Nov 09 '22 20:11 xnuinside

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.

leppikallio avatar Nov 09 '22 21:11 leppikallio

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

peterdudfield avatar Jan 06 '23 14:01 peterdudfield

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

xnuinside avatar Jan 07 '23 13:01 xnuinside