1
1
Fork 0

Fixed™ enums, so I can finally modify them

dev
Jan Kužílek 5 years ago
parent 82e5c449bb
commit c0efbc96cd

@ -1,8 +1,8 @@
"""empty message """initial scheme
Revision ID: f4e1b4727000 Revision ID: 71386dc42f9b
Revises: Revises:
Create Date: 2020-03-09 12:32:25.827118 Create Date: 2020-03-16 00:26:18.607144
""" """
from alembic import op from alembic import op
@ -11,7 +11,7 @@ import sqlalchemy_utc
# revision identifiers, used by Alembic. # revision identifiers, used by Alembic.
revision = 'f4e1b4727000' revision = '71386dc42f9b'
down_revision = None down_revision = None
branch_labels = None branch_labels = None
depends_on = 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('updated', sqlalchemy_utc.sqltypes.UtcDateTime(timezone=True), server_default=sa.text('CURRENT_TIMESTAMP'), nullable=False),
sa.Column('id', sa.Integer(), nullable=False), sa.Column('id', sa.Integer(), nullable=False),
sa.Column('content', sa.String(length=128), 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.PrimaryKeyConstraint('id'),
sa.UniqueConstraint('content') sa.UniqueConstraint('content')
) )
@ -35,9 +35,13 @@ def upgrade():
sa.Column('username', sa.String(length=128), nullable=False), sa.Column('username', sa.String(length=128), nullable=False),
sa.Column('email', sa.String(length=256), nullable=True), sa.Column('email', sa.String(length=256), nullable=True),
sa.Column('pass_hash', sa.String(length=128), 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('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'), 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('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.PrimaryKeyConstraint('id'),
sa.UniqueConstraint('email'), sa.UniqueConstraint('email'),
sa.UniqueConstraint('username') 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('updated', sqlalchemy_utc.sqltypes.UtcDateTime(timezone=True), server_default=sa.text('CURRENT_TIMESTAMP'), nullable=False),
sa.Column('id', sa.Integer(), nullable=False), sa.Column('id', sa.Integer(), nullable=False),
sa.Column('md5', sa.String(length=32), nullable=False), sa.Column('md5', sa.String(length=32), nullable=False),
sa.Column('filetype', sa.Enum('png', 'jpeg', name='filetype'), 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'), 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'), 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('width', sa.Integer(), nullable=True),
sa.Column('height', sa.Integer(), nullable=True), sa.Column('height', sa.Integer(), nullable=True),
sa.Column('filesize', sa.Integer(), nullable=True), sa.Column('filesize', sa.Integer(), nullable=True),
@ -62,6 +66,12 @@ def upgrade():
sa.PrimaryKeyConstraint('id'), sa.PrimaryKeyConstraint('id'),
sa.UniqueConstraint('md5') 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', op.create_table('comment',
sa.Column('created', sqlalchemy_utc.sqltypes.UtcDateTime(timezone=True), server_default=sa.text('CURRENT_TIMESTAMP'), nullable=False), 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), 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! ### # ### commands auto generated by Alembic - please adjust! ###
op.drop_table('post_tags') op.drop_table('post_tags')
op.drop_table('comment') op.drop_table('comment')
op.drop_table('user_tags_blacklist')
op.drop_table('post') op.drop_table('post')
op.drop_table('user') op.drop_table('user')
op.drop_table('tag') op.drop_table('tag')

@ -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 ###

@ -80,8 +80,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), server_default=OP_LEVEL.user.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), server_default=USER_STATUS.active.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) last_login = db.Column(UtcDateTime)
ban_until = db.Column(UtcDateTime) ban_until = db.Column(UtcDateTime)
@ -89,7 +89,7 @@ class User(UserMixin, TimestampMixin, db.Model):
biography = db.Column(db.String(512)) 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')) tag_blacklist = db.relationship('Tag', secondary=user_tags_blacklist, backref=db.backref('user_blacklisted'))
def __repr__(self): def __repr__(self):
@ -163,9 +163,9 @@ post_tags = db.Table('post_tags', db.metadata,
class Post(TimestampMixin, db.Model): class Post(TimestampMixin, db.Model):
id = db.Column(db.Integer, primary_key=True) id = db.Column(db.Integer, primary_key=True)
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, native_enum=False, create_constraint=False), nullable=False)
rating = db.Column(db.Enum(RATING), nullable=False) rating = db.Column(db.Enum(RATING, native_enum=False, create_constraint=False), nullable=False)
status = db.Column(db.Enum(POST_STATUS), server_default=POST_STATUS.pending.name, 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) width = db.Column(db.Integer, default=0)
height = 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): 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), 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 @property
def content_deser(self): def content_deser(self):

Loading…
Cancel
Save