On Sun, Apr 8, 2012 at 9:53 PM, Michael Bayer <[email protected]>wrote:
>
> On Apr 7, 2012, at 8:50 PM, limodou wrote:
>
> I've tested today, and I felt very good. And I have a question, if I've
> autogenerated once, and havn't upgrade to the database, so if I rerun the
> autogenerate again, it'll say:
>
> Target database is not up to date.
>
> So I want to know if there is an option so that it can delete the revision
> which havenot upgrade to database(maybe I can set the revision number), and
> recreate new rivision, for now, I can delete last revision by hand, and run
> the autogenerate again it'll be ok.
>
>
>
> yeah I've been deleting it by hand. I guess a command "prune" or
> something like that ? I'd make it prompt you before deleting the files
> though. I'm not sure if i want to be in the business of erasing people's
> source code.
>
>
>
> And I want to know how to let alembic know other python web framework
> configuration when init. Or how to customize alembic init process?
>
>
> So the two integration paths are a. how to have the Alembic scripts know
> about your web framework when they run and b. how to have your web
> framework know about alembic when it runs.
>
> For a. we have the env.py script. I do this a lot now in env.py:
>
> from myapplication.model import Session
>
> # ...
>
> def run_migrations_online():
> s = Session()
> if s.bind is not None:
> engine = s.bind
> else:
> engine = engine_from_config(...)
>
>
> so above, if I'm running Alembic from inside a script that has already
> loaded up my web framework (like in tests), Alembic uses the same engine
> that the web framework has already set up.
>
> for b. that was part of the focus for 0.3, to get more public API for
> alembic. I have an init() like this:
>
>
> def init_alembic(check_only):
> from alembic.config import Config
> from alembic.script import ScriptDirectory
> from alembic.migration import MigrationContext
> from alembic import command
>
> config = Config()
> config.set_main_option("script_location", "myapp:migrations")
>
> if check_only:
> # check that the DB is up to date only
> script = ScriptDirectory.from_config(config)
> conn = DBSession().connection()
> ctx = MigrationContext.configure(conn)
> head = script.get_current_head()
> db_head = ctx.get_current_revision()
> if db_head != head:
> raise Exception("Current migration version %s "
> "does not match %s" % (db_head, head))
> else:
> # upgrade to head
> command.upgrade(config, "head")
>
>
> so unit test fixtures that want to have a whole database available on a
> test node will run init_alembic() with False, the main app runner runs
> init_alembic() with True, so that the production app isn't trying to
> upgrade the database.
>
>
>
>
Thank you very much. I'll test it more.
--
I like python!
UliPad <<The Python Editor>>: http://code.google.com/p/ulipad/
UliWeb <<simple web framework>>: http://code.google.com/p/uliweb/
My Blog: http://hi.baidu.com/limodou
--
You received this message because you are subscribed to the Google Groups
"sqlalchemy" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/sqlalchemy?hl=en.