sqlalchemy / sqlalchemy/alembic
support PG INHERITS in autogenerate
Open
Nobody has claimed this yet.
autogenerate - detection
feature
low priority
- Dominant language
- Python
- Stars
- 4.4k
- Forks
- 375
- PR merge metrics
- No merged PRs in 30d
Description
Migrated issue, originally created by Quentin Leffray
Running Alembic autogenerate do not detect inherited columns from a parent table, and flag them as "to-be-dropped".
The model is defined as follow:
class Animal(Base):
__tablename__ = 'animal'
id = Column(Integer, primary_key=True)
name = Column(String)
type_ = Column(String)
__mapper_args__ = {
'polymorphic_identity': 'animal',
'polymorphic_on': type_,
'with_polymorphic': '*',
}
class Unicorn(Animal):
__tablename__ = 'unicorn'
__table_args__ = {'postgresql_inherits': 'animal'}
id = Column(Integer, ForeignKey('animal.id'), primary_key=True)
color = Column(String)
__mapper_args__ = {
'polymorphic_identity': 'unicorn',
}
And the migration produced by alembic --autogenerate:
def upgrade():
### commands auto generated by Alembic - please adjust! ###
op.drop_column('unicorn', 'name')
op.drop_column('unicorn', 'type_')
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the issue with the Animal and Unicorn models shown in the report and run Alembic autogenerate against PostgreSQL. Trace the autogenerate comparison that produces the drop_column operations; done means inherited name and type_ columns are not flagged for removal.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- postgresql, python, sqlalchemy
- Domain
- databases
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100