def upgrade_2_to_3(self): self.drop_index(self.table.c.type) self.alter_column(Column('type', IbidUnicode(8), nullable=False, index=True), force_rebuild=True) self.alter_column(Column('channel', IbidUnicode(32)), force_rebuild=True) self.alter_column(Column('value', IbidUnicodeText), force_rebuild=True) self.add_index(self.table.c.type)
class Sighting(Base): __table__ = Table('seen', Base.metadata, Column('id', Integer, primary_key=True), Column('identity_id', Integer, ForeignKey('identities.id'), nullable=False, index=True), Column('type', IbidUnicode(8), nullable=False, index=True), Column('channel', IbidUnicode(32)), Column('value', IbidUnicodeText), Column('time', DateTime, nullable=False), Column('count', Integer, nullable=False), UniqueConstraint('identity_id', 'type'), useexisting=True) class SightingSchema(VersionedSchema): def upgrade_1_to_2(self): self.add_index(self.table.c.identity_id) self.add_index(self.table.c.type) def upgrade_2_to_3(self): self.drop_index(self.table.c.type) self.alter_column(Column('type', IbidUnicode(8), nullable=False, index=True), force_rebuild=True) self.alter_column(Column('channel', IbidUnicode(32)), force_rebuild=True) self.alter_column(Column('value', IbidUnicodeText), force_rebuild=True) self.add_index(self.table.c.type) __table__.versioned_schema = SightingSchema(__table__, 3) identity = relation('Identity') def __init__(self, identity_id=None, type='message', channel=None, value=None): self.identity_id = identity_id self.type = type self.channel = channel self.value = value self.time = datetime.utcnow() self.count = 0 def __repr__(self): return u'<Sighting %s %s in %s at %s: %s>' % ( self.type, self.identity_id, self.channel, self.time, self.value)
def upgrade_2_to_3(self): self.alter_column( Column('subject', IbidUnicode(64), unique=True, nullable=False, index=True))
class URL(Base): __table__ = Table('urls', Base.metadata, Column('id', Integer, primary_key=True), Column('url', IbidUnicodeText, nullable=False), Column('channel', IbidUnicode(32, case_insensitive=True), nullable=False), Column('identity_id', Integer, ForeignKey('identities.id'), nullable=False, index=True), Column('time', DateTime, nullable=False), useexisting=True) class URLSchema(VersionedSchema): def upgrade_1_to_2(self): self.add_index(self.table.c.identity_id) def upgrade_2_to_3(self): self.alter_column(Column('url', IbidUnicodeText, nullable=False)) self.alter_column(Column('channel', IbidUnicode(32, case_insensitive=True), nullable=False), force_rebuild=True) __table__.versioned_schema = URLSchema(__table__, 3) def __init__(self, url, channel, identity_id): self.url = url self.channel = channel self.identity_id = identity_id self.time = datetime.utcnow()
class Factpack(Base): __table__ = Table('factpacks', Base.metadata, Column('id', Integer, primary_key=True), Column('name', IbidUnicode(64, case_insensitive=True), nullable=False, unique=True, index=True), useexisting=True) class FactpackSchema(VersionedSchema): def upgrade_1_to_2(self): self.add_index(self.table.c.name) def upgrade_2_to_3(self): self.drop_index(self.table.c.name) self.alter_column(Column('name', IbidUnicode(64, case_insensitive=True), nullable=False, unique=True, index=True), force_rebuild=True) self.add_index(self.table.c.name) __table__.versioned_schema = FactpackSchema(__table__, 3) def __init__(self, name): self.name = name def __repr__(self): return u'<Factpack %s>' % (self.name, )
def upgrade_2_to_3(self): self.drop_index(self.table.c.name) self.alter_column(Column('name', IbidUnicode(64, case_insensitive=True), nullable=False, unique=True, index=True), force_rebuild=True) self.add_index(self.table.c.name)
def upgrade_3_to_4(self): self.drop_index(self.table.c.subject) self.alter_column(Column('subject', IbidUnicode(64, case_insensitive=True), unique=True, nullable=False, index=True), force_rebuild=True) self.add_index(self.table.c.subject)
class Karma(Base): __table__ = Table('karma', Base.metadata, Column('id', Integer, primary_key=True), Column('subject', IbidUnicode(64, case_insensitive=True), unique=True, nullable=False, index=True), Column('changes', Integer, nullable=False), Column('value', Integer, nullable=False), Column('time', DateTime, nullable=False), useexisting=True) class KarmaSchema(VersionedSchema): def upgrade_1_to_2(self): self.add_index(self.table.c.subject) def upgrade_2_to_3(self): self.alter_column(Column('subject', IbidUnicode(64), unique=True, nullable=False, index=True)) def upgrade_3_to_4(self): self.drop_index(self.table.c.subject) self.alter_column(Column('subject', IbidUnicode(64, case_insensitive=True), unique=True, nullable=False, index=True), force_rebuild=True) self.add_index(self.table.c.subject) __table__.versioned_schema = KarmaSchema(__table__, 4) def __init__(self, subject): self.subject = subject self.changes = 0 self.value = 0 self.time = datetime.utcnow()
def upgrade_4_to_5(self): self.alter_column( Column('name', IbidUnicode(64), key='_name', nullable=False, unique=True, index=True))
def upgrade_3_to_4(self): self.drop_index(self.table.c.name) self.drop_index(self.table.c.source) self.drop_index(self.table.c.target) self.alter_column(Column('name', IbidUnicode(32, case_insensitive=True), unique=True, nullable=False, index=True), force_rebuild=True) self.alter_column(Column('url', IbidUnicodeText, nullable=False), force_rebuild=True) self.alter_column(Column('source', IbidUnicode(32, case_insensitive=True), index=True), force_rebuild=True) self.alter_column(Column('target', IbidUnicode(32, case_insensitive=True), index=True), force_rebuild=True) self.add_index(self.table.c.name) self.add_index(self.table.c.source) self.add_index(self.table.c.target)
def upgrade_2_to_3(self): from ibid.db import IbidUnicode, Column self.add_column(Column('source', IbidUnicode(32), index=True)) self.add_column(Column('target', IbidUnicode(32), index=True))
class Feed(Base): __table__ = Table('feeds', Base.metadata, Column('id', Integer, primary_key=True), Column('name', IbidUnicode(32, case_insensitive=True), unique=True, nullable=False, index=True), Column('url', IbidUnicodeText, nullable=False), Column('identity_id', Integer, ForeignKey('identities.id'), nullable=False, index=True), Column('time', DateTime, nullable=False), Column('source', IbidUnicode(32, case_insensitive=True), index=True), Column('target', IbidUnicode(32, case_insensitive=True), index=True), useexisting=True) class FeedSchema(VersionedSchema): def upgrade_1_to_2(self): self.add_index(self.table.c.name) self.add_index(self.table.c.identity_id) def upgrade_2_to_3(self): from ibid.db import IbidUnicode, Column self.add_column(Column('source', IbidUnicode(32), index=True)) self.add_column(Column('target', IbidUnicode(32), index=True)) def upgrade_3_to_4(self): self.drop_index(self.table.c.name) self.drop_index(self.table.c.source) self.drop_index(self.table.c.target) self.alter_column(Column('name', IbidUnicode(32, case_insensitive=True), unique=True, nullable=False, index=True), force_rebuild=True) self.alter_column(Column('url', IbidUnicodeText, nullable=False), force_rebuild=True) self.alter_column(Column('source', IbidUnicode(32, case_insensitive=True), index=True), force_rebuild=True) self.alter_column(Column('target', IbidUnicode(32, case_insensitive=True), index=True), force_rebuild=True) self.add_index(self.table.c.name) self.add_index(self.table.c.source) self.add_index(self.table.c.target) __table__.versioned_schema = FeedSchema(__table__, 4) feed = None entries = None def __init__(self, name, url, identity_id, source=None, target=None): self.name = name self.url = url self.identity_id = identity_id self.source = source self.target = target self.time = datetime.utcnow() self.update() def update(self, max_age=None): headers = {} if max_age: headers['Cache-Control'] = 'max-age=%i' % max_age feedfile = cacheable_download(self.url, "feeds/%s-%i.xml" % ( re.sub(r'\W+', '_', self.name), self.identity_id), headers) self.feed = feedparser.parse(feedfile) self.entries = self.feed['entries'] def __unicode__(self): if self.source is not None and self.target is not None: string = u'%s (notify %s on %s)' % ( self.name, self.target, self.source) if self.name in broken_feeds: string += ' [broken]' return string else: return self.name
def upgrade_2_to_3(self): self.alter_column(Column('url', IbidUnicodeText, nullable=False)) self.alter_column(Column('channel', IbidUnicode(32, case_insensitive=True), nullable=False), force_rebuild=True)