diff --git a/edbob/scaffolds/edbob/+package+/alembic/env.py_tmpl b/edbob/scaffolds/edbob/+package+/alembic/env.py_tmpl new file mode 100644 index 0000000..cbbcc3a --- /dev/null +++ b/edbob/scaffolds/edbob/+package+/alembic/env.py_tmpl @@ -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() diff --git a/edbob/scaffolds/edbob/+package+/alembic/script.py.mako b/edbob/scaffolds/edbob/+package+/alembic/script.py.mako new file mode 100644 index 0000000..46eb3a1 --- /dev/null +++ b/edbob/scaffolds/edbob/+package+/alembic/script.py.mako @@ -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"} diff --git a/edbob/scaffolds/edbob/+package+/alembic/versions/.dummy b/edbob/scaffolds/edbob/+package+/alembic/versions/.dummy new file mode 100644 index 0000000..e69de29 diff --git a/edbob/scaffolds/edbob/development.ini_tmpl b/edbob/scaffolds/edbob/development.ini_tmpl index 300d5d4..10f4d8f 100644 --- a/edbob/scaffolds/edbob/development.ini_tmpl +++ b/edbob/scaffolds/edbob/development.ini_tmpl @@ -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 #################### diff --git a/edbob/scaffolds/edbob/production.ini_tmpl b/edbob/scaffolds/edbob/production.ini_tmpl index c5bfdbd..ef451e4 100644 --- a/edbob/scaffolds/edbob/production.ini_tmpl +++ b/edbob/scaffolds/edbob/production.ini_tmpl @@ -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 ', + '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 ', - 'managers@example.com', - 'support@example.com', - ] -subject.default = Message from {{project}} - -[edbob.time] -timezone = US/Central - - #################### # logging #################### diff --git a/edbob/scaffolds/edbob/setup.py_tmpl b/edbob/scaffolds/edbob/setup.py_tmpl index 31bcde1..723230a 100644 --- a/edbob/scaffolds/edbob/setup.py_tmpl +++ b/edbob/scaffolds/edbob/setup.py_tmpl @@ -39,6 +39,7 @@ requires = [ # # package # low high + 'alembic', # 0.3.4 'edbob[db,pyramid]', # 0.1a1.dev 'psycopg2', # 2.4.4 ] diff --git a/setup.py b/setup.py index 12c0dcd..6eb94e4 100644 --- a/setup.py +++ b/setup.py @@ -93,7 +93,6 @@ extras = { # # package # low high - # 'alembic', # 0.3.4 'SQLAlchemy', # 0.7.6 # 'Tempita', # 0.5.1 ],