ergo / ziggurat_foundations

Framework agnostic set of sqlalchemy classes that make building applications that require permissions an easy task.
BSD 3-Clause "New" or "Revised" License
71 stars 22 forks source link

ExternalIdentityMixin missing mysql_engine #28

Closed TheMightyOnyx closed 8 years ago

TheMightyOnyx commented 8 years ago

ExternalIdentityMixin doesn't have table_args declaring the mysql_engine like the other models do and as such SQLAlchemy create_all() fails with the error "Cannot add foreign key constraint". Adding the line in the overridden class for ziggurat_model_init fixed it for me.

ergo commented 8 years ago

I will pull this in, but as per docs you are NOT supposed to create those models with create_all() - use alembic migrations as it will be almost certain things will be subtly incorrect.

I'm not maintaining unique indices and other things on sqlalchemy model level, all the database schema entities are managed via alembic. At best you will get locked on this specific version of zigg and I would live to save you lots of pain further down the road :)

ergo commented 8 years ago

It is possible to mix alembic with create_all() if you need this functionality,

    alembic_cfg = Config()
    alembic_cfg.set_main_option("script_location", "ziggurat_foundations:migrations")
    alembic_cfg.set_main_option("sqlalchemy.url", settings["sqlalchemy.url"])
    command.upgrade(alembic_cfg, "head")

You can have this in database initializing script and then let create_all do your own thing or ideally maintain your own set of migrations for your application to avoid any future conflicts that may arise.

TheMightyOnyx commented 8 years ago

I see, thanks for the tips. I'll look into using Alembic.