From 2d17519f792d25a01572354a24f8fd75f09e00c6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Ku=C5=BE=C3=ADlek?= Date: Tue, 3 Mar 2020 15:57:40 +0100 Subject: [PATCH] Better (init) manage script, and server_default only for timestamps --- init.sh | 30 ---------------------------- manage.sh | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++ yadc/models.py | 16 +++++++-------- 3 files changed, 62 insertions(+), 38 deletions(-) delete mode 100644 init.sh create mode 100644 manage.sh diff --git a/init.sh b/init.sh deleted file mode 100644 index 1b752cf..0000000 --- a/init.sh +++ /dev/null @@ -1,30 +0,0 @@ -#!/bin/bash -export FLASK_APP=yadc -root="." - -createdirs() { - mkdir -p instance - mkdir -p instance/post/img - mkdir -p instance/post/jpeg - mkdir -p instance/post/sample - mkdir -p instance/post/thumb -} -prepare_instance() { - python3 -m pipenv install - - createdirs - cp yadc/config.def.py instance/config.py -} - -prepare_db() { - python3 -m pipenv run flask upgrade -} - -case $1 in - "instance"|"") - prepare_instance - ;; - "db") - prepare_db - ;; -esac \ No newline at end of file diff --git a/manage.sh b/manage.sh new file mode 100644 index 0000000..c006dc3 --- /dev/null +++ b/manage.sh @@ -0,0 +1,54 @@ +#!/bin/bash +export FLASK_APP=yadc +root="." + +pipenv="python3 -m pipenv" +run="$pipenv run" + +prepare_venv() { $pipenv install } + +prepare_instance() { + mkdir -p instance + mkdir -p instance/post/img + mkdir -p instance/post/jpeg + mkdir -p instance/post/sample + mkdir -p instance/post/thumb + + cp yadc/config.def.py instance/config.py +} + +prepare_db() { + $run flask upgrade +} + +gunicorn_run() { + $run gunicorn yadc:app +} + +case $1 in + "init_venv") + prepare_venv + ;; + "init_instance") + prepare_instance + ;; + "init_db") + prepare_db + ;; + "init") + prepare_venv + prepare_instance + prepare_db + ;; + "run") + gunicorn_run + ;; + "") + echo "useable parameters:" + echo " run - run gunicorn listener" + echo " init - complete init" + echo " init_venv" + echo " init_instance" + echo " init_db" + ;; +esac \ No newline at end of file diff --git a/yadc/models.py b/yadc/models.py index 38aa395..3a20177 100644 --- a/yadc/models.py +++ b/yadc/models.py @@ -70,8 +70,8 @@ class User(UserMixin, TimestampMixin, db.Model): username = db.Column(db.String(128), unique=True, nullable=False) email = db.Column(db.String(256), unique=True) pass_hash = db.Column(db.String(128)) - op_level = db.Column(db.Enum(OP_LEVEL), server_default=OP_LEVEL.user, nullable=False) - user_status = db.Column(db.Enum(USER_STATUS), server_default=USER_STATUS.active, nullable=False) + op_level = db.Column(db.Enum(OP_LEVEL), default=OP_LEVEL.user, nullable=False) + user_status = db.Column(db.Enum(USER_STATUS), default=USER_STATUS.active, nullable=False) last_login = db.Column(UtcDateTime) ban_status = None @@ -130,11 +130,11 @@ class Post(TimestampMixin, db.Model): md5 = db.Column(db.String(32), unique=True, nullable=False) filetype = db.Column(db.Enum(FILETYPE), nullable=False) rating = db.Column(db.Enum(RATING), nullable=False) - status = db.Column(db.Enum(POST_STATUS), server_default=POST_STATUS.pending, nullable=False) + status = db.Column(db.Enum(POST_STATUS), default=POST_STATUS.pending, nullable=False) - width = db.Column(db.Integer, server_default=0) - height = db.Column(db.Integer, server_default=0) - filesize = db.Column(db.Integer, server_default=0) + width = db.Column(db.Integer, default=0) + height = db.Column(db.Integer, default=0) + filesize = db.Column(db.Integer, default=0) source = db.Column(db.String(2048)) origin_filename = db.Column(db.String(255)) @@ -227,7 +227,7 @@ class Post(TimestampMixin, db.Model): class Tag(TimestampMixin, db.Model): id = db.Column(db.Integer, primary_key=True) content = db.Column(db.String(128), unique=True, nullable=False) - category = db.Column(db.Enum(TAG_CATEGORY), server_default=TAG_CATEGORY.general) + category = db.Column(db.Enum(TAG_CATEGORY), default=TAG_CATEGORY.general) #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) # status = db.Column(db.Enum(COMMENT_STATUS), default=COMMENT_STATUS.visible) - deleted = db.Column(db.Boolean, server_default=False) + deleted = db.Column(db.Boolean, default=False) delete_reason = db.Column(db.String(512)) post_id = db.Column(db.Integer, db.ForeignKey('post.id'))