From 2330cf017ded0a47ead92066cae4ae9c479bc51d Mon Sep 17 00:00:00 2001 From: rr- Date: Sun, 8 May 2016 22:18:13 +0200 Subject: [PATCH] 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... --- server/szurubooru/db/comment.py | 4 ++-- server/szurubooru/db/post.py | 20 ++++++++++--------- server/szurubooru/db/snapshot.py | 8 ++++---- server/szurubooru/db/tag.py | 4 ++-- server/szurubooru/db/tag_category.py | 6 +++--- server/szurubooru/db/user.py | 14 ++++++------- .../00cb3a2734db_create_tag_tables.py | 6 +++--- .../23abaf4a0a4b_add_mime_type_to_posts.py | 2 +- .../336a76ec1338_create_post_tables.py | 8 ++++---- ...46cd5229839b_add_snapshot_resource_repr.py | 2 +- .../46df355634dc_add_comment_tables.py | 2 +- .../565e01e3cf6d_create_snapshot_table.py | 4 ++-- .../9587de88a84b_create_aux_post_tables.py | 4 ++-- .../e5c1216a8503_create_user_table.py | 12 +++++------ 14 files changed, 49 insertions(+), 47 deletions(-) diff --git a/server/szurubooru/db/comment.py b/server/szurubooru/db/comment.py index c40e6e1..3367026 100644 --- a/server/szurubooru/db/comment.py +++ b/server/szurubooru/db/comment.py @@ -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') diff --git a/server/szurubooru/db/post.py b/server/szurubooru/db/post.py index 081e97f..18e2eb5 100644 --- a/server/szurubooru/db/post.py +++ b/server/szurubooru/db/post.py @@ -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') diff --git a/server/szurubooru/db/snapshot.py b/server/szurubooru/db/snapshot.py index cd9af7a..276f914 100644 --- a/server/szurubooru/db/snapshot.py +++ b/server/szurubooru/db/snapshot.py @@ -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) diff --git a/server/szurubooru/db/tag.py b/server/szurubooru/db/tag.py index f54a03e..555e3d7 100644 --- a/server/szurubooru/db/tag.py +++ b/server/szurubooru/db/tag.py @@ -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 diff --git a/server/szurubooru/db/tag_category.py b/server/szurubooru/db/tag_category.py index 1a4acd7..d60965f 100644 --- a/server/szurubooru/db/tag_category.py +++ b/server/szurubooru/db/tag_category.py @@ -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 diff --git a/server/szurubooru/db/user.py b/server/szurubooru/db/user.py index 02e2ed6..48ee444 100644 --- a/server/szurubooru/db/user.py +++ b/server/szurubooru/db/user.py @@ -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) diff --git a/server/szurubooru/migrations/versions/00cb3a2734db_create_tag_tables.py b/server/szurubooru/migrations/versions/00cb3a2734db_create_tag_tables.py index 4cfde40..ccdcb88 100644 --- a/server/szurubooru/migrations/versions/00cb3a2734db_create_tag_tables.py +++ b/server/szurubooru/migrations/versions/00cb3a2734db_create_tag_tables.py @@ -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')) diff --git a/server/szurubooru/migrations/versions/23abaf4a0a4b_add_mime_type_to_posts.py b/server/szurubooru/migrations/versions/23abaf4a0a4b_add_mime_type_to_posts.py index 8ac336e..e6d06f0 100644 --- a/server/szurubooru/migrations/versions/23abaf4a0a4b_add_mime_type_to_posts.py +++ b/server/szurubooru/migrations/versions/23abaf4a0a4b_add_mime_type_to_posts.py @@ -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') diff --git a/server/szurubooru/migrations/versions/336a76ec1338_create_post_tables.py b/server/szurubooru/migrations/versions/336a76ec1338_create_post_tables.py index 6f397c5..2fc0e16 100644 --- a/server/szurubooru/migrations/versions/336a76ec1338_create_post_tables.py +++ b/server/szurubooru/migrations/versions/336a76ec1338_create_post_tables.py @@ -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), diff --git a/server/szurubooru/migrations/versions/46cd5229839b_add_snapshot_resource_repr.py b/server/szurubooru/migrations/versions/46cd5229839b_add_snapshot_resource_repr.py index 819f947..a33273e 100644 --- a/server/szurubooru/migrations/versions/46cd5229839b_add_snapshot_resource_repr.py +++ b/server/szurubooru/migrations/versions/46cd5229839b_add_snapshot_resource_repr.py @@ -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') diff --git a/server/szurubooru/migrations/versions/46df355634dc_add_comment_tables.py b/server/szurubooru/migrations/versions/46df355634dc_add_comment_tables.py index 0a8965a..6e8f805 100644 --- a/server/szurubooru/migrations/versions/46df355634dc_add_comment_tables.py +++ b/server/szurubooru/migrations/versions/46df355634dc_add_comment_tables.py @@ -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')) diff --git a/server/szurubooru/migrations/versions/565e01e3cf6d_create_snapshot_table.py b/server/szurubooru/migrations/versions/565e01e3cf6d_create_snapshot_table.py index 2f43e3a..e2eefb6 100644 --- a/server/szurubooru/migrations/versions/565e01e3cf6d_create_snapshot_table.py +++ b/server/szurubooru/migrations/versions/565e01e3cf6d_create_snapshot_table.py @@ -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']), diff --git a/server/szurubooru/migrations/versions/9587de88a84b_create_aux_post_tables.py b/server/szurubooru/migrations/versions/9587de88a84b_create_aux_post_tables.py index 983ea94..769e873 100644 --- a/server/szurubooru/migrations/versions/9587de88a84b_create_aux_post_tables.py +++ b/server/szurubooru/migrations/versions/9587de88a84b_create_aux_post_tables.py @@ -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')) diff --git a/server/szurubooru/migrations/versions/e5c1216a8503_create_user_table.py b/server/szurubooru/migrations/versions/e5c1216a8503_create_user_table.py index b1e01ba..a9c0fb1 100644 --- a/server/szurubooru/migrations/versions/e5c1216a8503_create_user_table.py +++ b/server/szurubooru/migrations/versions/e5c1216a8503_create_user_table.py @@ -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'])