server/db: fix mappings

Post notes had mixed up column types. I fixed that and at the same time,
I took the opportunity to convert everything into Unicode. Also, I've
changed existing migrations rather than creating new ones - it's not
like we're even close to alpha...
This commit is contained in:
rr- 2016-05-08 22:18:13 +02:00
parent 339c9a3333
commit 2330cf017d
14 changed files with 49 additions and 47 deletions

View file

@ -1,4 +1,4 @@
from sqlalchemy import Column, Integer, DateTime, Text, ForeignKey
from sqlalchemy import Column, Integer, DateTime, UnicodeText, ForeignKey
from sqlalchemy.orm import relationship, object_session
from sqlalchemy.sql.expression import func
from szurubooru.db.base import Base
@ -22,7 +22,7 @@ class Comment(Base):
user_id = Column('user_id', Integer, ForeignKey('user.id'))
creation_time = Column('creation_time', DateTime, nullable=False)
last_edit_time = Column('last_edit_time', DateTime)
text = Column('text', Text, default=None)
text = Column('text', UnicodeText, default=None)
user = relationship('User')
post = relationship('Post')

View file

@ -1,4 +1,5 @@
from sqlalchemy import Column, Integer, DateTime, String, Text, PickleType, ForeignKey
from sqlalchemy import (
Column, Integer, DateTime, Unicode, UnicodeText, PickleType, ForeignKey)
from sqlalchemy.orm import relationship, column_property, object_session
from sqlalchemy.sql.expression import func, select
from szurubooru.db.base import Base
@ -42,7 +43,7 @@ class PostNote(Base):
post_note_id = Column('id', Integer, primary_key=True)
post_id = Column('post_id', Integer, ForeignKey('post.id'), nullable=False)
polygon = Column('polygon', PickleType, nullable=False)
text = Column('text', Text, nullable=False)
text = Column('text', UnicodeText, nullable=False)
post = relationship('Post')
@ -62,9 +63,9 @@ class PostTag(Base):
post_id = Column('post_id', Integer, ForeignKey('post.id'), primary_key=True)
tag_id = Column('tag_id', Integer, ForeignKey('tag.id'), primary_key=True)
def __init__(self, tag_id, post_id):
self.tag_id = tag_id
def __init__(self, post_id, tag_id):
self.post_id = post_id
self.tag_id = tag_id
class Post(Base):
__tablename__ = 'post'
@ -72,6 +73,7 @@ class Post(Base):
SAFETY_SAFE = 'safe'
SAFETY_SKETCHY = 'sketchy'
SAFETY_UNSAFE = 'unsafe'
TYPE_IMAGE = 'image'
TYPE_ANIMATION = 'animation'
TYPE_VIDEO = 'video'
@ -82,17 +84,17 @@ class Post(Base):
user_id = Column('user_id', Integer, ForeignKey('user.id'))
creation_time = Column('creation_time', DateTime, nullable=False)
last_edit_time = Column('last_edit_time', DateTime)
safety = Column('safety', String(32), nullable=False)
source = Column('source', String(200))
safety = Column('safety', Unicode(32), nullable=False)
source = Column('source', Unicode(200))
flags = Column('flags', PickleType, default=None)
# content description
type = Column('type', String(32), nullable=False)
checksum = Column('checksum', String(64), nullable=False)
type = Column('type', Unicode(32), nullable=False)
checksum = Column('checksum', Unicode(64), nullable=False)
file_size = Column('file_size', Integer)
canvas_width = Column('image_width', Integer)
canvas_height = Column('image_height', Integer)
mime_type = Column('mime-type', String(32), nullable=False)
mime_type = Column('mime-type', Unicode(32), nullable=False)
# foreign tables
user = relationship('User')

View file

@ -1,4 +1,4 @@
from sqlalchemy import Column, Integer, DateTime, String, PickleType, ForeignKey
from sqlalchemy import Column, Integer, DateTime, Unicode, PickleType, ForeignKey
from sqlalchemy.orm import relationship
from szurubooru.db.base import Base
@ -11,10 +11,10 @@ class Snapshot(Base):
snapshot_id = Column('id', Integer, primary_key=True)
creation_time = Column('creation_time', DateTime, nullable=False)
resource_type = Column('resource_type', String(32), nullable=False)
resource_type = Column('resource_type', Unicode(32), nullable=False)
resource_id = Column('resource_id', Integer, nullable=False)
resource_repr = Column('resource_repr', String(64), nullable=False)
operation = Column('operation', String(16), nullable=False)
resource_repr = Column('resource_repr', Unicode(64), nullable=False)
operation = Column('operation', Unicode(16), nullable=False)
user_id = Column('user_id', Integer, ForeignKey('user.id'))
data = Column('data', PickleType)

