mara / mara-app

A framework for distributing flask apps across separate packages with minimal dependencies
MIT License
15 stars 4 forks source link

migrations does not work #6

Closed ghost closed 6 years ago

ghost commented 7 years ago

This is probably a result of me using declared tables for stuff which I don't want to have migrated on updates.

update-packages: 2017-04-20T18:07:53 INFO, alembic.runtime.migration: Will assume transactional DDL.
update-packages: Traceback (most recent call last):
update-packages:   File ".venv/bin/flask", line 11, in <module>
update-packages:     sys.exit(main())
update-packages:   File "/home/js/projects/pricing/.venv/lib/python3.6/site-packages/flask/cli.py", line 513, in main
update-packages:     cli.main(args=args, prog_name=name)
update-packages:   File "/home/js/projects/pricing/.venv/lib/python3.6/site-packages/flask/cli.py", line 380, in main
update-packages:     return AppGroup.main(self, *args, **kwargs)
update-packages:   File "/home/js/projects/pricing/.venv/lib/python3.6/site-packages/click/core.py", line 697, in main
update-packages:     rv = self.invoke(ctx)
update-packages:   File "/home/js/projects/pricing/.venv/lib/python3.6/site-packages/click/core.py", line 1066, in invoke
update-packages:     return _process_result(sub_ctx.command.invoke(sub_ctx))
update-packages:   File "/home/js/projects/pricing/.venv/lib/python3.6/site-packages/click/core.py", line 895, in invoke
update-packages:     return ctx.invoke(self.callback, **ctx.params)
update-packages:   File "/home/js/projects/pricing/.venv/lib/python3.6/site-packages/click/core.py", line 535, in invoke
update-packages:     return callback(*args, **kwargs)
update-packages:   File "/home/js/projects/pricing/packages/mara-app/mara_app/cli.py", line 12, in migrate
update-packages:     migrations.auto_migrate(dbs.engine(mara_db.config.mara_db_alias()))
update-packages:   File "/home/js/projects/pricing/packages/mara-app/mara_app/migrations.py", line 65, in auto_migrate
update-packages:     ddl = get_migration_ddl(engine)
update-packages:   File "/home/js/projects/pricing/packages/mara-app/mara_app/migrations.py", line 46, in get_migration_ddl
update-packages:     operations = alembic.autogenerate.produce_migrations(diff_context, combined_meta_data).upgrade_ops.ops
update-packages:   File "/home/js/projects/pricing/.venv/lib/python3.6/site-packages/alembic/autogenerate/api.py", line 132, in produce_migrations
update-packages:     compare._populate_migration_script(autogen_context, migration_script)
update-packages:   File "/home/js/projects/pricing/.venv/lib/python3.6/site-packages/alembic/autogenerate/compare.py", line 22, in _populate_migration_script
update-packages:     _produce_net_changes(autogen_context, upgrade_ops)
update-packages:   File "/home/js/projects/pricing/.venv/lib/python3.6/site-packages/alembic/autogenerate/compare.py", line 48, in _produce_net_changes
update-packages:     autogen_context, upgrade_ops, schemas
update-packages:   File "/home/js/projects/pricing/.venv/lib/python3.6/site-packages/alembic/util/langhelpers.py", line 314, in go
update-packages:     fn(*arg, **kw)
update-packages:   File "/home/js/projects/pricing/.venv/lib/python3.6/site-packages/alembic/autogenerate/compare.py", line 75, in _autogen_for_tables
update-packages:     inspector, upgrade_ops, autogen_context)
update-packages:   File "/home/js/projects/pricing/.venv/lib/python3.6/site-packages/alembic/autogenerate/compare.py", line 104, in _compare_tables
update-packages:     metadata_table_names)
update-packages:   File "/home/js/projects/pricing/.venv/lib/python3.6/site-packages/alembic/autogenerate/compare.py", line 102, in <genexpr>
update-packages:     for no_dflt_schema, (schema, tname) in zip(
update-packages: KeyError: 'pricing.product'
update-packages: 1 seconds
Makefile:38: recipe for target 'update-packages' failed
make: *** [update-packages] Error 1

In this case, pricing.product is defined as

class Product(Base):
    __table__ = Table('product', Base.metadata,
                      Column('product_number', Text, primary_key=True),
                      autoload=True, autoload_with=pricing_engine, schema='pricing')
    prices = relationship("Price", back_populates="product")
jacopofar commented 7 years ago

@jan-schulz-k24 is this issue still open ?

jankatins commented 7 years ago

Yes, but it probably gets resolved by adding a MARA_MODELS=[model1, model2,...] way to specify models instead of getting them from gc.

martin-loetzsch commented 6 years ago

Solved with the introduction of the MARA_AUTOMIGRATE_SQLALCHEMY_MODELS concept