def emit_db_sequence_updates(self):
        """Set database sequence objects to match the source db

           Relevant only when generated from SQLAlchemy connection.
           Needed to avoid subsequent unique key violations after DB build."""

        if self.source.db_engine and self.source.db_engine.name != 'postgresql':
            # not implemented for other RDBMS; necessity unknown
            conn = self.source.db_engine.connect()
            qry = """SELECT 'SELECT last_value FROM ' || n.nspname || '.' || c.relname || ';'
                     FROM   pg_namespace n
                     JOIN   pg_class c ON (n.oid = c.relnamespace)
                     WHERE  c.relkind = 'S'"""
            result = []
            for (sequence, ) in list(conn.execute(qry)):
                qry = "SELECT last_value FROM %s" % sequence
                (lastval, ) = conn.execute(qry).first()
                nextval = int(lastval) + 1
                yield "ALTER SEQUENCE %s RESTART WITH %s;" % nextval
Set database sequence objects to match the source db

           Relevant only when generated from SQLAlchemy connection.
           Needed to avoid subsequent unique key violations after DB build.