View file

@ -1,4 +1,4 @@
from sqlalchemy import Column, Integer, DateTime, String, ForeignKey
from sqlalchemy import Column, Integer, DateTime, Unicode, ForeignKey
from sqlalchemy.orm import relationship, column_property
from sqlalchemy.sql.expression import func, select
from szurubooru.db.base import Base
@ -33,7 +33,7 @@ class TagName(Base):
tag_name_id = Column('tag_name_id', Integer, primary_key=True)
tag_id = Column('tag_id', Integer, ForeignKey('tag.id'), nullable=False)
name = Column('name', String(64), nullable=False, unique=True)
name = Column('name', Unicode(64), nullable=False, unique=True)
def __init__(self, name):
self.name = name

View file

@ -1,4 +1,4 @@
from sqlalchemy import Column, Integer, String, table
from sqlalchemy import Column, Integer, Unicode, table
from sqlalchemy.orm import column_property
from sqlalchemy.sql.expression import func, select
from szurubooru.db.base import Base
@ -8,8 +8,8 @@ class TagCategory(Base):
__tablename__ = 'tag_category'
tag_category_id = Column('id', Integer, primary_key=True)
name = Column('name', String(32), nullable=False)
color = Column('color', String(32), nullable=False, default='#000000')
name = Column('name', Unicode(32), nullable=False)
color = Column('color', Unicode(32), nullable=False, default='#000000')
def __init__(self, name=None):
self.name = name

View file

@ -1,4 +1,4 @@
from sqlalchemy import Column, Integer, String, DateTime
from sqlalchemy import Column, Integer, Unicode, DateTime
from szurubooru.db.base import Base
class User(Base):
@ -25,12 +25,12 @@ class User(Base):
]
user_id = Column('id', Integer, primary_key=True)
name = Column('name', String(50), nullable=False, unique=True)
password_hash = Column('password_hash', String(64), nullable=False)
password_salt = Column('password_salt', String(32))
email = Column('email', String(64), nullable=True)
rank = Column('rank', String(32), nullable=False)
name = Column('name', Unicode(50), nullable=False, unique=True)
password_hash = Column('password_hash', Unicode(64), nullable=False)
password_salt = Column('password_salt', Unicode(32))
email = Column('email', Unicode(64), nullable=True)
rank = Column('rank', Unicode(32), nullable=False)
creation_time = Column('creation_time', DateTime, nullable=False)
last_login_time = Column('last_login_time', DateTime)
avatar_style = Column(
'avatar_style', String(32), nullable=False, default=AVATAR_GRAVATAR)
'avatar_style', Unicode(32), nullable=False, default=AVATAR_GRAVATAR)

View file

@ -17,8 +17,8 @@ def upgrade():
op.create_table(
'tag_category',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('name', sa.String(length=32), nullable=False),
sa.Column('color', sa.String(length=32), nullable=False),
sa.Column('name', sa.Unicode(length=32), nullable=False),
sa.Column('color', sa.Unicode(length=32), nullable=False),
sa.PrimaryKeyConstraint('id'))
op.create_table(
@ -34,7 +34,7 @@ def upgrade():
'tag_name',
sa.Column('tag_name_id', sa.Integer(), nullable=False),
sa.Column('tag_id', sa.Integer(), nullable=False),
sa.Column('name', sa.String(length=64), nullable=False),
sa.Column('name', sa.Unicode(length=64), nullable=False),
sa.ForeignKeyConstraint(['tag_id'], ['tag.id']),
sa.PrimaryKeyConstraint('tag_name_id'),
sa.UniqueConstraint('name'))

View file

@ -14,7 +14,7 @@ branch_labels = None
depends_on = None
def upgrade():
op.add_column('post', sa.Column('mime-type', sa.String(length=32), nullable=False))
op.add_column('post', sa.Column('mime-type', sa.Unicode(length=32), nullable=False))
def downgrade():
op.drop_column('post', 'mime-type')

