I'm having problem with alembic revision. When running alembic revision --autogenerate
, I do receive corrupted schema. Two tables out of 6 are there and there rest is treated as columns. I'm running out of ideas what's wrong.
These are my models:
class SkillBase(SQLModel):
id_skill: Optional[int] = Field(primary_key=True)
family: Family
domain: Domain
provider: str
skill_name: str = Field(unique=True)
skill_type: SkillType
# --- > TABLES
class DateCreation(SQLModel):
date_creation: datetime = Field(
default_factory=datetime.utcnow().date, nullable=False
)
class Offer(ORM, DateCreation, table=True):
__table_args__ = {"extend_existing": True}
id_offer: Optional[int] = Field(primary_key=True)
ext_id_offer: str
link_offer: str
offer_desc: str
class Skill(ORM, SkillBase, DateCreation, table=True):
__table_args__ = {"extend_existing": True}
user_creation: str
date_last_mod: datetime = Field(
default_factory=datetime.utcnow().date, nullable=False
)
people: List["Person_skill"] = Relationship(back_populates="skill")
class Project(ORM, table=True):
__table_args__ = {"extend_existing": True}
id_project: Optional[int] = Field(primary_key=True)
project_name: str
start_date: datetime
end_date: datetime
owner: str
cost_center: str
people: List["Person"] = Relationship(back_populates="project")
class Person(ORM, table=True):
__table_args__ = {"extend_existing": True}
id_person: Optional[int] = Field(primary_key=True)
first_name: str
last_name: str
current_id_project: int = Field(foreign_key="project.id_project")
project: Optional[Project] = Relationship(back_populates="people")
skills: List["Person_skill"] = Relationship(back_populates="person")
class Person_skill(ORM, table=True):
__table_args__ = {"extend_existing": True}
id_person_skill: Optional[int] = Field(primary_key=True)
id_person: int = Field(foreign_key="person.id_person")
person: Optional[Person] = Relationship(back_populates="skills")
id_skill: int = Field(foreign_key="skill.id_skill")
skill: Optional[Skill] = Relationship(back_populates="people")
level_wod: int
yoe: int
certification: int
training: int
score: int
class Offer_skill(ORM, DateCreation, table=True):
__table_args__ = {"extend_existing": True}
id_offer_skill: Optional[int] = Field(primary_key=True)
id_offer: int = Field(foreign_key="offer.id_offer")
id_skill: int = Field(foreign_key="skill.id_skill")
ORM
implements classmethod functions like update, delete etc.
Based on the above when running alembic revision --autogenerate
I receive:
def upgrade() -> None:
# ### commands auto generated by Alembic - please adjust! ###
op.create_table('offer_skill',
sa.Column('date_creation', sa.DateTime(), nullable=False),
sa.Column('id_offer_skill', sa.Integer(), nullable=False),
sa.Column('id_offer', sa.Integer(), nullable=False),
sa.Column('id_skill', sa.Integer(), nullable=False),
sa.ForeignKeyConstraint(['id_offer'], ['offer.id_offer'], ),
sa.ForeignKeyConstraint(['id_skill'], ['skill.id_skill'], ),
sa.PrimaryKeyConstraint('id_offer_skill')
)
op.create_table('person_skill',
sa.Column('id_person_skill', sa.Integer(), nullable=False),
sa.Column('id_person', sa.Integer(), nullable=False),
sa.Column('id_skill', sa.Integer(), nullable=False),
sa.Column('level_wod', sa.Integer(), nullable=False),
sa.Column('yoe', sa.Integer(), nullable=False),
sa.Column('certification', sa.Integer(), nullable=False),
sa.Column('training', sa.Integer(), nullable=False),
sa.Column('score', sa.Integer(), nullable=False),
sa.ForeignKeyConstraint(['id_person'], ['person.id_person'], ),
sa.ForeignKeyConstraint(['id_skill'], ['skill.id_skill'], ),
sa.PrimaryKeyConstraint('id_person_skill')
)
op.drop_table('offerskill')
op.drop_table('personskill')
op.add_column('offer', sa.Column('date_creation', sa.DateTime(), nullable=False))
op.add_column('offer', sa.Column('id_offer', sa.Integer(), nullable=False))
op.add_column('offer', sa.Column('ext_id_offer', sqlmodel.sql.sqltypes.AutoString(), nullable=False))
op.add_column('offer', sa.Column('link_offer', sqlmodel.sql.sqltypes.AutoString(), nullable=False))
op.add_column('offer', sa.Column('offer_desc', sqlmodel.sql.sqltypes.AutoString(), nullable=False))
op.drop_column('offer', 'offer_link')
op.drop_column('offer', 'created')
op.drop_column('offer', 'description')
op.drop_column('offer', 'ext_offer_id')
op.drop_column('offer', 'id')
op.add_column('person', sa.Column('id_person', sa.Integer(), nullable=False))
op.add_column('person', sa.Column('current_id_project', sa.Integer(), nullable=False))
op.drop_constraint('person_first_name_key', 'person', type_='unique')
op.drop_constraint('person_current_project_id_fkey', 'person', type_='foreignkey')
op.create_foreign_key(None, 'person', 'project', ['current_id_project'], ['id_project'])
op.drop_column('person', 'id')
op.drop_column('person', 'created')
op.drop_column('person', 'current_project_id')
op.add_column('project', sa.Column('id_project', sa.Integer(), nullable=False))
op.drop_column('project', 'id')
op.drop_column('project', 'created')
op.add_column('skill', sa.Column('date_creation', sa.DateTime(), nullable=False))
op.add_column('skill', sa.Column('id_skill', sa.Integer(), nullable=False))
op.drop_column('skill', 'id')
op.drop_column('skill', 'created')
# ### end Alembic commands ###
def downgrade() -> None:
# ### commands auto generated by Alembic - please adjust! ###
op.add_column('skill', sa.Column('created', postgresql.TIMESTAMP(), autoincrement=False, nullable=False))
op.add_column('skill', sa.Column('id', sa.INTEGER(), autoincrement=True, nullable=False))
op.drop_column('skill', 'id_skill')
op.drop_column('skill', 'date_creation')
op.add_column('project', sa.Column('created', postgresql.TIMESTAMP(), autoincrement=False, nullable=False))
op.add_column('project', sa.Column('id', sa.INTEGER(), autoincrement=True, nullable=False))
op.drop_column('project', 'id_project')
op.add_column('person', sa.Column('current_project_id', sa.INTEGER(), autoincrement=False, nullable=False))
op.add_column('person', sa.Column('created', postgresql.TIMESTAMP(), autoincrement=False, nullable=False))
op.add_column('person', sa.Column('id', sa.INTEGER(), autoincrement=True, nullable=False))
op.drop_constraint(None, 'person', type_='foreignkey')
op.create_foreign_key('person_current_project_id_fkey', 'person', 'project', ['current_project_id'], ['id'])
op.create_unique_constraint('person_first_name_key', 'person', ['first_name'])
op.drop_column('person', 'current_id_project')
op.drop_column('person', 'id_person')
op.add_column('offer', sa.Column('id', sa.INTEGER(), autoincrement=True, nullable=False))
op.add_column('offer', sa.Column('ext_offer_id', sa.INTEGER(), autoincrement=False, nullable=False))
op.add_column('offer', sa.Column('description', sa.VARCHAR(), autoincrement=False, nullable=False))
op.add_column('offer', sa.Column('created', postgresql.TIMESTAMP(), autoincrement=False, nullable=False))
op.add_column('offer', sa.Column('offer_link', sa.VARCHAR(), autoincrement=False, nullable=False))
op.drop_column('offer', 'offer_desc')
op.drop_column('offer', 'link_offer')
op.drop_column('offer', 'ext_id_offer')
op.drop_column('offer', 'id_offer')
op.drop_column('offer', 'date_creation')
op.create_table('personskill',
sa.Column('id', sa.INTEGER(), autoincrement=True, nullable=False),
sa.Column('created', postgresql.TIMESTAMP(), autoincrement=False, nullable=False),
sa.Column('person_id', sa.INTEGER(), autoincrement=False, nullable=False),
sa.Column('skill_id', sa.INTEGER(), autoincrement=False, nullable=False),
sa.Column('wod_level', postgresql.ENUM('BEGINNER', 'MEDIUM', 'ADVANCED', name='wodlevel'), autoincrement=False, nullable=False),
sa.Column('yoe', sa.INTEGER(), autoincrement=False, nullable=False),
sa.Column('certification', sa.INTEGER(), autoincrement=False, nullable=False),
sa.Column('training', sa.INTEGER(), autoincrement=False, nullable=False),
sa.Column('score', sa.INTEGER(), autoincrement=False, nullable=False),
sa.ForeignKeyConstraint(['person_id'], ['person.id'], name='personskill_person_id_fkey'),
sa.ForeignKeyConstraint(['skill_id'], ['skill.id'], name='personskill_skill_id_fkey'),
sa.PrimaryKeyConstraint('id', name='personskill_pkey')
)
op.create_table('offerskill',
sa.Column('id', sa.INTEGER(), autoincrement=True, nullable=False),
sa.Column('created', postgresql.TIMESTAMP(), autoincrement=False, nullable=False),
sa.Column('offer_id', sa.INTEGER(), autoincrement=False, nullable=False),
sa.Column('skill_id', sa.INTEGER(), autoincrement=False, nullable=False),
sa.ForeignKeyConstraint(['offer_id'], ['offer.id'], name='offerskill_offer_id_fkey'),
sa.ForeignKeyConstraint(['skill_id'], ['skill.id'], name='offerskill_skill_id_fkey'),
sa.PrimaryKeyConstraint('id', name='offerskill_pkey')
)
op.drop_table('person_skill')
op.drop_table('offer_skill')
As you can see it's totally wrong... Appreciate any help.