From: Mike Bayer Date: Sat, 24 Apr 2010 21:41:46 +0000 (-0400) Subject: thinking about layout X-Git-Tag: rel_0_1_0~115 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=cf93eeab9943d1d567e172a9a6a1f5f649c368e3;p=thirdparty%2Fsqlalchemy%2Falembic.git thinking about layout --- diff --git a/alembic/ddl/op.py b/alembic/ddl/op.py index 462c9fd8..f0f96b10 100644 --- a/alembic/ddl/op.py +++ b/alembic/ddl/op.py @@ -1,13 +1,15 @@ -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 diff --git a/alembic/ddl/postgresql.py b/alembic/ddl/postgresql.py index 91dadf52..e69de29b 100644 --- a/alembic/ddl/postgresql.py +++ b/alembic/ddl/postgresql.py @@ -1 +0,0 @@ -"ALTER TABLE foo ADD COLUMN bat integer NOT NULL DEFAULT 7;" \ No newline at end of file diff --git a/alembic/op.py b/alembic/op.py index 6211903b..6a31c4f0 100644 --- a/alembic/op.py +++ b/alembic/op.py @@ -6,8 +6,13 @@ def alter_column(table_name, column_name, 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_ + ) diff --git a/alembic/options.py b/alembic/options.py index 0b1a388c..0130b5e9 100644 --- a/alembic/options.py +++ b/alembic/options.py @@ -1,5 +1,9 @@ - +def get_option_parser(): + parser = OptionParser("usage: %prog [options] ") + parser.add_option("-d", "--dir", type="string", action="store", help="Location of script directory.") + + class Options(object): def __init__(self, options): self.options = options diff --git a/alembic/script.py b/alembic/script.py index 4a534ea4..79ce1ba5 100644 --- a/alembic/script.py +++ b/alembic/script.py @@ -1,6 +1,6 @@ import os -class Script(object): +class ScriptDirectory(object): def __init__(self, dir): self.dir = dir diff --git a/sample_notes.txt b/sample_notes.txt new file mode 100644 index 00000000..d17cbfc1 --- /dev/null +++ b/sample_notes.txt @@ -0,0 +1,81 @@ +# 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 diff --git a/scripts/alembic b/scripts/alembic index cc905a0b..df453e2e 100644 --- a/scripts/alembic +++ b/scripts/alembic @@ -5,9 +5,7 @@ import sys from optparse import OptionParser def main(argv=None): - - parser = OptionParser("usage: %prog [options] ") - 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: