Exemple #1
0
 def copy_fixed(self, **kw):
     """Create a copy of this ``Column``, with all attributes."""
     q = util.safe_quote(self)
     return sqlalchemy.Column(self.name,
                              self.type,
                              self.default,
                              key=self.key,
                              primary_key=self.primary_key,
                              nullable=self.nullable,
                              quote=q,
                              index=self.index,
                              unique=self.unique,
                              onupdate=self.onupdate,
                              autoincrement=self.autoincrement,
                              server_default=self.server_default,
                              server_onupdate=self.server_onupdate,
                              *[c.copy(**kw) for c in self.constraints])
    def visit_column(self, delta):
        table = delta.table
        colspec = self.get_column_specification(delta.result_column)
        if delta.result_column.autoincrement:
            primary_keys = [
                c for c in table.primary_key.columns
                if (c.autoincrement and isinstance(c.type, sqltypes.Integer)
                    and not c.foreign_keys)
            ]

            if primary_keys:
                first = primary_keys.pop(0)
                if first.name == delta.current_name:
                    colspec += " AUTO_INCREMENT"
        q = util.safe_quote(table)
        old_col_name = self.preparer.quote(delta.current_name, q)

        self.start_alter_table(table)

        self.append("CHANGE COLUMN %s " % old_col_name)
        self.append(colspec)
        self.execute()
Exemple #3
0
 def _visit_column_name(self, table, column, delta):
     self.start_alter_table(table)
     q = util.safe_quote(table)
     col_name = self.preparer.quote(delta.current_name, q)
     new_name = self.preparer.format_column(delta.result_column)
     self.append('RENAME COLUMN %s TO %s' % (col_name, new_name))
Exemple #4
0
 def start_alter_column(self, table, col_name):
     """Starts ALTER COLUMN"""
     self.start_alter_table(table)
     q = util.safe_quote(table)
     self.append("ALTER COLUMN %s " % self.preparer.quote(col_name, q))
Exemple #5
0
 def visit_table(self, table):
     """Rename a table. Other ops aren't supported."""
     self.start_alter_table(table)
     q = util.safe_quote(table)
     self.append("RENAME TO %s" % self.preparer.quote(table.new_name, q))
     self.execute()