server/db: specify nullable for foreign keys

This is mostly stylistic change, but it clearly shows the intended
behavior should we detect more integrity violation errors.
This commit is contained in:
rr- 2016-08-15 18:36:31 +02:00
parent 522886ae6c
commit e688f39887
4 changed files with 34 additions and 7 deletions

View file

@ -8,11 +8,16 @@ class CommentScore(Base):
__tablename__ = 'comment_score'
comment_id = Column(
'comment_id', Integer, ForeignKey('comment.id'), primary_key=True)
'comment_id',
Integer,
ForeignKey('comment.id'),
nullable=False,
primary_key=True)
user_id = Column(
'user_id',
Integer,
ForeignKey('user.id'),
nullable=False,
primary_key=True,
index=True)
time = Column('time', DateTime, nullable=False)
@ -29,8 +34,9 @@ class Comment(Base):
comment_id = Column('id', Integer, primary_key=True)
post_id = Column(
'post_id', Integer, ForeignKey('post.id'), index=True, nullable=False)
user_id = Column('user_id', Integer, ForeignKey('user.id'), index=True)
'post_id', Integer, ForeignKey('post.id'), nullable=False, index=True)
user_id = Column(
'user_id', Integer, ForeignKey('user.id'), nullable=True, index=True)
version = Column('version', Integer, default=1, nullable=False)
creation_time = Column('creation_time', DateTime, nullable=False)
last_edit_time = Column('last_edit_time', DateTime)

View file

@ -31,12 +31,14 @@ class PostScore(Base):
Integer,
ForeignKey('post.id'),
primary_key=True,
nullable=False,
index=True)
user_id = Column(
'user_id',
Integer,
ForeignKey('user.id'),
primary_key=True,
nullable=False,
index=True)
time = Column('time', DateTime, nullable=False)
score = Column('score', Integer, nullable=False)
@ -55,12 +57,14 @@ class PostFavorite(Base):
Integer,
ForeignKey('post.id'),
primary_key=True,
nullable=False,
index=True)
user_id = Column(
'user_id',
Integer,
ForeignKey('user.id'),
primary_key=True,
nullable=False,
index=True)
time = Column('time', DateTime, nullable=False)
@ -90,12 +94,14 @@ class PostRelation(Base):
Integer,
ForeignKey('post.id'),
primary_key=True,
nullable=False,
index=True)
child_id = Column(
'child_id',
Integer,
ForeignKey('post.id'),
primary_key=True,
nullable=False,
index=True)
def __init__(self, parent_id, child_id):
@ -111,9 +117,15 @@ class PostTag(Base):
Integer,
ForeignKey('post.id'),
primary_key=True,
nullable=False,
index=True)
tag_id = Column(
'tag_id', Integer, ForeignKey('tag.id'), primary_key=True, index=True)
'tag_id',
Integer,
ForeignKey('tag.id'),
primary_key=True,
nullable=False,
index=True)
def __init__(self, post_id, tag_id):
self.post_id = post_id

View file

@ -19,7 +19,10 @@ class Snapshot(Base):
resource_repr = Column('resource_repr', Unicode(64), nullable=False)
operation = Column('operation', Unicode(16), nullable=False)
user_id = Column(
'user_id', Integer, ForeignKey('user.id', ondelete='set null'))
'user_id',
Integer,
ForeignKey('user.id', ondelete='set null'),
nullable=True)
data = Column('data', PickleType)
user = relationship('User')

View file

@ -13,12 +13,16 @@ class TagSuggestion(Base):
'parent_id',
Integer,
ForeignKey('tag.id'),
primary_key=True, index=True)
nullable=False,
primary_key=True,
index=True)
child_id = Column(
'child_id',
Integer,
ForeignKey('tag.id'),
primary_key=True, index=True)
nullable=False,
primary_key=True,
index=True)
def __init__(self, parent_id, child_id):
self.parent_id = parent_id
@ -32,12 +36,14 @@ class TagImplication(Base):
'parent_id',
Integer,
ForeignKey('tag.id'),
nullable=False,
primary_key=True,
index=True)
child_id = Column(
'child_id',
Integer,
ForeignKey('tag.id'),
nullable=False,
primary_key=True,
index=True)