Commits

Daniel Holth committed 40207cd

add stucco_evolution paster template

  • Participants
  • Parent commits ba286f2

Comments (0)

Files changed (9)

 *.so
 *.log
 *.egg-info/*
+*.rej
 dist/*
+0.34
+----
+- add `paster create -t stucco_evolution mypackage` to create an evolution
+  module in `mypackage/evolve/...`
+
 0.33
 ----
 - Backwards-incompatible change. A SQLAlchemy connection is now required
 	    import mypackage.models
 	    mypackage.models.Base.metadata.create_all(connection)
 
+(If you have Paste Script installed you can type `paster create
+-t stucco_evolution [mypackage]` to create an evolution module in
+[mypackage]/evolve. Since Paste Script's package name substitution is
+not perfect, check mypackage/evolve/__init__.py to make sure NAME +
+'.evolve' can be imported.)
+
 Now you are ready to create your versioned schema::
 
     import sqlalchemy.orm
 tests_requires = ['nose'] + requires
 
 setup(name='stucco_evolution',
-      version='0.33',
+      version='0.34',
       description='Moderately simple schema upgrades for SQLAlchemy.',
       long_description=README + '\n\n' +  CHANGES,
       classifiers=[
       obsoletes=['ponzi_evolution'],
       test_suite='nose.collector',
       entry_points = """\
+      [paste.paster_create_template]
+      stucco_evolution=stucco_evolution.paster:EvolveModule
       """,
       )
 

File stucco_evolution/+template+/evolve/__init__.py_tmpl

+"""
+Evolution module. Numbered Python scripts in this directory update the
+named database schema to VERSION.
+"""
+NAME = '{{package}}'
+VERSION = 0
+DEPENDS = []

File stucco_evolution/+template+/evolve/create.py

+def create(connection):
+    """Create the latest version of the schema. This function should be
+    idempotent and can be usefully called more than once per database
+    for development, but stucco_evolution tries to call this only once
+    in production."""
+    # import yourproject
+    # yourproject.Base.metadata.create_all(connection)
+    # or
+    # connection.execute("CREATE TABLE ...")

File stucco_evolution/+template+/evolve/evolve1.py

+def evolve(connection):
+    """Execute any ALTER TABLE etc. statements needed to bring the
+    database up-to-date (upgrade the schema from VERSION n-1 to VERSION n.)"""
+    pass

File stucco_evolution/paster.py

+from paste.script.templates import Template, var
+from paste.util.template import paste_script_template_renderer
+
+class EvolveModule(Template):
+    """Create a stucco_evolution evolution module."""
+    _template_dir = '+template+'
+    summary = 'Create a stucco_evolution evolution module.'
+    template_renderer = staticmethod(paste_script_template_renderer)

File stucco_evolution/test.py

     Session = sqlalchemy.orm.sessionmaker(bind=engine)
     session = Session()
     stucco_evolution.initialize(session.connection())
-    manager = stucco_evolution.SQLAlchemyEvolutionManager(session.connection(), 'testing_testing', 4)
+    manager = stucco_evolution.SQLAlchemyEvolutionManager(session.connection(), 
+                                                          'testing_testing', 4)
     assert manager.get_db_version() is None
     assert manager.get_sw_version() is 4
     assert isinstance(repr(manager), basestring)
     assert stucco_evolution.manager(None, 'stucco_evolution') is not None
 
 def test_transactional_ddl():
-    """Ensure CREATE TABLE statements can be rolled back when there is
-    an error in the migration.
-
-    XXX This test will only pass with a patched pysqlite.
-    """
+    """Test transaction ddl. Requires a patched sqlite3 module."""
     from sqlalchemy import Column, Integer
     from sqlalchemy.ext.declarative import declarative_base
     Base = declarative_base()
     connection.close()
 
 def test_transactional_ddl_2():
+    """Test transaction ddl (2). Requires a patched sqlite3 module."""
     import logging
     log = logging.getLogger(__name__)
     engine = sqlalchemy.create_engine('sqlite:///:memory:')