Commits

dieselmachine committed 663fc9a Draft

bugfixes

Comments (0)

Files changed (2)

alembic/autogenerate.py

                 else:
                     " this is a rename "
                     old_name = potential_renames[cmd-2]
+                    _sch, _name = (None, old_name)
+                    if old_name.find('.') > -1:
+                        _sch, _name = old_name.rsplit('.',1)
                     removed_tables.remove(old_name)
                     existing_tables.add(tname)
                     conn_column_info[tname] = dict(
                         (rec["name"], rec)
-                        for rec in inspector.get_columns(old_name)
+                        for rec in inspector.get_columns(_name, schema=_sch)
                         )
-                    diffs.append(("rename_table", old_name, tname, sch))
+                    diffs.append(("rename_table", _name, name, sch))
         else:
             diffs.append(("add_table", metadata.tables[tname]))
             log.info("Detected added table %r", tname)
 # element comparison
 
 def _compare_columns(tname, conn_table, metadata_table, diffs, autogen_context,
-                     interactive=False, schema=None):
-    sch, name = (schema, tname)
+                     interactive=False, schema_=None):
+    sch, name = (schema_, tname)
     if tname.find('.') > -1:
         sch, name = tname.rsplit('.',1)
                      
     for cname in added_columns:
         if interactive:
             if not removed_columns:
-                diffs.append(("add_column", tname, metadata_cols_by_name[cname]))
+                diffs.append(("add_column", name, metadata_cols_by_name[cname],
+                    sch))
                 log.info("Detected added column '%s.%s'", tname, cname)
             else:
                 print 'detected added column %s. Action?' % cname
                     existing_columns.add(old_name)
                     renamed_columns[old_name] = cname
         else:
-            diffs.append(("add_column", tname, metadata_cols_by_name[cname]))
+            diffs.append(("add_column", name, metadata_cols_by_name[cname],
+                sch))
             log.info("Detected added column '%s.%s'", tname, cname)
 
     for cname in removed_columns:
         diffs.append(
-            ("remove_column", tname, schema.Column(
+            ("remove_column", name, schema.Column(
                 cname,
                 conn_table[cname]['type'],
                 nullable=conn_table[cname]['nullable'],
                 server_default=conn_table[cname]['default']
-            ))
+            ),sch)
         )
         log.info("Detected removed column '%s.%s'", tname, cname)
 
 
 def _invoke_rename_table_command(updown, args, autogen_context):
     old_name, new_name = args[1:3]
-    if len(args) > 3:
-        schema = args[3]
-    else:
-        schema = None
+    schema = args[3] if len(args) > 3 else None
 
     if updown == 'upgrade':
         return _rename_table(old_name, new_name, autogen_context, schema=schema)
 def _invoke_adddrop_command(updown, args, autogen_context):
     cmd_type = args[0]
     adddrop, cmd_type = cmd_type.split("_")
-
+    kwargs = {}
+    if len(args) > 3:
+        kwargs['schema'] = args[3]
+        args = args[:3] + args[4:]
     cmd_args = args[1:] + (autogen_context,)
 
     _commands = {
     ) or (
         updown == "downgrade" and adddrop == "remove"
     ):
-        return cmd_callables[1](*cmd_args)
+        return cmd_callables[1](*cmd_args, **kwargs)
     else:
-        return cmd_callables[0](*cmd_args)
+        return cmd_callables[0](*cmd_args, **kwargs)
 
 def _invoke_modify_command(updown, args, autogen_context):
     tname, cname = args[0][1:3]

alembic/command.py

              initial=False):
     """Create a new revision file."""
     script = ScriptDirectory.from_config(config)
-    current_rev = script.get_revision("head").revision
+    current_rev = script.get_revision("head")
+    current_rev = current_rev.revision if current_rev else None
     template_args = {}
     imports = set()
     if autogenerate or interactive or initial: