]> git.ipfire.org Git - thirdparty/sqlalchemy/alembic.git/commitdiff
thinking about layout
authorMike Bayer <mike_mp@zzzcomputing.com>
Sat, 24 Apr 2010 21:41:46 +0000 (17:41 -0400)
committerMike Bayer <mike_mp@zzzcomputing.com>
Sat, 24 Apr 2010 21:41:46 +0000 (17:41 -0400)
alembic/ddl/op.py
alembic/ddl/postgresql.py
alembic/op.py
alembic/options.py
alembic/script.py
sample_notes.txt [new file with mode: 0644]
scripts/alembic

index 462c9fd8f34506d608d0924b0da823da697744b9..f0f96b10472f96ec64af71a4ac318a67505a98d5 100644 (file)
@@ -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
index 91dadf5242c0e2674a459a736d5fd3bb06335bc3..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 100644 (file)
@@ -1 +0,0 @@
-"ALTER TABLE foo   ADD COLUMN bat integer NOT NULL DEFAULT 7;"
\ No newline at end of file
index 6211903bea0ca2b1e35df321dd443d2114d3bb6e..6a31c4f079872933b4e5c08e33ad8fc97724ebf6 100644 (file)
@@ -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_
+    )
index 0b1a388c85db058a7aa7ea8d43a22b180993d32b..0130b5e99c5635cfd6c17dd0894a171127cdf37c 100644 (file)
@@ -1,5 +1,9 @@
 
-
+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
index 4a534ea476835fc052e83498634e225560ddca68..79ce1ba50517249925efece817f729ebc72e6314 100644 (file)
@@ -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 (file)
index 0000000..d17cbfc
--- /dev/null
@@ -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
index cc905a0b6efdbda88390011e80e950ad4223844c..df453e2e7b960530afbbb3879e92de6f3c782dcb 100644 (file)
@@ -5,9 +5,7 @@ import sys
 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: