Logo Search packages:      
Sourcecode: ibid version File versions  Download package

def ibid::db::versioned_schema::VersionedSchema::_create_table (   self  )  [private]

Check that the table is in a suitable form for all DBs, before
creating. Yes, SQLAlchemy's abstractions are leaky enough that you have
to do this

Definition at line 154 of file versioned_schema.py.

00154                            :
        """
        Check that the table is in a suitable form for all DBs, before
        creating. Yes, SQLAlchemy's abstractions are leaky enough that you have
        to do this
        """
        session = self.upgrade_session
        indices = []
        old_indexes = list(self.table.indexes)
        old_constraints = list(self.table.constraints)

        for column in self.table.c:
            if column.unique and not column.index:
                raise Exception(u"Column %s.%s is unique but not indexed. "
                    u"SQLite doesn't like such things, "
                    u"so please be nice and don't do that."
                    % (self.table.name, self.column.name))

        # Strip out Indexes and Constraints that SQLAlchemy can't create by
        # itself
        if session.bind.engine.name == 'mysql':
            for type, old_list in (
                    ('constraints', old_constraints),
                    ('indexes', old_indexes)):
                for constraint in old_list:
                    if any(True for column in constraint.columns
                            if isinstance(column.type, IbidUnicodeText)):
                        indices.append((
                            isinstance(constraint, UniqueConstraint),
                            self._mysql_constraint_createstring(constraint)
                        ))

                        getattr(self.table, type).remove(constraint)
            # In case the database's DEFAULT CHARSET isn't set to UTF8
            self.table.kwargs['mysql_charset'] = 'utf8'

        self.table.create(bind=session.bind)

        if session.bind.engine.name == 'mysql':
            for constraint in old_constraints:
                if constraint not in self.table.constraints:
                    self.table.constraints.add(constraint)

            for index in old_indexes:
                if index not in self.table.indexes:
                    self.table.indexes.add(index)

            for unique, columnspec in indices:
                session.execute('ALTER TABLE "%s" ADD %s INDEX (%s);' % (
                    self.table.name, unique and 'UNIQUE' or '', columnspec))

    def _get_reflected_model(self):


Generated by  Doxygen 1.6.0   Back to index