0

Let's say my schemas.py looks like these:

class EimBase(SQLModel):
    fimno: Optional[str]
    spv_component_id: Optional[int] 
    eim_technology_name: Optional[str]
    eim_technology_version: Optional[str]
    obsolete_start_date: Optional[date]
    actual_remediation_date: Optional[date]
    intended_remediation_date: Optional[date]
    issuestatus: Optional[str]
    current_manu_phase: Optional[str]
    current_manu_phase_start: Optional[date]
    current_manu_phase_end: Optional[date]
    remediation_type: Optional[str]
    issue_component_id: Optional[str]
    middleware_instance_name: Optional[str]

class Eim(EimBase,table=True):
    id: Optional[int] = Field(default=None,primary_key=True)
    spv_component_id: Optional[int] = Field(default=None,index=True)

When the database creates the table it will create like that in Postgres:

CREATE TABLE stage_eim (
        fimno VARCHAR,
        spv_component_id INTEGER,
        eim_technology_name VARCHAR,
        eim_technology_version VARCHAR,
        obsolete_start_date DATE,
        actual_remediation_date DATE,
        intended_remediation_date DATE,
        issuestatus VARCHAR,
        current_manu_phase VARCHAR,
        current_manu_phase_start DATE,
        current_manu_phase_end DATE,
        remediation_type VARCHAR,
        issue_component_id VARCHAR,
        middleware_instance_name VARCHAR,
        id SERIAL NOT NULL,
        PRIMARY KEY (id)
)

As you can see the id has the last position. I want the id to be the first position:

CREATE TABLE stage_eim (
            id SERIAL NOT NULL,
....
)

How can I achieve that while keeping my schemas with the same structure ? If I define Eim on top of EimBase it will complain about spv_component_id

moth
  • 1,833
  • 12
  • 29
  • A bit of a hack, but how about having a mixin-class named `HasId` that has the single id field, then `class Eim(HasId, EimBase, table=True):`? – MatsLindh Feb 20 '23 at 12:38
  • yep, that's hacky, no other way ? usually an id should have first positional ordering – moth Feb 20 '23 at 13:28
  • Why does it matter, in what order the columns are defined? Column order has no semantic meaning in database tables aside from a few edge cases. – Daniil Fajnberg Feb 20 '23 at 22:23

0 Answers0