From 82db716b61eb1e7ac6488f215bfdf10ccb7b63ea Mon Sep 17 00:00:00 2001 From: "Jeremy \"EndenDragon\" Zhang" Date: Sun, 9 Jul 2017 17:15:45 -0700 Subject: [PATCH] Moved some text fields over to longtext type (#21) --- discordbot/titanembeds/database/guilds.py | 8 +- webapp/alembic/env.py | 3 +- ...oved_some_text_columns_to_longtext_type.py | 142 ++++++++++++++++++ webapp/titanembeds/database/guilds.py | 8 +- webapp/titanembeds/database/user_css.py | 2 +- 5 files changed, 153 insertions(+), 10 deletions(-) create mode 100644 webapp/alembic/versions/40cbd3e0f22d_moved_some_text_columns_to_longtext_type.py diff --git a/discordbot/titanembeds/database/guilds.py b/discordbot/titanembeds/database/guilds.py index f8c0169..b391b74 100644 --- a/discordbot/titanembeds/database/guilds.py +++ b/discordbot/titanembeds/database/guilds.py @@ -10,10 +10,10 @@ class Guilds(Base): chat_links = db.Column(db.Boolean()) # If users can post links bracket_links = db.Column(db.Boolean()) # If appending brackets to links to prevent embed mentions_limit = db.Column(db.Integer) # If there is a limit on the number of mentions in a msg - roles = db.Column(db.Text()) # Guild Roles - channels = db.Column(db.Text()) # Guild channels - webhooks = db.Column(db.Text()) # Guild webhooks - emojis = db.Column(db.Text()) # Guild Emojis + roles = db.Column(db.Text(length=4294967295)) # Guild Roles + channels = db.Column(db.Text(length=4294967295))# Guild channels + webhooks = db.Column(db.Text(length=4294967295))# Guild webhooks + emojis = db.Column(db.Text(length=4294967295)) # Guild Emojis owner_id = db.Column(db.String(255)) # Snowflake of the owner icon = db.Column(db.String(255)) # The icon string, null if none discordio = db.Column(db.String(255)) # Custom Discord.io Invite Link diff --git a/webapp/alembic/env.py b/webapp/alembic/env.py index 8060c76..4415561 100644 --- a/webapp/alembic/env.py +++ b/webapp/alembic/env.py @@ -64,7 +64,8 @@ def run_migrations_online(): with connectable.connect() as connection: context.configure( connection=connection, - target_metadata=target_metadata + target_metadata=target_metadata, + compare_type=True ) with context.begin_transaction(): diff --git a/webapp/alembic/versions/40cbd3e0f22d_moved_some_text_columns_to_longtext_type.py b/webapp/alembic/versions/40cbd3e0f22d_moved_some_text_columns_to_longtext_type.py new file mode 100644 index 0000000..93419b3 --- /dev/null +++ b/webapp/alembic/versions/40cbd3e0f22d_moved_some_text_columns_to_longtext_type.py @@ -0,0 +1,142 @@ +"""Moved some text columns to longtext type + +Revision ID: 40cbd3e0f22d +Revises: 9bf2adbc33e8 +Create Date: 2017-07-10 00:01:53.940034 + +""" + +# revision identifiers, used by Alembic. +revision = '40cbd3e0f22d' +down_revision = '9bf2adbc33e8' +branch_labels = None +depends_on = None + +from alembic import op +import sqlalchemy as sa +from sqlalchemy.dialects import mysql + +def upgrade(): + # ### commands auto generated by Alembic - please adjust! ### + op.alter_column('cosmetics', 'css', + existing_type=mysql.TINYINT(display_width=1), + type_=sa.Boolean(), + existing_nullable=False) + op.alter_column('guild_members', 'active', + existing_type=mysql.TINYINT(display_width=1), + type_=sa.Boolean(), + existing_nullable=False, + existing_server_default=sa.text(u"'1'")) + op.alter_column('guild_members', 'banned', + existing_type=mysql.TINYINT(display_width=1), + type_=sa.Boolean(), + existing_nullable=False, + existing_server_default=sa.text(u"'0'")) + op.alter_column('guilds', 'bracket_links', + existing_type=mysql.TINYINT(display_width=1), + type_=sa.Boolean(), + existing_nullable=False, + existing_server_default=sa.text(u"'1'")) + op.alter_column('guilds', 'channels', + existing_type=mysql.MEDIUMTEXT(collation=u'utf8mb4_unicode_ci'), + type_=sa.Text(length=4294967295), + existing_nullable=False) + op.alter_column('guilds', 'chat_links', + existing_type=mysql.TINYINT(display_width=1), + type_=sa.Boolean(), + existing_nullable=False, + existing_server_default=sa.text(u"'1'")) + op.alter_column('guilds', 'emojis', + existing_type=mysql.TEXT(collation=u'utf8mb4_unicode_ci'), + type_=sa.Text(length=4294967295), + existing_nullable=False) + op.alter_column('guilds', 'roles', + existing_type=mysql.MEDIUMTEXT(collation=u'utf8mb4_unicode_ci'), + type_=sa.Text(length=4294967295), + existing_nullable=False) + op.alter_column('guilds', 'unauth_users', + existing_type=mysql.TINYINT(display_width=1), + type_=sa.Boolean(), + existing_nullable=False, + existing_server_default=sa.text(u"'1'")) + op.alter_column('guilds', 'visitor_view', + existing_type=mysql.TINYINT(display_width=1), + type_=sa.Boolean(), + existing_nullable=False) + op.alter_column('guilds', 'webhooks', + existing_type=mysql.TEXT(collation=u'utf8mb4_unicode_ci'), + type_=sa.Text(length=4294967295), + existing_nullable=False) + op.alter_column('unauthenticated_users', 'revoked', + existing_type=mysql.TINYINT(display_width=1), + type_=sa.Boolean(), + existing_nullable=False, + existing_server_default=sa.text(u"'0'")) + op.alter_column('user_css', 'css', + existing_type=mysql.MEDIUMTEXT(collation=u'utf8mb4_unicode_ci'), + type_=sa.Text(length=4294967295), + existing_nullable=True) + # ### end Alembic commands ### + + +def downgrade(): + # ### commands auto generated by Alembic - please adjust! ### + op.alter_column('user_css', 'css', + existing_type=sa.Text(length=4294967295), + type_=mysql.MEDIUMTEXT(collation=u'utf8mb4_unicode_ci'), + existing_nullable=True) + op.alter_column('unauthenticated_users', 'revoked', + existing_type=sa.Boolean(), + type_=mysql.TINYINT(display_width=1), + existing_nullable=False, + existing_server_default=sa.text(u"'0'")) + op.alter_column('guilds', 'webhooks', + existing_type=sa.Text(length=4294967295), + type_=mysql.TEXT(collation=u'utf8mb4_unicode_ci'), + existing_nullable=False) + op.alter_column('guilds', 'visitor_view', + existing_type=sa.Boolean(), + type_=mysql.TINYINT(display_width=1), + existing_nullable=False) + op.alter_column('guilds', 'unauth_users', + existing_type=sa.Boolean(), + type_=mysql.TINYINT(display_width=1), + existing_nullable=False, + existing_server_default=sa.text(u"'1'")) + op.alter_column('guilds', 'roles', + existing_type=sa.Text(length=4294967295), + type_=mysql.MEDIUMTEXT(collation=u'utf8mb4_unicode_ci'), + existing_nullable=False) + op.alter_column('guilds', 'emojis', + existing_type=sa.Text(length=4294967295), + type_=mysql.TEXT(collation=u'utf8mb4_unicode_ci'), + existing_nullable=False) + op.alter_column('guilds', 'chat_links', + existing_type=sa.Boolean(), + type_=mysql.TINYINT(display_width=1), + existing_nullable=False, + existing_server_default=sa.text(u"'1'")) + op.alter_column('guilds', 'channels', + existing_type=sa.Text(length=4294967295), + type_=mysql.MEDIUMTEXT(collation=u'utf8mb4_unicode_ci'), + existing_nullable=False) + op.alter_column('guilds', 'bracket_links', + existing_type=sa.Boolean(), + type_=mysql.TINYINT(display_width=1), + existing_nullable=False, + existing_server_default=sa.text(u"'1'")) + op.alter_column('guild_members', 'banned', + existing_type=sa.Boolean(), + type_=mysql.TINYINT(display_width=1), + existing_nullable=False, + existing_server_default=sa.text(u"'0'")) + op.alter_column('guild_members', 'active', + existing_type=sa.Boolean(), + type_=mysql.TINYINT(display_width=1), + existing_nullable=False, + existing_server_default=sa.text(u"'1'")) + op.alter_column('cosmetics', 'css', + existing_type=sa.Boolean(), + type_=mysql.TINYINT(display_width=1), + existing_nullable=False) + # ### end Alembic commands ### diff --git a/webapp/titanembeds/database/guilds.py b/webapp/titanembeds/database/guilds.py index d8b0985..10ff3bd 100644 --- a/webapp/titanembeds/database/guilds.py +++ b/webapp/titanembeds/database/guilds.py @@ -10,10 +10,10 @@ class Guilds(db.Model): chat_links = db.Column(db.Boolean(), nullable=False, default=1) # If users can post links bracket_links = db.Column(db.Boolean(), nullable=False, default=1) # If appending brackets to links to prevent embed mentions_limit = db.Column(db.Integer, nullable=False, default=11) # If there is a limit on the number of mentions in a msg - roles = db.Column(db.Text(), nullable=False) # Guild Roles - channels = db.Column(db.Text(), nullable=False) # Guild channels - webhooks = db.Column(db.Text(), nullable=False) # Guild webhooks - emojis = db.Column(db.Text(), nullable=False) # Guild Emojis + roles = db.Column(db.Text(4294967295), nullable=False) # Guild Roles + channels = db.Column(db.Text(4294967295), nullable=False) # Guild channels + webhooks = db.Column(db.Text(4294967295), nullable=False) # Guild webhooks + emojis = db.Column(db.Text(4294967295), nullable=False) # Guild Emojis owner_id = db.Column(db.String(255), nullable=False) # Snowflake of the owner icon = db.Column(db.String(255)) # The icon string, null if none discordio = db.Column(db.String(255)) # Custom Discord.io Invite Link diff --git a/webapp/titanembeds/database/user_css.py b/webapp/titanembeds/database/user_css.py index e9905be..c70154b 100644 --- a/webapp/titanembeds/database/user_css.py +++ b/webapp/titanembeds/database/user_css.py @@ -5,7 +5,7 @@ class UserCSS(db.Model): id = db.Column(db.Integer, primary_key=True) # Auto increment id name = db.Column(db.String(255), nullable=False) # CSS Name user_id = db.Column(db.String(255), nullable=False) # Discord client ID of the owner of the css (can edit) - css = db.Column(db.Text()) # CSS contents + css = db.Column(db.Text(4294967295)) # CSS contents def __init__(self, name, user_id, css=None): self.name = name