add alembic to scaffold

This commit is contained in:
Lance Edgar 2012-08-14 13:28:03 -07:00
parent cdfb81c54c
commit 005fca223f
7 changed files with 156 additions and 54 deletions

View file

@ -0,0 +1,78 @@
#!/usr/bin/env python
"""
``{{package}}.alembic.env`` -- Alembic Environment Script
"""
from __future__ import with_statement
from alembic import context
import edbob
import edbob.db
# this is the Alembic Config object, which provides
# access to the values within the .ini file in use.
config = context.config
# Initialize edbob with whichever config file alembic is using.
edbob.init('{{package}}', config.config_file_name)
# add your model's MetaData object here
# for 'autogenerate' support
target_metadata = edbob.db.Base.metadata
# other values from the config, defined by the needs of env.py,
# can be acquired:
# my_important_option = config.get_main_option("my_important_option")
# ... etc.
def run_migrations_offline():
"""Run migrations in 'offline' mode.
This configures the context with just a URL
and not an Engine, though an Engine is acceptable
here as well. By skipping the Engine creation
we don't even need a DBAPI to be available.
Calls to context.execute() here emit the given string to the
script output.
"""
url = edbob.config.require('edbob.db', 'sqlalchemy.url')
context.configure(url=url)
with context.begin_transaction():
context.run_migrations()
def run_migrations_online():
"""Run migrations in 'online' mode.
In this scenario we need to create an Engine
and associate a connection with the context.
"""
engine = edbob.db.engine
connection = engine.connect()
context.configure(
connection=connection,
target_metadata=target_metadata
)
try:
with context.begin_transaction():
context.run_migrations()
finally:
connection.close()
if context.is_offline_mode():
run_migrations_offline()
else:
run_migrations_online()

View file

@ -0,0 +1,31 @@
"""${message}
Revision ID: ${up_revision}
Revises: ${down_revision}
Create Date: ${create_date}
"""
# revision identifiers, used by Alembic.
revision = ${repr(up_revision)}
down_revision = ${repr(down_revision)}
from alembic import op
import sqlalchemy as sa
${imports if imports else ""}
metadata = sa.MetaData()
active_extensions = sa.Table(
'active_extensions', metadata,
sa.Column('name', sa.String(50)),
)
def upgrade():
${upgrades if upgrades else "pass"}
def downgrade():
${downgrades if downgrades else "pass"}

View file

@ -19,6 +19,14 @@
whatever = you like
####################
# edbob
####################
[edbob]
include_config = [r'%(here)s/production.ini']
####################
# Pyramid
####################
@ -29,8 +37,7 @@ use = egg:{{package}}
pyramid.reload_templates = true
pyramid.debug_all = true
pyramid.default_locale_name = en
pyramid.includes =
pyramid_debugtoolbar
pyramid.includes = pyramid_debugtoolbar
# Hack so edbob can find this file from within WSGI app.
edbob.config = %(here)s/development.ini
@ -41,14 +48,6 @@ host = 0.0.0.0
port = 6543
####################
# edbob
####################
[edbob]
include_config = ['%(here)s/production.ini']
####################
# logging
####################

View file

@ -13,6 +13,43 @@
whatever = you like
####################
# edbob
####################
[edbob]
init = edbob.time, edbob.errors, edbob.db
basic_logging = True
configure_logging = True
# shell.python = ipython
[edbob.db]
sqlalchemy.url = postgresql://user:pass@localhost/{{package}}
[edbob.mail]
smtp.server = localhost
# smtp.username = user
# smtp.password = pass
sender.default = {{package}}@example.com
subject.default = Message from {{project}}
recipients.default = [
'Joe Blow <owner@example.com>',
'managers@example.com',
'support@example.com',
]
[edbob.time]
zone.local = America/Chicago
####################
# alembic
####################
[alembic]
script_location = {{package}}:alembic
####################
# pyramid
####################
@ -33,49 +70,6 @@ host = 0.0.0.0
port = 6543
####################
# alembic
####################
[alembic]
# path to migration scripts
script_location = schema
# template used to generate migration files
# file_template = %%(rev)s_%%(slug)s
sqlalchemy.url = postgresql://user:pass@localhost/{{package}}
####################
# edbob
####################
[edbob]
init = edbob.time, edbob.db
basic_logging = True
configure_logging = True
# shell.python = ipython
[edbob.db]
sqlalchemy.url = postgresql://user:pass@localhost/{{package}}
[edbob.mail]
smtp.server = localhost
# smtp.username = user
# smtp.password = pass
sender.default = {{package}}@example.com
recipients.default = [
'Joe Blow <owner@example.com>',
'managers@example.com',
'support@example.com',
]
subject.default = Message from {{project}}
[edbob.time]
timezone = US/Central
####################
# logging
####################

View file

@ -39,6 +39,7 @@ requires = [
#
# package # low high
'alembic', # 0.3.4
'edbob[db,pyramid]', # 0.1a1.dev
'psycopg2', # 2.4.4
]

View file

@ -93,7 +93,6 @@ extras = {
#
# package # low high
# 'alembic', # 0.3.4
'SQLAlchemy', # 0.7.6
# 'Tempita', # 0.5.1
],