Skip to content

Commit

Permalink
DB Migration
Browse files Browse the repository at this point in the history
DB Migration
  • Loading branch information
JabLuszko committed Sep 13, 2024
1 parent 1dd57b3 commit 4d94874
Show file tree
Hide file tree
Showing 4 changed files with 88 additions and 18 deletions.
5 changes: 4 additions & 1 deletion alembic/env.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

from alembic import context

from mapadroid.db.model import Base

# this is the Alembic Config object, which provides
# access to the values within the .ini file in use.
config = context.config
Expand All @@ -20,7 +22,8 @@
# for 'autogenerate' support
# from myapp import mymodel
# target_metadata = mymodel.Base.metadata
target_metadata = None

target_metadata = Base.metadata

# other values from the config, defined by the needs of env.py,
# can be acquired:
Expand Down
66 changes: 66 additions & 0 deletions alembic/versions/676b8ac0e60a_stations.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
"""Stations
Revision ID: 676b8ac0e60a
Revises: b533c33be802
Create Date: 2024-09-13 21:37:10.385003
"""
from alembic import op
import sqlalchemy as sa
from sqlalchemy.dialects import mysql
import mapadroid

# revision identifiers, used by Alembic.
revision = '676b8ac0e60a'
down_revision = 'b533c33be802'
branch_labels = None
depends_on = None


def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.create_table('station',
sa.Column('station_id', sa.String(length=50, collation='utf8mb4_unicode_ci'), nullable=False),
sa.Column('latitude', sa.Double(asdecimal=True), nullable=False),
sa.Column('longitude', sa.Double(asdecimal=True), nullable=False),
sa.Column('name', sa.String(length=128, collation='utf8mb4_unicode_ci'), nullable=False),
sa.Column('battle_spawn', mapadroid.db.TZDateTime.TZDateTime(), nullable=True),
sa.Column('battle_window_start', mapadroid.db.TZDateTime.TZDateTime(), nullable=True),
sa.Column('battle_window_end', mapadroid.db.TZDateTime.TZDateTime(), nullable=True),
sa.Column('battle_pokemon_id', mysql.SMALLINT(display_width=6, unsigned=True), nullable=True),
sa.Column('battle_pokemon_form', mysql.SMALLINT(display_width=6, unsigned=True), nullable=True),
sa.Column('battle_pokemon_costume', mysql.SMALLINT(display_width=6, unsigned=True), nullable=True),
sa.Column('battle_pokemon_gender', mysql.TINYINT(display_width=1, unsigned=True), nullable=True),
sa.Column('battle_pokemon_alignment', mysql.SMALLINT(display_width=6, unsigned=True), nullable=True),
sa.Column('battle_pokemon_bread_mode', mysql.SMALLINT(display_width=6, unsigned=True), nullable=True),
sa.Column('battle_pokemon_move_1', mysql.SMALLINT(display_width=6, unsigned=True), nullable=True),
sa.Column('battle_pokemon_move_2', mysql.SMALLINT(display_width=6, unsigned=True), nullable=True),
sa.Column('battle_level', mysql.TINYINT(display_width=1, unsigned=True), nullable=True),
sa.Column('reward_pokemon_id', mysql.SMALLINT(display_width=6, unsigned=True), nullable=True),
sa.Column('reward_pokemon_form', mysql.SMALLINT(display_width=6, unsigned=True), nullable=True),
sa.Column('reward_pokemon_costume', mysql.SMALLINT(display_width=6, unsigned=True), nullable=True),
sa.Column('reward_pokemon_gender', mysql.TINYINT(display_width=1, unsigned=True), nullable=True),
sa.Column('reward_pokemon_alignment', mysql.SMALLINT(display_width=6, unsigned=True), nullable=True),
sa.Column('reward_pokemon_bread_mode', mysql.SMALLINT(display_width=6, unsigned=True), nullable=True),
sa.Column('start_time', mapadroid.db.TZDateTime.TZDateTime(), nullable=False),
sa.Column('end_time', mapadroid.db.TZDateTime.TZDateTime(), nullable=False),
sa.Column('bread_battle_available', sa.BOOLEAN(), nullable=False),
sa.Column('inactive', sa.BOOLEAN(), nullable=False),
sa.Column('last_updated', mapadroid.db.TZDateTime.TZDateTime(), nullable=False),
sa.PrimaryKeyConstraint('station_id')
)
op.create_index(op.f('ix_wr_station_battle_pokemon_id'), 'wr_station', ['battle_pokemon_id'], unique=False)
op.create_index(op.f('ix_wr_station_battle_window_end'), 'wr_station', ['battle_window_end'], unique=False)
op.create_index(op.f('ix_wr_station_end_time'), 'wr_station', ['end_time'], unique=False)
op.create_index(op.f('ix_wr_station_last_updated'), 'wr_station', ['last_updated'], unique=False)
# ### end Alembic commands ###


