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:
parent
522886ae6c
commit
e688f39887
4 changed files with 34 additions and 7 deletions
|
@ -8,11 +8,16 @@ class CommentScore(Base):
|
||||||
__tablename__ = 'comment_score'
|
__tablename__ = 'comment_score'
|
||||||
|
|
||||||
comment_id = Column(
|
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 = Column(
|
||||||
'user_id',
|
'user_id',
|
||||||
Integer,
|
Integer,
|
||||||
ForeignKey('user.id'),
|
ForeignKey('user.id'),
|
||||||
|
nullable=False,
|
||||||
primary_key=True,
|
primary_key=True,
|
||||||
index=True)
|
index=True)
|
||||||
time = Column('time', DateTime, nullable=False)
|
time = Column('time', DateTime, nullable=False)
|
||||||
|
@ -29,8 +34,9 @@ class Comment(Base):
|
||||||
|
|
||||||
comment_id = Column('id', Integer, primary_key=True)
|
comment_id = Column('id', Integer, primary_key=True)
|
||||||
post_id = Column(
|
post_id = Column(
|
||||||
'post_id', Integer, ForeignKey('post.id'), index=True, nullable=False)
|
'post_id', Integer, ForeignKey('post.id'), nullable=False, index=True)
|
||||||
user_id = Column('user_id', Integer, ForeignKey('user.id'), index=True)
|
user_id = Column(
|
||||||
|
'user_id', Integer, ForeignKey('user.id'), nullable=True, index=True)
|
||||||
version = Column('version', Integer, default=1, nullable=False)
|
version = Column('version', Integer, default=1, nullable=False)
|
||||||
creation_time = Column('creation_time', DateTime, nullable=False)
|
creation_time = Column('creation_time', DateTime, nullable=False)
|
||||||
last_edit_time = Column('last_edit_time', DateTime)
|
last_edit_time = Column('last_edit_time', DateTime)
|
||||||
|
|
|
@ -31,12 +31,14 @@ class PostScore(Base):
|
||||||
Integer,
|
Integer,
|
||||||
ForeignKey('post.id'),
|
ForeignKey('post.id'),
|
||||||
primary_key=True,
|
primary_key=True,
|
||||||
|
nullable=False,
|
||||||
index=True)
|
index=True)
|
||||||
user_id = Column(
|
user_id = Column(
|
||||||
'user_id',
|
'user_id',
|
||||||
Integer,
|
Integer,
|
||||||
ForeignKey('user.id'),
|
ForeignKey('user.id'),
|
||||||
primary_key=True,
|
primary_key=True,
|
||||||
|
nullable=False,
|
||||||
index=True)
|
index=True)
|
||||||
time = Column('time', DateTime, nullable=False)
|
time = Column('time', DateTime, nullable=False)
|
||||||
score = Column('score', Integer, nullable=False)
|
score = Column('score', Integer, nullable=False)
|
||||||
|
@ -55,12 +57,14 @@ class PostFavorite(Base):
|
||||||
Integer,
|
Integer,
|
||||||
ForeignKey('post.id'),
|
ForeignKey('post.id'),
|
||||||
primary_key=True,
|
primary_key=True,
|
||||||
|
nullable=False,
|
||||||
index=True)
|
index=True)
|
||||||
user_id = Column(
|
user_id = Column(
|
||||||
'user_id',
|
'user_id',
|
||||||
Integer,
|
Integer,
|
||||||
ForeignKey('user.id'),
|
ForeignKey('user.id'),
|
||||||
primary_key=True,
|
primary_key=True,
|
||||||
|
nullable=False,
|
||||||
index=True)
|
index=True)
|
||||||
time = Column('time', DateTime, nullable=False)
|
time = Column('time', DateTime, nullable=False)
|
||||||
|
|
||||||
|
@ -90,12 +94,14 @@ class PostRelation(Base):
|
||||||
Integer,
|
Integer,
|
||||||
ForeignKey('post.id'),
|
ForeignKey('post.id'),
|
||||||
primary_key=True,
|
primary_key=True,
|
||||||
|
nullable=False,
|
||||||
index=True)
|
index=True)
|
||||||
child_id = Column(
|
child_id = Column(
|
||||||
'child_id',
|
'child_id',
|
||||||
Integer,
|
Integer,
|
||||||
ForeignKey('post.id'),
|
ForeignKey('post.id'),
|
||||||
primary_key=True,
|
primary_key=True,
|
||||||
|
nullable=False,
|
||||||
index=True)
|
index=True)
|
||||||
|
|
||||||
def __init__(self, parent_id, child_id):
|
def __init__(self, parent_id, child_id):
|
||||||
|
@ -111,9 +117,15 @@ class PostTag(Base):
|
||||||
Integer,
|
Integer,
|
||||||
ForeignKey('post.id'),
|
ForeignKey('post.id'),
|
||||||
primary_key=True,
|
primary_key=True,
|
||||||
|
nullable=False,
|
||||||
index=True)
|
index=True)
|
||||||
tag_id = Column(
|
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):
|
def __init__(self, post_id, tag_id):
|
||||||
self.post_id = post_id
|
self.post_id = post_id
|
||||||
|
|
|
@ -19,7 +19,10 @@ class Snapshot(Base):
|
||||||
resource_repr = Column('resource_repr', Unicode(64), nullable=False)
|
resource_repr = Column('resource_repr', Unicode(64), nullable=False)
|
||||||
operation = Column('operation', Unicode(16), nullable=False)
|
operation = Column('operation', Unicode(16), nullable=False)
|
||||||
user_id = Column(
|
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)
|
data = Column('data', PickleType)
|
||||||
|
|
||||||
user = relationship('User')
|
user = relationship('User')
|
||||||
|
|
|
@ -13,12 +13,16 @@ class TagSuggestion(Base):
|
||||||
'parent_id',
|
'parent_id',
|
||||||
Integer,
|
Integer,
|
||||||
ForeignKey('tag.id'),
|
ForeignKey('tag.id'),
|
||||||
primary_key=True, index=True)
|
nullable=False,
|
||||||
|
primary_key=True,
|
||||||
|
index=True)
|
||||||
child_id = Column(
|
child_id = Column(
|
||||||
'child_id',
|
'child_id',
|
||||||
Integer,
|
Integer,
|
||||||
ForeignKey('tag.id'),
|
ForeignKey('tag.id'),
|
||||||
primary_key=True, index=True)
|
nullable=False,
|
||||||
|
primary_key=True,
|
||||||
|
index=True)
|
||||||
|
|
||||||
def __init__(self, parent_id, child_id):
|
def __init__(self, parent_id, child_id):
|
||||||
self.parent_id = parent_id
|
self.parent_id = parent_id
|
||||||
|
@ -32,12 +36,14 @@ class TagImplication(Base):
|
||||||
'parent_id',
|
'parent_id',
|
||||||
Integer,
|
Integer,
|
||||||
ForeignKey('tag.id'),
|
ForeignKey('tag.id'),
|
||||||
|
nullable=False,
|
||||||
primary_key=True,
|
primary_key=True,
|
||||||
index=True)
|
index=True)
|
||||||
child_id = Column(
|
child_id = Column(
|
||||||
'child_id',
|
'child_id',
|
||||||
Integer,
|
Integer,
|
||||||
ForeignKey('tag.id'),
|
ForeignKey('tag.id'),
|
||||||
|
nullable=False,
|
||||||
primary_key=True,
|
primary_key=True,
|
||||||
index=True)
|
index=True)
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue