Fix postgresql and mysql db upgrades

This commit is contained in:
Jeremy Zhang 2018-03-30 20:44:23 +00:00
parent 8b32690b55
commit 350b7ab65c
4 changed files with 44 additions and 25 deletions

View File

@ -18,7 +18,7 @@ import sqlalchemy as sa
def upgrade(): def upgrade():
# ### commands auto generated by Alembic - please adjust! ### # ### commands auto generated by Alembic - please adjust! ###
op.alter_column('guilds', 'discordio', new_column_name='invite_link') op.alter_column('guilds', 'discordio', new_column_name='invite_link', existing_type=sa.String(255))
# ### end Alembic commands ### # ### end Alembic commands ###

View File

@ -18,8 +18,8 @@ import sqlalchemy as sa
def upgrade(): def upgrade():
# ### commands auto generated by Alembic - please adjust! ### # ### commands auto generated by Alembic - please adjust! ###
op.alter_column('guilds', 'webhook_icon', new_column_name='guest_icon') op.alter_column('guilds', 'webhook_icon', new_column_name='guest_icon', existing_type=sa.String(255))
op.alter_column('cosmetics', 'webhook_icon', new_column_name='guest_icon') op.alter_column('cosmetics', 'webhook_icon', new_column_name='guest_icon', existing_type=sa.String(255))
# ### end Alembic commands ### # ### end Alembic commands ###

View File