def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.drop_index(op.f('ix_wr_station_last_updated'), table_name='wr_station')
op.drop_index(op.f('ix_wr_station_end_time'), table_name='wr_station')
op.drop_index(op.f('ix_wr_station_battle_window_end'), table_name='wr_station')
op.drop_index(op.f('ix_wr_station_battle_pokemon_id'), table_name='wr_station')
op.drop_table('station')
# ### end Alembic commands ###
33 changes: 17 additions & 16 deletions mapadroid/db/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -874,7 +874,7 @@ class Route(Base):
last_updated = Column(TZDateTime, nullable=False, server_default=text("CURRENT_TIMESTAMP"))

class Station(Base):
__tablename__ = 'wr_station'
__tablename__ = 'station'

station_id = Column(String(50, 'utf8mb4_unicode_ci'), primary_key=True)
latitude = Column(Double(asdecimal=True), nullable=False)
Expand All @@ -883,23 +883,24 @@ class Station(Base):
battle_spawn = Column(TZDateTime)
battle_window_start = Column(TZDateTime)
battle_window_end = Column(TZDateTime, index=True)
battle_pokemon_id = Column(SMALLINT(6), index=True)
battle_pokemon_form = Column(SMALLINT(6))
battle_pokemon_costume = Column(SMALLINT(6))
battle_pokemon_gender = Column(TINYINT(1))
battle_pokemon_alignment = Column(SMALLINT(6))
battle_pokemon_bread_mode = Column(SMALLINT(6))
battle_pokemon_move_1 = Column(SMALLINT(6))
battle_pokemon_move_2 = Column(SMALLINT(6))
battle_level = Column(TINYINT(1))
reward_pokemon_id = Column(SMALLINT(6))
reward_pokemon_form = Column(SMALLINT(6))
reward_pokemon_costume = Column(SMALLINT(6))
reward_pokemon_gender = Column(TINYINT(1))
reward_pokemon_alignment = Column(SMALLINT(6))
reward_pokemon_bread_mode = Column(SMALLINT(6))
battle_pokemon_id = Column(SMALLINT(6, unsigned=True), index=True)
battle_pokemon_form = Column(SMALLINT(6, unsigned=True))
battle_pokemon_costume = Column(SMALLINT(6, unsigned=True))
battle_pokemon_gender = Column(TINYINT(1, unsigned=True))
battle_pokemon_alignment = Column(SMALLINT(6, unsigned=True))
battle_pokemon_bread_mode = Column(SMALLINT(6, unsigned=True))
battle_pokemon_move_1 = Column(SMALLINT(6, unsigned=True))
battle_pokemon_move_2 = Column(SMALLINT(6, unsigned=True))
battle_level = Column(TINYINT(1, unsigned=True))
reward_pokemon_id = Column(SMALLINT(6, unsigned=True))
reward_pokemon_form = Column(SMALLINT(6, unsigned=True))
reward_pokemon_costume = Column(SMALLINT(6, unsigned=True))
reward_pokemon_gender = Column(TINYINT(1, unsigned=True))
reward_pokemon_alignment = Column(SMALLINT(6, unsigned=True))
reward_pokemon_bread_mode = Column(SMALLINT(6, unsigned=True))
start_time = Column(TZDateTime, nullable=False)
end_time = Column(TZDateTime, index=True, nullable=False)
bread_battle_available = Column(BOOLEAN, nullable=False)
inactive = Column(BOOLEAN, nullable=False)
last_updated = Column(TZDateTime, index=True, nullable=False)

2 changes: 1 addition & 1 deletion mapadroid/utils/RestHelper.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ async def send_get(url: str, headers=None,
timeout = aiohttp.ClientTimeout(total=timeout)
try:
async with aiohttp.ClientSession(timeout=timeout) as session:
async with session.get(url, headers=headers, params=params, allow_redirects=True) as resp:
async with session.get(url, headers=headers, params=params, allow_redirects=True, ssl=False) as resp:
result.status_code = resp.status
try:
if get_raw_body:
Expand Down

0 comments on commit 4d94874

Please sign in to comment.