mirror of
https://github.com/rommapp/romm.git
synced 2026-02-18 00:27:41 +01:00
migrations added
This commit is contained in:
@@ -36,7 +36,6 @@ def upgrade() -> None:
|
||||
# Move primary key to slug
|
||||
batch_op.drop_constraint(constraint_name="PRIMARY", type_="primary")
|
||||
batch_op.create_primary_key(constraint_name=None, columns=["slug"])
|
||||
print("Moved primary key to slug column on platforms table")
|
||||
except ValueError as e:
|
||||
print(f"Cannot drop primary key on platforms table: {e}")
|
||||
except OperationalError as e:
|
||||
@@ -96,8 +95,6 @@ def upgrade() -> None:
|
||||
)
|
||||
except ValueError as e:
|
||||
print(f"Cannot create foreign key on roms table: {e}")
|
||||
else:
|
||||
print("Created foreign key on roms table")
|
||||
|
||||
|
||||
def downgrade() -> None:
|
||||
|
||||
82
backend/alembic/versions/0015_platform_id_refactor.py
Normal file
82
backend/alembic/versions/0015_platform_id_refactor.py
Normal file
@@ -0,0 +1,82 @@
|
||||
"""empty message
|
||||
|
||||
Revision ID: 0015_platform_id_refactor
|
||||
Revises: 0014_asset_files
|
||||
Create Date: 2024-01-12 02:08:14.962703
|
||||
|
||||
"""
|
||||
from alembic import op
|
||||
import sqlalchemy as sa
|
||||
from sqlalchemy.dialects import mysql
|
||||
|
||||
# revision identifiers, used by Alembic.
|
||||
revision = '0015_platform_id_refactor'
|
||||
down_revision = '0014_asset_files'
|
||||
branch_labels = None
|
||||
depends_on = None
|
||||
|
||||
|
||||
def upgrade() -> None:
|
||||
# ### commands auto generated by Alembic - please adjust! ###
|
||||
with op.batch_alter_table('states', schema=None) as batch_op:
|
||||
batch_op.drop_constraint("states_ibfk_1", type_='foreignkey')
|
||||
batch_op.drop_column('platform_slug')
|
||||
|
||||
with op.batch_alter_table('screenshots', schema=None) as batch_op:
|
||||
batch_op.drop_constraint("screenshots_ibfk_1", type_='foreignkey')
|
||||
batch_op.drop_column('platform_slug')
|
||||
|
||||
with op.batch_alter_table('saves', schema=None) as batch_op:
|
||||
batch_op.drop_constraint("saves_ibfk_1", type_='foreignkey')
|
||||
batch_op.drop_column('platform_slug')
|
||||
|
||||
with op.batch_alter_table('roms', schema=None) as batch_op:
|
||||
batch_op.drop_constraint("fk_platform_roms", type_='foreignkey')
|
||||
|
||||
with op.batch_alter_table('platforms', schema=None) as batch_op:
|
||||
batch_op.drop_constraint(constraint_name="PRIMARY", type_="primary")
|
||||
|
||||
with op.batch_alter_table('platforms', schema=None) as batch_op:
|
||||
batch_op.execute("ALTER TABLE platforms ADD COLUMN id INTEGER(11) NOT NULL AUTO_INCREMENT PRIMARY KEY")
|
||||
|
||||
with op.batch_alter_table('roms', schema=None) as batch_op:
|
||||
batch_op.add_column(sa.Column('platform_id', mysql.INTEGER(display_width=11), autoincrement=False, nullable=False))
|
||||
|
||||
with op.batch_alter_table('roms', schema=None) as batch_op:
|
||||
batch_op.execute("update roms inner join platforms on roms.platform_slug = platforms.slug set roms.platform_id = platforms.id")
|
||||
|
||||
with op.batch_alter_table('roms', schema=None) as batch_op:
|
||||
batch_op.create_foreign_key('roms_platforms_FK', 'platforms', ['platform_id'], ['id'])
|
||||
batch_op.drop_column('platform_slug')
|
||||
batch_op.drop_column('p_sgdb_id')
|
||||
batch_op.drop_column('p_igdb_id')
|
||||
batch_op.drop_column('p_name')
|
||||
# ### end Alembic commands ###
|
||||
|
||||
|
||||
def downgrade() -> None:
|
||||
# ### commands auto generated by Alembic - please adjust! ###
|
||||
with op.batch_alter_table('platforms', schema=None) as batch_op:
|
||||
batch_op.drop_column('id')
|
||||
|
||||
with op.batch_alter_table('roms', schema=None) as batch_op:
|
||||
batch_op.add_column(sa.Column('platform_slug', sa.String(length=50), nullable=False))
|
||||
batch_op.add_column(sa.Column('p_name', sa.String(length=150), nullable=True))
|
||||
batch_op.add_column(sa.Column('p_igdb_id', sa.String(length=10), nullable=True))
|
||||
batch_op.add_column(sa.Column('p_sgdb_id', sa.String(length=10), nullable=True))
|
||||
batch_op.drop_constraint('roms_platforms_FK', type_='foreignkey')
|
||||
batch_op.create_foreign_key(None, 'platforms', ['platform_slug'], ['slug'])
|
||||
batch_op.drop_column('platform_id')
|
||||
|
||||
with op.batch_alter_table('saves', schema=None) as batch_op:
|
||||
batch_op.add_column(sa.Column('platform_slug', sa.String(length=50), nullable=False))
|
||||
batch_op.create_foreign_key(None, 'platforms', ['platform_slug'], ['slug'], ondelete='CASCADE')
|
||||
|
||||
with op.batch_alter_table('screenshots', schema=None) as batch_op:
|
||||
batch_op.add_column(sa.Column('platform_slug', sa.String(length=50), nullable=True))
|
||||
batch_op.create_foreign_key(None, 'platforms', ['platform_slug'], ['slug'], ondelete='CASCADE')
|
||||
|
||||
with op.batch_alter_table('states', schema=None) as batch_op:
|
||||
batch_op.add_column(sa.Column('platform_slug', sa.String(length=50), nullable=False))
|
||||
batch_op.create_foreign_key(None, 'platforms', ['platform_slug'], ['slug'], ondelete='CASCADE')
|
||||
# ### end Alembic commands ###
|
||||
Reference in New Issue
Block a user