@ -18,59 +18,79 @@ import sqlalchemy as sa
def upgrade(): def upgrade():
# ### commands auto generated by Alembic - please adjust! ### # ### commands auto generated by Alembic - please adjust! ###
op.execute("ALTER TABLE administrators ALTER COLUMN user_id TYPE BIGINT USING user_id::bigint") op.alter_column("administrators", "user_id", existing_type=sa.String(255), type_=sa.BIGINT(), postgresql_using="user_id::bigint")
#op.execute("ALTER TABLE administrators ALTER COLUMN user_id TYPE BIGINT USING user_id::bigint")
op.drop_column('administrators', 'id') op.drop_column('administrators', 'id')
op.execute("ALTER TABLE administrators ADD PRIMARY KEY (user_id);") op.execute("ALTER TABLE administrators ADD PRIMARY KEY (user_id);")
op.execute("ALTER TABLE authenticated_users ALTER COLUMN client_id DROP DEFAULT") op.execute("ALTER TABLE authenticated_users ALTER COLUMN client_id DROP DEFAULT")
op.execute("ALTER TABLE authenticated_users ALTER COLUMN client_id TYPE BIGINT USING client_id::bigint") op.alter_column("authenticated_users", "client_id", existing_type=sa.String(255), type_=sa.BIGINT(), postgresql_using="client_id::bigint")
#op.execute("ALTER TABLE authenticated_users ALTER COLUMN client_id TYPE BIGINT USING client_id::bigint")
op.execute("ALTER TABLE authenticated_users ALTER COLUMN guild_id DROP DEFAULT") op.execute("ALTER TABLE authenticated_users ALTER COLUMN guild_id DROP DEFAULT")
op.execute("ALTER TABLE authenticated_users ALTER COLUMN guild_id TYPE BIGINT USING guild_id::bigint") op.alter_column("authenticated_users", "guild_id", existing_type=sa.String(255), type_=sa.BIGINT(), postgresql_using="guild_id::bigint")
#op.execute("ALTER TABLE authenticated_users ALTER COLUMN guild_id TYPE BIGINT USING guild_id::bigint")
op.execute("ALTER TABLE cosmetics ALTER COLUMN user_id DROP DEFAULT") op.execute("ALTER TABLE cosmetics ALTER COLUMN user_id DROP DEFAULT")
op.execute("ALTER TABLE cosmetics ALTER COLUMN user_id TYPE BIGINT USING user_id::bigint") op.alter_column("cosmetics", "user_id", existing_type=sa.String(255), type_=sa.BIGINT(), postgresql_using="user_id::bigint")
#op.execute("ALTER TABLE cosmetics ALTER COLUMN user_id TYPE BIGINT USING user_id::bigint")
op.drop_column('cosmetics', 'id') op.drop_column('cosmetics', 'id')
op.execute("ALTER TABLE cosmetics ADD PRIMARY KEY (user_id);") op.execute("ALTER TABLE cosmetics ADD PRIMARY KEY (user_id);")
op.execute("ALTER TABLE disabled_guilds ALTER COLUMN guild_id DROP DEFAULT") op.execute("ALTER TABLE disabled_guilds ALTER COLUMN guild_id DROP DEFAULT")
op.execute("ALTER TABLE disabled_guilds ALTER COLUMN guild_id TYPE BIGINT USING guild_id::bigint") op.alter_column("disabled_guilds", "guild_id", existing_type=sa.String(255), type_=sa.BIGINT(), postgresql_using="guild_id::bigint")
#op.execute("ALTER TABLE disabled_guilds ALTER COLUMN guild_id TYPE BIGINT USING guild_id::bigint")
op.drop_column('disabled_guilds', 'id') op.drop_column('disabled_guilds', 'id')
op.execute("ALTER TABLE disabled_guilds ADD PRIMARY KEY (guild_id);") op.execute("ALTER TABLE disabled_guilds ADD PRIMARY KEY (guild_id);")
op.execute("ALTER TABLE guild_members ALTER COLUMN guild_id DROP DEFAULT") op.execute("ALTER TABLE guild_members ALTER COLUMN guild_id DROP DEFAULT")
op.execute("ALTER TABLE guild_members ALTER COLUMN guild_id TYPE BIGINT USING guild_id::bigint") op.alter_column("guild_members", "guild_id", existing_type=sa.String(255), type_=sa.BIGINT(), postgresql_using="guild_id::bigint")
#op.execute("ALTER TABLE guild_members ALTER COLUMN guild_id TYPE BIGINT USING guild_id::bigint")
op.execute("ALTER TABLE guild_members ALTER COLUMN user_id DROP DEFAULT") op.execute("ALTER TABLE guild_members ALTER COLUMN user_id DROP DEFAULT")
op.execute("ALTER TABLE guild_members ALTER COLUMN user_id TYPE BIGINT USING user_id::bigint") op.alter_column("guild_members", "user_id", existing_type=sa.String(255), type_=sa.BIGINT(), postgresql_using="user_id::bigint")
#op.execute("ALTER TABLE guild_members ALTER COLUMN user_id TYPE BIGINT USING user_id::bigint")
op.execute("ALTER TABLE guilds ALTER COLUMN guild_id DROP DEFAULT") op.execute("ALTER TABLE guilds ALTER COLUMN guild_id DROP DEFAULT")
op.execute("ALTER TABLE guilds ALTER COLUMN guild_id TYPE BIGINT USING guild_id::bigint") op.alter_column("guilds", "guild_id", existing_type=sa.String(255), type_=sa.BIGINT(), postgresql_using="guild_id::bigint")
#op.execute("ALTER TABLE guilds ALTER COLUMN guild_id TYPE BIGINT USING guild_id::bigint")
op.execute("ALTER TABLE guilds ALTER COLUMN owner_id DROP DEFAULT") op.execute("ALTER TABLE guilds ALTER COLUMN owner_id DROP DEFAULT")
op.execute("ALTER TABLE guilds ALTER COLUMN owner_id TYPE BIGINT USING owner_id::bigint") op.alter_column("guilds", "owner_id", existing_type=sa.String(255), type_=sa.BIGINT(), postgresql_using="owner_id::bigint")
#op.execute("ALTER TABLE guilds ALTER COLUMN owner_id TYPE BIGINT USING owner_id::bigint")
op.drop_column('guilds', 'id') op.drop_column('guilds', 'id')
op.execute("ALTER TABLE guilds ADD PRIMARY KEY (guild_id);") op.execute("ALTER TABLE guilds ADD PRIMARY KEY (guild_id);")
op.execute("ALTER TABLE messages ALTER COLUMN channel_id DROP DEFAULT") op.execute("ALTER TABLE messages ALTER COLUMN channel_id DROP DEFAULT")
op.execute("ALTER TABLE messages ALTER COLUMN channel_id TYPE BIGINT USING channel_id::bigint") op.alter_column("messages", "channel_id", existing_type=sa.String(255), type_=sa.BIGINT(), postgresql_using="channel_id::bigint")
#op.execute("ALTER TABLE messages ALTER COLUMN channel_id TYPE BIGINT USING channel_id::bigint")
op.execute("ALTER TABLE messages ALTER COLUMN guild_id DROP DEFAULT") op.execute("ALTER TABLE messages ALTER COLUMN guild_id DROP DEFAULT")
op.execute("ALTER TABLE messages ALTER COLUMN guild_id TYPE BIGINT USING guild_id::bigint") op.alter_column("messages", "guild_id", existing_type=sa.String(255), type_=sa.BIGINT(), postgresql_using="guild_id::bigint")
#op.execute("ALTER TABLE messages ALTER COLUMN guild_id TYPE BIGINT USING guild_id::bigint")
op.execute("ALTER TABLE messages ALTER COLUMN message_id DROP DEFAULT") op.execute("ALTER TABLE messages ALTER COLUMN message_id DROP DEFAULT")
op.execute("ALTER TABLE messages ALTER COLUMN message_id TYPE BIGINT USING message_id::bigint") op.alter_column("messages", "message_id", existing_type=sa.String(255), type_=sa.BIGINT(), postgresql_using="message_id::bigint")
#op.execute("ALTER TABLE messages ALTER COLUMN message_id TYPE BIGINT USING message_id::bigint")
op.drop_column('messages', 'id') op.drop_column('messages', 'id')
op.execute("ALTER TABLE messages ADD PRIMARY KEY (message_id);") op.execute("ALTER TABLE messages ADD PRIMARY KEY (message_id);")
op.execute("ALTER TABLE patreon ALTER COLUMN user_id DROP DEFAULT") op.execute("ALTER TABLE patreon ALTER COLUMN user_id DROP DEFAULT")
op.execute("ALTER TABLE patreon ALTER COLUMN user_id TYPE BIGINT USING user_id::bigint") op.alter_column("patreon", "user_id", existing_type=sa.String(255), type_=sa.BIGINT(), postgresql_using="user_id::bigint")
#op.execute("ALTER TABLE patreon ALTER COLUMN user_id TYPE BIGINT USING user_id::bigint")
op.drop_column('patreon', 'id') op.drop_column('patreon', 'id')
op.execute("ALTER TABLE patreon ADD PRIMARY KEY (user_id);") op.execute("ALTER TABLE patreon ADD PRIMARY KEY (user_id);")
op.execute("ALTER TABLE titan_tokens ALTER COLUMN user_id DROP DEFAULT") op.execute("ALTER TABLE titan_tokens ALTER COLUMN user_id DROP DEFAULT")
op.execute("ALTER TABLE titan_tokens ALTER COLUMN user_id TYPE BIGINT USING user_id::bigint") op.alter_column("titan_tokens", "user_id", existing_type=sa.String(255), type_=sa.BIGINT(), postgresql_using="user_id::bigint")
#op.execute("ALTER TABLE titan_tokens ALTER COLUMN user_id TYPE BIGINT USING user_id::bigint")
op.drop_column('titan_tokens', 'id') op.drop_column('titan_tokens', 'id')
op.execute("ALTER TABLE titan_tokens ADD PRIMARY KEY (user_id);") op.execute("ALTER TABLE titan_tokens ADD PRIMARY KEY (user_id);")
op.execute("ALTER TABLE token_transactions ALTER COLUMN user_id DROP DEFAULT") op.execute("ALTER TABLE token_transactions ALTER COLUMN user_id DROP DEFAULT")
op.execute("ALTER TABLE token_transactions ALTER COLUMN user_id TYPE BIGINT USING user_id::bigint") op.alter_column("token_transactions", "user_id", existing_type=sa.String(255), type_=sa.BIGINT(), postgresql_using="user_id::bigint")
#op.execute("ALTER TABLE token_transactions ALTER COLUMN user_id TYPE BIGINT USING user_id::bigint")
op.execute("ALTER TABLE unauthenticated_bans ALTER COLUMN guild_id DROP DEFAULT") op.execute("ALTER TABLE unauthenticated_bans ALTER COLUMN guild_id DROP DEFAULT")
op.execute("ALTER TABLE unauthenticated_bans ALTER COLUMN guild_id TYPE BIGINT USING guild_id::bigint") op.alter_column("unauthenticated_bans", "guild_id", existing_type=sa.String(255), type_=sa.BIGINT(), postgresql_using="guild_id::bigint")
#op.execute("ALTER TABLE unauthenticated_bans ALTER COLUMN guild_id TYPE BIGINT USING guild_id::bigint")
op.execute("ALTER TABLE unauthenticated_bans ALTER COLUMN lifter_id DROP DEFAULT") op.execute("ALTER TABLE unauthenticated_bans ALTER COLUMN lifter_id DROP DEFAULT")
op.execute("ALTER TABLE unauthenticated_bans ALTER COLUMN lifter_id TYPE BIGINT USING lifter_id::bigint") op.alter_column("unauthenticated_bans", "lifter_id", existing_type=sa.String(255), type_=sa.BIGINT(), postgresql_using="lifter_id::bigint")
#op.execute("ALTER TABLE unauthenticated_bans ALTER COLUMN lifter_id TYPE BIGINT USING lifter_id::bigint")
op.execute("ALTER TABLE unauthenticated_bans ALTER COLUMN placer_id DROP DEFAULT") op.execute("ALTER TABLE unauthenticated_bans ALTER COLUMN placer_id DROP DEFAULT")
op.execute("ALTER TABLE unauthenticated_bans ALTER COLUMN placer_id TYPE BIGINT USING placer_id::bigint") op.alter_column("unauthenticated_bans", "placer_id", existing_type=sa.String(255), type_=sa.BIGINT(), postgresql_using="placer_id::bigint")
#op.execute("ALTER TABLE unauthenticated_bans ALTER COLUMN placer_id TYPE BIGINT USING placer_id::bigint")
op.execute("ALTER TABLE unauthenticated_users ALTER COLUMN guild_id DROP DEFAULT") op.execute("ALTER TABLE unauthenticated_users ALTER COLUMN guild_id DROP DEFAULT")
op.execute("ALTER TABLE unauthenticated_users ALTER COLUMN guild_id TYPE BIGINT USING guild_id::bigint") op.alter_column("unauthenticated_bans", "guild_id", existing_type=sa.String(255), type_=sa.BIGINT(), postgresql_using="guild_id::bigint")
#op.execute("ALTER TABLE unauthenticated_users ALTER COLUMN guild_id TYPE BIGINT USING guild_id::bigint")
op.execute("ALTER TABLE user_css ALTER COLUMN user_id DROP DEFAULT") op.execute("ALTER TABLE user_css ALTER COLUMN user_id DROP DEFAULT")
op.execute("ALTER TABLE user_css ALTER COLUMN user_id TYPE BIGINT USING user_id::bigint") op.alter_column("user_css", "user_id", existing_type=sa.String(255), type_=sa.BIGINT(), postgresql_using="user_id::bigint")
#op.execute("ALTER TABLE user_css ALTER COLUMN user_id TYPE BIGINT USING user_id::bigint")
# ### end Alembic commands ### # ### end Alembic commands ###

View File

@ -50,8 +50,7 @@ def upgrade():
op.alter_column('guilds', 'mentions_limit', op.alter_column('guilds', 'mentions_limit',
existing_type=sa.BIGINT(), existing_type=sa.BIGINT(),
type_=sa.Integer(), type_=sa.Integer(),
existing_nullable=False, existing_nullable=False)
existing_server_default=sa.text('(-1)::bigint'))
op.alter_column('keyvalue_properties', 'expiration', op.alter_column('keyvalue_properties', 'expiration',
existing_type=postgresql.TIMESTAMP(timezone=True), existing_type=postgresql.TIMESTAMP(timezone=True),
type_=sa.TIMESTAMP(), type_=sa.TIMESTAMP(),