From c0efbc96cd4da1258d58e182b1ede22a7dd4b6ca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Ku=C5=BE=C3=ADlek?= Date: Mon, 16 Mar 2020 00:38:33 +0100 Subject: [PATCH] =?UTF-8?q?Fixed=E2=84=A2=20enums,=20so=20I=20can=20finall?= =?UTF-8?q?y=20modify=20them?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...000_.py => 71386dc42f9b_initial_scheme.py} | 31 ++++++++---- migrations/versions/b1a3eed8e38f_.py | 47 ------------------- yadc/models.py | 14 +++--- 3 files changed, 28 insertions(+), 64 deletions(-) rename migrations/versions/{f4e1b4727000_.py => 71386dc42f9b_initial_scheme.py} (77%) delete mode 100644 migrations/versions/b1a3eed8e38f_.py diff --git a/migrations/versions/f4e1b4727000_.py b/migrations/versions/71386dc42f9b_initial_scheme.py similarity index 77% rename from migrations/versions/f4e1b4727000_.py rename to migrations/versions/71386dc42f9b_initial_scheme.py index ee8c221..880e243 100644 --- a/migrations/versions/f4e1b4727000_.py +++ b/migrations/versions/71386dc42f9b_initial_scheme.py @@ -1,8 +1,8 @@ -"""empty message +"""initial scheme -Revision ID: f4e1b4727000 +Revision ID: 71386dc42f9b Revises: -Create Date: 2020-03-09 12:32:25.827118 +Create Date: 2020-03-16 00:26:18.607144 """ from alembic import op @@ -11,7 +11,7 @@ import sqlalchemy_utc # revision identifiers, used by Alembic. -revision = 'f4e1b4727000' +revision = '71386dc42f9b' down_revision = None branch_labels = None depends_on = None @@ -24,7 +24,7 @@ def upgrade(): sa.Column('updated', sqlalchemy_utc.sqltypes.UtcDateTime(timezone=True), server_default=sa.text('CURRENT_TIMESTAMP'), nullable=False), sa.Column('id', sa.Integer(), nullable=False), sa.Column('content', sa.String(length=128), nullable=False), - sa.Column('category', sa.Enum('general', 'style', 'circle', 'artist', 'character', 'copyright', name='tag_category'), nullable=False), + sa.Column('category', sa.Enum('general', 'style', 'circle', 'artist', 'character', 'copyright', name='tag_category', native_enum=False), server_default='general', nullable=False), sa.PrimaryKeyConstraint('id'), sa.UniqueConstraint('content') ) @@ -35,9 +35,13 @@ def upgrade(): sa.Column('username', sa.String(length=128), nullable=False), sa.Column('email', sa.String(length=256), nullable=True), sa.Column('pass_hash', sa.String(length=128), nullable=True), - sa.Column('op_level', sa.Enum('user', 'creator', 'moderator', 'admin', name='op_level'), nullable=False), - sa.Column('user_status', sa.Enum('active', 'inactive', 'banned', name='user_status'), nullable=False), + sa.Column('op_level', sa.Enum('user', 'creator', 'moderator', 'admin', name='op_level', native_enum=False), server_default='user', nullable=False), + sa.Column('user_status', sa.Enum('active', 'inactive', 'banned', name='user_status', native_enum=False), server_default='active', nullable=False), sa.Column('last_login', sqlalchemy_utc.sqltypes.UtcDateTime(timezone=True), nullable=True), + sa.Column('ban_until', sqlalchemy_utc.sqltypes.UtcDateTime(timezone=True), nullable=True), + sa.Column('ban_reason', sa.String(length=512), nullable=True), + sa.Column('biography', sa.String(length=512), nullable=True), + sa.Column('rating', sa.Enum('safe', 'questionable', 'explicit', name='rating', native_enum=False), server_default='safe', nullable=False), sa.PrimaryKeyConstraint('id'), sa.UniqueConstraint('email'), sa.UniqueConstraint('username') @@ -47,9 +51,9 @@ def upgrade(): sa.Column('updated', sqlalchemy_utc.sqltypes.UtcDateTime(timezone=True), server_default=sa.text('CURRENT_TIMESTAMP'), nullable=False), sa.Column('id', sa.Integer(), nullable=False), sa.Column('md5', sa.String(length=32), nullable=False), - sa.Column('filetype', sa.Enum('png', 'jpeg', name='filetype'), nullable=False), - sa.Column('rating', sa.Enum('safe', 'questionable', 'explicit', name='rating'), nullable=False), - sa.Column('status', sa.Enum('pending', 'active', 'deleted', name='post_status'), nullable=False), + sa.Column('filetype', sa.Enum('png', 'jpeg', name='filetype', native_enum=False), nullable=False), + sa.Column('rating', sa.Enum('safe', 'questionable', 'explicit', name='rating', native_enum=False), nullable=False), + sa.Column('status', sa.Enum('pending', 'active', 'deleted', name='post_status', native_enum=False), server_default='pending', nullable=False), sa.Column('width', sa.Integer(), nullable=True), sa.Column('height', sa.Integer(), nullable=True), sa.Column('filesize', sa.Integer(), nullable=True), @@ -62,6 +66,12 @@ def upgrade(): sa.PrimaryKeyConstraint('id'), sa.UniqueConstraint('md5') ) + op.create_table('user_tags_blacklist', + sa.Column('user_id', sa.Integer(), nullable=True), + sa.Column('tag_id', sa.Integer(), nullable=True), + sa.ForeignKeyConstraint(['tag_id'], ['tag.id'], ), + sa.ForeignKeyConstraint(['user_id'], ['user.id'], ) + ) op.create_table('comment', sa.Column('created', sqlalchemy_utc.sqltypes.UtcDateTime(timezone=True), server_default=sa.text('CURRENT_TIMESTAMP'), nullable=False), sa.Column('updated', sqlalchemy_utc.sqltypes.UtcDateTime(timezone=True), server_default=sa.text('CURRENT_TIMESTAMP'), nullable=False), @@ -88,6 +98,7 @@ def downgrade(): # ### commands auto generated by Alembic - please adjust! ### op.drop_table('post_tags') op.drop_table('comment') + op.drop_table('user_tags_blacklist') op.drop_table('post') op.drop_table('user') op.drop_table('tag') diff --git a/migrations/versions/b1a3eed8e38f_.py b/migrations/versions/b1a3eed8e38f_.py deleted file mode 100644 index 4fb947e..0000000 --- a/migrations/versions/b1a3eed8e38f_.py +++ /dev/null @@ -1,47 +0,0 @@ -"""empty message - -Revision ID: b1a3eed8e38f -Revises: f4e1b4727000 -Create Date: 2020-03-09 23:58:53.716242 - -""" -from alembic import op -import sqlalchemy as sa -import sqlalchemy_utc - - -# revision identifiers, used by Alembic. -revision = 'b1a3eed8e38f' -down_revision = 'f4e1b4727000' -branch_labels = None -depends_on = None - - -def upgrade(): - # ### commands auto generated by Alembic - please adjust! ### - op.create_table('user_tags_blacklist', - sa.Column('user_id', sa.Integer(), nullable=True), - sa.Column('tag_id', sa.Integer(), nullable=True), - sa.ForeignKeyConstraint(['tag_id'], ['tag.id'], ), - sa.ForeignKeyConstraint(['user_id'], ['user.id'], ) - ) - op.add_column('user', sa.Column('ban_reason', sa.String(length=512), nullable=True)) - op.add_column('user', sa.Column('ban_until', sqlalchemy_utc.sqltypes.UtcDateTime(timezone=True), nullable=True)) - op.add_column('user', sa.Column('biography', sa.String(length=512), nullable=True)) - op.add_column('user', sa.Column('rating', sa.Enum('safe', 'questionable', 'explicit', name='rating'), server_default='safe', nullable=False)) - - op.alter_column('user', 'op_level', server_default='user') - op.alter_column('user', 'user_status', server_default='active') - op.alter_column('post', 'status', server_default='pending') - op.alter_column('tag', 'category', server_default='general') - # ### end Alembic commands ### - - -def downgrade(): - # ### commands auto generated by Alembic - please adjust! ### - op.drop_column('user', 'rating') - op.drop_column('user', 'biography') - op.drop_column('user', 'ban_until') - op.drop_column('user', 'ban_reason') - op.drop_table('user_tags_blacklist') - # ### end Alembic commands ### diff --git a/yadc/models.py b/yadc/models.py index 77c41fc..bb48c2b 100644 --- a/yadc/models.py +++ b/yadc/models.py @@ -80,8 +80,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.name, nullable=False) - user_status = db.Column(db.Enum(USER_STATUS), server_default=USER_STATUS.active.name, nullable=False) + op_level = db.Column(db.Enum(OP_LEVEL, native_enum=False, create_constraint=False), server_default=OP_LEVEL.user.name, nullable=False) + user_status = db.Column(db.Enum(USER_STATUS, native_enum=False, create_constraint=False), server_default=USER_STATUS.active.name, nullable=False) last_login = db.Column(UtcDateTime) ban_until = db.Column(UtcDateTime) @@ -89,7 +89,7 @@ class User(UserMixin, TimestampMixin, db.Model): biography = db.Column(db.String(512)) - rating = db.Column(db.Enum(RATING), server_default=RATING.safe.name, nullable=False) + rating = db.Column(db.Enum(RATING, native_enum=False, create_constraint=False), server_default=RATING.safe.name, nullable=False) tag_blacklist = db.relationship('Tag', secondary=user_tags_blacklist, backref=db.backref('user_blacklisted')) def __repr__(self): @@ -163,9 +163,9 @@ post_tags = db.Table('post_tags', db.metadata, class Post(TimestampMixin, db.Model): id = db.Column(db.Integer, primary_key=True) 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.name, nullable=False) + filetype = db.Column(db.Enum(FILETYPE, native_enum=False, create_constraint=False), nullable=False) + rating = db.Column(db.Enum(RATING, native_enum=False, create_constraint=False), nullable=False) + status = db.Column(db.Enum(POST_STATUS, native_enum=False, create_constraint=False), server_default=POST_STATUS.pending.name, nullable=False) width = db.Column(db.Integer, default=0) height = db.Column(db.Integer, default=0) @@ -278,7 +278,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.name, nullable=False) + category = db.Column(db.Enum(TAG_CATEGORY, native_enum=False, create_constraint=False), server_default=TAG_CATEGORY.general.name, nullable=False) @property def content_deser(self):