1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
|
from datetime import datetime
from .. import db
class Category(db.Model):
id = db.Column(db.Integer, primary_key=True)
name = db.Column(db.Unicode(30), unique=True, nullable=False)
description = db.Column(db.Unicode(500))
def __repr__(self):
return "<Category %r>" % self.name
package_maintainer_rel_table = db.Table('package_maintainer_rel',
db.Column('package_id', db.Integer, db.ForeignKey('package.id')),
db.Column('maintainer_id', db.Integer, db.ForeignKey('maintainer.id')),
)
class Package(db.Model):
id = db.Column(db.Integer, primary_key=True)
name = db.Column(db.Unicode(128), nullable=False)
category_id = db.Column(db.Integer, db.ForeignKey('category.id'), nullable=False)
category = db.relationship('Category', backref=db.backref('packages', lazy='dynamic'))
description = db.Column(db.Unicode(500))
last_sync_ts = db.Column(db.TIMESTAMP, nullable=False, default=datetime.utcfromtimestamp(0))
maintainers = db.relationship("Maintainer",
secondary=package_maintainer_rel_table,
backref='directly_maintained_packages')
@property
def full_name(self):
return "%s/%s" % (self.category.name, self.name)
def __repr__(self):
return "<Package '%s/%s'>" % (self.category.name, self.name)
class PackageVersion(db.Model):
id = db.Column(db.Integer, primary_key=True)
version = db.Column(db.Unicode(128), nullable=False)
package_id = db.Column(db.Integer, db.ForeignKey('package.id'), nullable=False)
package = db.relationship('Package', backref=db.backref('versions', lazy='dynamic'))
def __repr__(self):
return "<PackageVersion '%s/%s-%s'>" % (self.package.category.name, self.package.name, self.version)
maintainer_project_membership_rel_table = db.Table('maintainer_project_membership_rel',
db.Column('project_id', db.Integer, db.ForeignKey('maintainer.id')),
db.Column('maintainer_id', db.Integer, db.ForeignKey('maintainer.id')),
)
class Maintainer(db.Model):
id = db.Column(db.Integer, primary_key=True)
# TODO: This has to be unique case insensitive. Currently we have to always force lower() to guarantee this and find the proper maintainer entry; later we might want to use some sort of NOCASE collate rules here to keep the capitalization as preferred per master data
email = db.Column(db.Unicode(50), nullable=False, unique=True)
is_project = db.Column(db.Boolean, nullable=False, server_default='f', default=False)
name = db.Column(db.Unicode(128))
url = db.Column(db.Unicode())
description = db.Column(db.Unicode(500))
members = db.relationship("Maintainer",
secondary=maintainer_project_membership_rel_table,
primaryjoin=id==maintainer_project_membership_rel_table.c.project_id,
secondaryjoin=id==maintainer_project_membership_rel_table.c.maintainer_id,
backref='projects')
# projects relationship backref ^^
# directly_maintained_packages backref - list of packages maintained directly by given project or individual maintainer (as opposed to a bigger list that includes packages maintained by parent/child projects or projects the given individual maintainer is part of)
def __repr__(self):
return "<Maintainer %s '%s'>" % ("project" if self.is_project else "individual", self.email)
|