Pyramid + SQLAchemy + Alembic

575 views
Skip to first unread message

Mário Idival

unread,
Jul 6, 2015, 10:40:43 PM7/6/15
to pylons-...@googlegroups.com
Does anyone have any concrete example of how to work perfectly Pyramid+ SqAlchemy Alembic?

Vincent Catalano

unread,
Jul 6, 2015, 11:39:19 PM7/6/15
to pylons-...@googlegroups.com
I found that there is a little bit of awkwardness using Alembic with Pyramid + Sqlalchemy, but overall, I works great for me. Here are a two things that I do:

  1. Keep the Alembic settings in the same file as your environment settings (.ini file), that way you have all your site settings per environment in the same file. Something like this:

    [app:main]
    ...
    sqlalchemy.url = postgresql+psycopg2://your-connection-string
    ...

    [alembic]
    script_location = db_scripts
    sqlalchemy.url = postgresql+psycopg2://your-connection-string
    ...

    You could probably configure Pyramid to just use the Alembic section, but that's shouldn't be too difficult.

    When running the Alembic command, you can specify the .ini file you want to use:

    alembic -c production.ini upgrade head

  2. In your Alembic folder's env.py file, make sure you import any models that you want Alembic to use (assuming you are using the autogenerate functionality). This is something I always forget.

Other than these two things, I found that the Sqlalchemy + Pyramid and Alembic documentation are quite good for showing how to get things started. Hopefully this helps and puts you on the right track.

-Vincent

On Mon, Jul 6, 2015 at 7:40 PM, Mário Idival <mario...@gmail.com> wrote:
Does anyone have any concrete example of how to work perfectly Pyramid+ SqAlchemy Alembic?

--
You received this message because you are subscribed to the Google Groups "pylons-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pylons-discus...@googlegroups.com.
To post to this group, send email to pylons-...@googlegroups.com.
Visit this group at http://groups.google.com/group/pylons-discuss.
For more options, visit https://groups.google.com/d/optout.



--
Vincent Catalano
Software Engineer and Web Developer,
(520).603.8944

tonthon

unread,
Jul 7, 2015, 9:12:44 AM7/7/15
to Pylons discuss

2015-07-07 4:40 GMT+02:00 Mário Idival <mario...@gmail.com>:
Does anyone have any concrete example of how to work perfectly Pyramid+ SqAlchemy Alembic?

--

Mário Idival

unread,
Jul 20, 2015, 4:48:06 PM7/20/15
to pylons-...@googlegroups.com
autogenerate not work as expected.

I started a project using the scaffold `alchemy` where` Base` class that is used as `declarative_base` is within the` models.py` file. My problem is this: `--autogenerate` to work properly, I have to keep my models in the` models.py` file, if I separate them, it's like the alembic or sqlalchemy did not find them, or it does not. Someone had any problem with this?

ps: already I put my `` Base.metadata` in env.py`.

Rebelo

unread,
Jul 20, 2015, 5:12:47 PM7/20/15
to pylons-...@googlegroups.com

You need to import your models in env.py for autogenerate to work.

If you have module (folder) models which conatins:
models
|- __init__.py
|- user.py
|- security.py

in env.py you must do:
from models import user, security

Mário Idival

unread,
Jul 20, 2015, 5:41:13 PM7/20/15
to pylons-...@googlegroups.com
Wow, Thank you Rabelo!

Mário Idival
Python Developer

Twitter|Github|Skype : marioidival
Facebookmario.idival
User Linux : #554446

--
Reply all
Reply to author
Forward
0 new messages