1
1
Fork 0

let's try server_default lol

dev
Jan Kužílek 5 years ago
parent 9fb30c8a58
commit 69be48e569

@ -56,8 +56,8 @@ class TAG_CATEGORY(enum.Enum):
# deleted = 2 # deleted = 2
class TimestampMixin(object): class TimestampMixin(object):
created = db.Column(UtcDateTime, nullable=False, default=utcnow()) created = db.Column(UtcDateTime, nullable=False, server_default=utcnow())
updated = db.Column(UtcDateTime, nullable=False, onupdate=utcnow(), default=utcnow()) updated = db.Column(UtcDateTime, nullable=False, onupdate=utcnow(), server_default=utcnow())
def natural_created(self): def natural_created(self):
return humanize.naturaltime(datetime.now().astimezone(self.created.tzinfo) - self.created) return humanize.naturaltime(datetime.now().astimezone(self.created.tzinfo) - self.created)
@ -70,8 +70,8 @@ class User(UserMixin, TimestampMixin, db.Model):
username = db.Column(db.String(128), unique=True, nullable=False) username = db.Column(db.String(128), unique=True, nullable=False)
email = db.Column(db.String(256), unique=True) email = db.Column(db.String(256), unique=True)
pass_hash = db.Column(db.String(128)) pass_hash = db.Column(db.String(128))
op_level = db.Column(db.Enum(OP_LEVEL), default=OP_LEVEL.user, nullable=False) op_level = db.Column(db.Enum(OP_LEVEL), server_default=OP_LEVEL.user, nullable=False)
user_status = db.Column(db.Enum(USER_STATUS), default=USER_STATUS.active, nullable=False) user_status = db.Column(db.Enum(USER_STATUS), server_default=USER_STATUS.active, nullable=False)
last_login = db.Column(UtcDateTime) last_login = db.Column(UtcDateTime)
ban_status = None ban_status = None
@ -130,11 +130,11 @@ class Post(TimestampMixin, db.Model):
md5 = db.Column(db.String(32), unique=True, nullable=False) md5 = db.Column(db.String(32), unique=True, nullable=False)
filetype = db.Column(db.Enum(FILETYPE), nullable=False) filetype = db.Column(db.Enum(FILETYPE), nullable=False)
rating = db.Column(db.Enum(RATING), nullable=False) rating = db.Column(db.Enum(RATING), nullable=False)
status = db.Column(db.Enum(POST_STATUS), default=POST_STATUS.pending, nullable=False) status = db.Column(db.Enum(POST_STATUS), server_default=POST_STATUS.pending, nullable=False)
width = db.Column(db.Integer, default=0) width = db.Column(db.Integer, server_default=0)
height = db.Column(db.Integer, default=0) height = db.Column(db.Integer, server_default=0)
filesize = db.Column(db.Integer, default=0) filesize = db.Column(db.Integer, server_default=0)
source = db.Column(db.String(2048)) source = db.Column(db.String(2048))
origin_filename = db.Column(db.String(255)) origin_filename = db.Column(db.String(255))
@ -227,7 +227,7 @@ class Post(TimestampMixin, db.Model):
class Tag(TimestampMixin, db.Model): class Tag(TimestampMixin, db.Model):
id = db.Column(db.Integer, primary_key=True) id = db.Column(db.Integer, primary_key=True)
content = db.Column(db.String(128), unique=True, nullable=False) content = db.Column(db.String(128), unique=True, nullable=False)
category = db.Column(db.Enum(TAG_CATEGORY), default=TAG_CATEGORY.general) category = db.Column(db.Enum(TAG_CATEGORY), server_default=TAG_CATEGORY.general)
#posts = db.relationship('Post', secondary=post_tags, back_populates='tags') #posts = db.relationship('Post', secondary=post_tags, back_populates='tags')
@ -243,7 +243,7 @@ class Comment(TimestampMixin, db.Model):
content = db.Column(db.String(512), nullable=False) content = db.Column(db.String(512), nullable=False)
# status = db.Column(db.Enum(COMMENT_STATUS), default=COMMENT_STATUS.visible) # status = db.Column(db.Enum(COMMENT_STATUS), default=COMMENT_STATUS.visible)
deleted = db.Column(db.Boolean, default=False) deleted = db.Column(db.Boolean, server_default=False)
delete_reason = db.Column(db.String(512)) delete_reason = db.Column(db.String(512))
post_id = db.Column(db.Integer, db.ForeignKey('post.id')) post_id = db.Column(db.Integer, db.ForeignKey('post.id'))

Loading…
Cancel
Save