View file

@ -20,10 +20,10 @@ def upgrade():
sa.Column('user_id', sa.Integer(), nullable=True),
sa.Column('creation_time', sa.DateTime(), nullable=False),
sa.Column('last_edit_time', sa.DateTime(), nullable=True),
sa.Column('safety', sa.String(length=32), nullable=False),
sa.Column('type', sa.String(length=32), nullable=False),
sa.Column('checksum', sa.String(length=64), nullable=False),
sa.Column('source', sa.String(length=200), nullable=True),
sa.Column('safety', sa.Unicode(length=32), nullable=False),
sa.Column('type', sa.Unicode(length=32), nullable=False),
sa.Column('checksum', sa.Unicode(length=64), nullable=False),
sa.Column('source', sa.Unicode(length=200), nullable=True),
sa.Column('file_size', sa.Integer(), nullable=True),
sa.Column('image_width', sa.Integer(), nullable=True),
sa.Column('image_height', sa.Integer(), nullable=True),

View file

@ -16,7 +16,7 @@ depends_on = None
def upgrade():
op.add_column(
'snapshot',
sa.Column('resource_repr', sa.String(length=64), nullable=False))
sa.Column('resource_repr', sa.Unicode(length=64), nullable=False))
def downgrade():
op.drop_column('snapshot', 'resource_repr')

View file

@ -21,7 +21,7 @@ def upgrade():
sa.Column('post_id', sa.Integer(), nullable=False),
sa.Column('creation_time', sa.DateTime(), nullable=False),
sa.Column('last_edit_time', sa.DateTime(), nullable=True),
sa.Column('text', sa.Text(), nullable=True),
sa.Column('text', sa.UnicodeText(), nullable=True),
sa.ForeignKeyConstraint(['user_id'], ['user.id']),
sa.ForeignKeyConstraint(['post_id'], ['post.id']),
sa.PrimaryKeyConstraint('id'))

View file

@ -18,9 +18,9 @@ def upgrade():
'snapshot',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('creation_time', sa.DateTime(), nullable=False),
sa.Column('resource_type', sa.String(length=32), nullable=False),
sa.Column('resource_type', sa.Unicode(length=32), nullable=False),
sa.Column('resource_id', sa.Integer(), nullable=False),
sa.Column('operation', sa.String(length=16), nullable=False),
sa.Column('operation', sa.Unicode(length=16), nullable=False),
sa.Column('user_id', sa.Integer(), nullable=True),
sa.Column('data', sa.PickleType(), nullable=True),
sa.ForeignKeyConstraint(['user_id'], ['user.id']),

View file

@ -37,8 +37,8 @@ def upgrade():
'post_note',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('post_id', sa.Integer(), nullable=False),
sa.Column('text', sa.PickleType(), nullable=False),
sa.Column('polygon', sa.Text(), nullable=False),
sa.Column('text', sa.UnicodeText(), nullable=False),
sa.Column('polygon', sa.PickleType(), nullable=False),
sa.ForeignKeyConstraint(['post_id'], ['post.id']),
sa.PrimaryKeyConstraint('id'))

View file

@ -17,14 +17,14 @@ def upgrade():
op.create_table(
'user',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('name', sa.String(length=50), nullable=False),
sa.Column('password_hash', sa.String(length=64), nullable=False),
sa.Column('password_salt', sa.String(length=32), nullable=True),
sa.Column('email', sa.String(length=64), nullable=True),
sa.Column('rank', sa.String(length=32), nullable=False),
sa.Column('name', sa.Unicode(length=50), nullable=False),
sa.Column('password_hash', sa.Unicode(length=64), nullable=False),
sa.Column('password_salt', sa.Unicode(length=32), nullable=True),
sa.Column('email', sa.Unicode(length=64), nullable=True),
sa.Column('rank', sa.Unicode(length=32), nullable=False),
sa.Column('creation_time', sa.DateTime(), nullable=False),
sa.Column('last_login_time', sa.DateTime()),
sa.Column('avatar_style', sa.String(length=32), nullable=False),
sa.Column('avatar_style', sa.Unicode(length=32), nullable=False),
sa.PrimaryKeyConstraint('id'))
op.create_unique_constraint('uq_user_name', 'user', ['name'])