-def alter_column(table_name, column_name,
- nullable=NO_VALUE,
- server_default=NO_VALUE,
- name=NO_VALUE,
- type=NO_VALUE
-):
+
+class DefaultContext(object):
+ def alter_column(self, table_name, column_name,
+ nullable=NO_VALUE,
+ server_default=NO_VALUE,
+ name=NO_VALUE,
+ type=NO_VALUE
+ ):
- if nullable is not NO_VALUE:
- ColumnNullable(table_name, column_name, nullable)
- if server_default is not NO_VALUE:
- ColumnDefault(table_name, column_name, server_default)
+ if nullable is not NO_VALUE:
+ ColumnNullable(table_name, column_name, nullable)
+ if server_default is not NO_VALUE:
+ ColumnDefault(table_name, column_name, server_default)
- # ... etc
\ No newline at end of file
+ # ... etc
\ No newline at end of file
-"ALTER TABLE foo ADD COLUMN bat integer NOT NULL DEFAULT 7;"
\ No newline at end of file
nullable=NO_VALUE,
server_default=NO_VALUE,
name=NO_VALUE,
- type=NO_VALUE
+ type_=NO_VALUE
):
"""Issue ALTER COLUMN using the current change context."""
- # TODO: dispatch to ddl.op
\ No newline at end of file
+ context.alter_column(table_name, column_name,
+ nullable=nullable,
+ server_default=server_default,
+ name=name,
+ type_=type_
+ )
-
+def get_option_parser():
+ parser = OptionParser("usage: %prog [options] <command>")
+ parser.add_option("-d", "--dir", type="string", action="store", help="Location of script directory.")
+
+
class Options(object):
def __init__(self, options):
self.options = options
import os
-class Script(object):
+class ScriptDirectory(object):
def __init__(self, dir):
self.dir = dir
--- /dev/null
+# temporary sample notes
+
+
+# commands:
+
+alembic init ./scripts
+alembic revision -m "do something else"
+alembic upgrade
+alembic revert -r jQq57
+alembic history
+alembic splice jQq57 Pz953
+alembic branches
+
+# with pylons - use paster commands ?
+
+
+scripts directory looks like:
+
+
+./scripts/
+ env.py
+ script_template.py
+ lfh56_do_this.py
+ jQq57_do_that.py
+ Pzz19_do_something_else.py
+
+
+
+# env.py looks like:
+# ------------------------------------
+
+from alembic import options, context
+
+import logging
+logging.fileConfig(options.config_file)
+
+engine = create_engine(options.get_main_option('url'))
+
+connection = engine.connect()
+context.configure_connection(connection)
+trans = connection.begin()
+try:
+ run_migrations()
+ trans.commit()
+except:
+ trans.rollback()
+
+
+# a pylons env.py looks like:
+# --------------------------------------
+
+from alembic import options, context
+
+from name_of_project.config import environment
+environment.setup_app(whatever)
+
+engine = environment.engine # or meta.engine, whatever it has to be here
+
+connection = engine.connect()
+context.configure_connection(connection)
+trans = connection.begin()
+try:
+ run_migrations()
+ trans.commit()
+except:
+ trans.rollback()
+
+# script template
+# -----------------------------------------
+from alembic.op import *
+
+def upgrade_%(up_revision)s():
+ pass
+
+def downgrade_%(down_revision)s():
+ pass
+
+
+
+
+
\ No newline at end of file
from optparse import OptionParser
def main(argv=None):
-
- parser = OptionParser("usage: %prog [options] <command>")
- parser.add_option("-d", "--dir", type="string", action="store", help="Location of script directory.")
+ parser = alembic.options.get_option_parser()
opts, args = parser.parse_args(argv[1:])
if len(args) < 1: