mirror of
https://github.com/rommapp/romm.git
synced 2026-06-28 14:56:01 +00:00
squash migrations for 3.0
This commit is contained in:
@@ -2,18 +2,17 @@
|
||||
|
||||
Revision ID: 0014_asset_files
|
||||
Revises: 0013_upgrade_file_extension
|
||||
Create Date: 2024-01-07 09:45:09.632571
|
||||
Create Date: 2024-02-08 15:03:26.338964
|
||||
|
||||
"""
|
||||
|
||||
import os
|
||||
|
||||
import sqlalchemy as sa
|
||||
from alembic import op
|
||||
import sqlalchemy as sa
|
||||
from sqlalchemy import create_engine, text
|
||||
from sqlalchemy.dialects import mysql
|
||||
from sqlalchemy.orm import sessionmaker
|
||||
from config import ROMM_DB_DRIVER
|
||||
from config.config_manager import SQLITE_DB_BASE_PATH, ConfigManager
|
||||
from sqlalchemy import create_engine, text
|
||||
from sqlalchemy.orm import sessionmaker
|
||||
|
||||
# revision identifiers, used by Alembic.
|
||||
revision = "0014_asset_files"
|
||||
@@ -21,6 +20,15 @@ down_revision = "0013_upgrade_file_extension"
|
||||
branch_labels = None
|
||||
depends_on = None
|
||||
|
||||
SIZE_UNIT_TO_BYTES = {
|
||||
"B": 1,
|
||||
"KB": 1024,
|
||||
"MB": 1024**2,
|
||||
"GB": 1024**3,
|
||||
"TB": 1024**4,
|
||||
"PB": 1024**5,
|
||||
}
|
||||
|
||||
|
||||
def migrate_to_mysql() -> None:
|
||||
if ROMM_DB_DRIVER != "mariadb":
|
||||
@@ -80,15 +88,11 @@ def migrate_to_mysql() -> None:
|
||||
|
||||
|
||||
def upgrade() -> None:
|
||||
|
||||
migrate_to_mysql()
|
||||
|
||||
### commands auto generated by Alembic - please adjust! ###
|
||||
op.create_table(
|
||||
"saves",
|
||||
sa.Column("emulator", sa.String(length=50), nullable=True),
|
||||
sa.Column("rom_id", sa.Integer(), nullable=False),
|
||||
sa.Column("platform_slug", sa.String(length=50), nullable=False),
|
||||
sa.Column("id", sa.Integer(), autoincrement=True, nullable=False),
|
||||
sa.Column(
|
||||
"created_at", sa.DateTime(), server_default=sa.text("now()"), nullable=False
|
||||
@@ -98,19 +102,18 @@ def upgrade() -> None:
|
||||
),
|
||||
sa.Column("file_name", sa.String(length=450), nullable=False),
|
||||
sa.Column("file_name_no_tags", sa.String(length=450), nullable=False),
|
||||
sa.Column("file_extension", sa.String(length=10), nullable=False),
|
||||
sa.Column("file_name_no_ext", sa.String(length=450), nullable=False),
|
||||
sa.Column("file_extension", sa.String(length=100), nullable=False),
|
||||
sa.Column("file_path", sa.String(length=1000), nullable=False),
|
||||
sa.Column("file_size_bytes", sa.Integer(), nullable=False),
|
||||
sa.ForeignKeyConstraint(
|
||||
["platform_slug"], ["platforms.slug"], ondelete="CASCADE"
|
||||
),
|
||||
sa.Column("file_size_bytes", sa.BigInteger(), nullable=False),
|
||||
sa.Column("rom_id", sa.Integer(), nullable=False),
|
||||
sa.Column("user_id", sa.Integer(), nullable=False),
|
||||
sa.ForeignKeyConstraint(["rom_id"], ["roms.id"], ondelete="CASCADE"),
|
||||
sa.ForeignKeyConstraint(["user_id"], ["users.id"], ondelete="CASCADE"),
|
||||
sa.PrimaryKeyConstraint("id"),
|
||||
)
|
||||
op.create_table(
|
||||
"screenshots",
|
||||
sa.Column("rom_id", sa.Integer(), nullable=False),
|
||||
sa.Column("platform_slug", sa.String(length=50), nullable=True),
|
||||
sa.Column("id", sa.Integer(), autoincrement=True, nullable=False),
|
||||
sa.Column(
|
||||
"created_at", sa.DateTime(), server_default=sa.text("now()"), nullable=False
|
||||
@@ -120,20 +123,19 @@ def upgrade() -> None:
|
||||
),
|
||||
sa.Column("file_name", sa.String(length=450), nullable=False),
|
||||
sa.Column("file_name_no_tags", sa.String(length=450), nullable=False),
|
||||
sa.Column("file_extension", sa.String(length=10), nullable=False),
|
||||
sa.Column("file_name_no_ext", sa.String(length=450), nullable=False),
|
||||
sa.Column("file_extension", sa.String(length=100), nullable=False),
|
||||
sa.Column("file_path", sa.String(length=1000), nullable=False),
|
||||
sa.Column("file_size_bytes", sa.Integer(), nullable=False),
|
||||
sa.ForeignKeyConstraint(
|
||||
["platform_slug"], ["platforms.slug"], ondelete="CASCADE"
|
||||
),
|
||||
sa.Column("file_size_bytes", sa.BigInteger(), nullable=False),
|
||||
sa.Column("rom_id", sa.Integer(), nullable=False),
|
||||
sa.Column("user_id", sa.Integer(), nullable=False),
|
||||
sa.ForeignKeyConstraint(["rom_id"], ["roms.id"], ondelete="CASCADE"),
|
||||
sa.ForeignKeyConstraint(["user_id"], ["users.id"], ondelete="CASCADE"),
|
||||
sa.PrimaryKeyConstraint("id"),
|
||||
)
|
||||
op.create_table(
|
||||
"states",
|
||||
sa.Column("emulator", sa.String(length=50), nullable=True),
|
||||
sa.Column("rom_id", sa.Integer(), nullable=False),
|
||||
sa.Column("platform_slug", sa.String(length=50), nullable=False),
|
||||
sa.Column("id", sa.Integer(), autoincrement=True, nullable=False),
|
||||
sa.Column(
|
||||
"created_at", sa.DateTime(), server_default=sa.text("now()"), nullable=False
|
||||
@@ -143,21 +145,132 @@ def upgrade() -> None:
|
||||
),
|
||||
sa.Column("file_name", sa.String(length=450), nullable=False),
|
||||
sa.Column("file_name_no_tags", sa.String(length=450), nullable=False),
|
||||
sa.Column("file_extension", sa.String(length=10), nullable=False),
|
||||
sa.Column("file_name_no_ext", sa.String(length=450), nullable=False),
|
||||
sa.Column("file_extension", sa.String(length=100), nullable=False),
|
||||
sa.Column("file_path", sa.String(length=1000), nullable=False),
|
||||
sa.Column("file_size_bytes", sa.Integer(), nullable=False),
|
||||
sa.ForeignKeyConstraint(
|
||||
["platform_slug"], ["platforms.slug"], ondelete="CASCADE"
|
||||
),
|
||||
sa.Column("file_size_bytes", sa.BigInteger(), nullable=False),
|
||||
sa.Column("rom_id", sa.Integer(), nullable=False),
|
||||
sa.Column("user_id", sa.Integer(), nullable=False),
|
||||
sa.ForeignKeyConstraint(["rom_id"], ["roms.id"], ondelete="CASCADE"),
|
||||
sa.ForeignKeyConstraint(["user_id"], ["users.id"], ondelete="CASCADE"),
|
||||
sa.PrimaryKeyConstraint("id"),
|
||||
)
|
||||
### end Alembic commands ###
|
||||
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"
|
||||
)
|
||||
batch_op.drop_column("n_roms")
|
||||
|
||||
with op.batch_alter_table("roms", schema=None) as batch_op:
|
||||
batch_op.add_column(
|
||||
sa.Column("file_name_no_ext", sa.String(length=450), nullable=False)
|
||||
)
|
||||
batch_op.add_column(
|
||||
sa.Column("file_size_bytes", sa.BigInteger(), nullable=False)
|
||||
)
|
||||
batch_op.add_column(sa.Column("igdb_metadata", mysql.JSON(), nullable=True))
|
||||
batch_op.add_column(sa.Column("platform_id", sa.Integer(), nullable=False))
|
||||
batch_op.drop_constraint("fk_platform_roms", type_="foreignkey")
|
||||
batch_op.execute(
|
||||
"update roms inner join platforms on roms.platform_slug = platforms.slug set roms.platform_id = platforms.id"
|
||||
)
|
||||
batch_op.create_foreign_key(
|
||||
None, "platforms", ["platform_id"], ["id"], ondelete="CASCADE"
|
||||
)
|
||||
|
||||
# Set file_name_no_ext on existing roms
|
||||
op.execute(
|
||||
"UPDATE roms SET file_name_no_ext = regexp_replace(file_name, '\\.[a-z]{2,}$', '')"
|
||||
)
|
||||
|
||||
# Process filesize data and prepare for bulk update
|
||||
connection = op.get_bind()
|
||||
result = connection.execute(text("SELECT id, file_size, file_size_units FROM roms"))
|
||||
updates = []
|
||||
for row in result:
|
||||
file_size_bytes = int(row[1] * SIZE_UNIT_TO_BYTES.get(row[2], 1))
|
||||
updates.append({"id": row[0], "file_size_bytes": file_size_bytes})
|
||||
|
||||
if updates:
|
||||
# Perform bulk update
|
||||
connection.execute(
|
||||
text("UPDATE roms SET file_size_bytes = :file_size_bytes WHERE id = :id"),
|
||||
updates,
|
||||
)
|
||||
|
||||
# Cleanup roms table
|
||||
with op.batch_alter_table("roms", schema=None) as batch_op:
|
||||
batch_op.drop_column("file_size")
|
||||
batch_op.drop_column("file_size_units")
|
||||
batch_op.drop_column("p_sgdb_id")
|
||||
batch_op.drop_column("p_name")
|
||||
batch_op.drop_column("p_igdb_id")
|
||||
batch_op.drop_column("platform_slug")
|
||||
|
||||
|
||||
def downgrade() -> None:
|
||||
# ### commands auto generated by Alembic - please adjust! ###
|
||||
with op.batch_alter_table("roms", schema=None) as batch_op:
|
||||
batch_op.add_column(
|
||||
sa.Column("platform_slug", mysql.VARCHAR(length=50), nullable=False)
|
||||
)
|
||||
batch_op.add_column(
|
||||
sa.Column("p_igdb_id", mysql.VARCHAR(length=10), nullable=True)
|
||||
)
|
||||
batch_op.add_column(
|
||||
sa.Column("p_name", mysql.VARCHAR(length=150), nullable=True)
|
||||
)
|
||||
batch_op.add_column(
|
||||
sa.Column("p_sgdb_id", mysql.VARCHAR(length=10), nullable=True)
|
||||
)
|
||||
batch_op.add_column(
|
||||
sa.Column("file_size_units", mysql.VARCHAR(length=10), nullable=False)
|
||||
)
|
||||
batch_op.add_column(sa.Column("file_size", mysql.FLOAT(), nullable=False))
|
||||
batch_op.drop_constraint(None, type_="foreignkey")
|
||||
batch_op.create_foreign_key(
|
||||
"fk_platform_roms", "platforms", ["platform_slug"], ["slug"]
|
||||
)
|
||||
|
||||
op.execute(
|
||||
"update roms inner join platforms on roms.platform_id = platforms.id set roms.platform_slug = platforms.slug"
|
||||
)
|
||||
|
||||
# Process filesize data and prepare for bulk update
|
||||
connection = op.get_bind()
|
||||
result = connection.execute(text("SELECT id, file_size_bytes FROM roms"))
|
||||
|
||||
updates = []
|
||||
for row in result:
|
||||
file_size = row[1] / SIZE_UNIT_TO_BYTES["MB"]
|
||||
updates.append({"id": row[0], "file_size": file_size, "file_size_units": "MB"})
|
||||
|
||||
if updates:
|
||||
# Perform bulk update
|
||||
connection.execute(
|
||||
text(
|
||||
"UPDATE roms SET file_size = :file_size, file_size_units = :file_size_units WHERE id = :id"
|
||||
),
|
||||
updates,
|
||||
)
|
||||
|
||||
# Cleanup roms table
|
||||
with op.batch_alter_table("roms", schema=None) as batch_op:
|
||||
batch_op.drop_column("platform_id")
|
||||
batch_op.drop_column("igdb_metadata")
|
||||
batch_op.drop_column("file_size_bytes")
|
||||
batch_op.drop_column("file_name_no_ext")
|
||||
|
||||
with op.batch_alter_table("platforms", schema=None) as batch_op:
|
||||
batch_op.add_column(
|
||||
sa.Column(
|
||||
"n_roms",
|
||||
mysql.INTEGER(display_width=11),
|
||||
autoincrement=False,
|
||||
nullable=True,
|
||||
)
|
||||
)
|
||||
batch_op.drop_column("id")
|
||||
|
||||
op.drop_table("states")
|
||||
op.drop_table("screenshots")
|
||||
op.drop_table("saves")
|
||||
# ### end Alembic commands ###
|
||||
|
||||
@@ -1,180 +0,0 @@
|
||||
"""empty message
|
||||
|
||||
Revision ID: 0015_platform_id_refactor
|
||||
Revises: 0014_asset_files
|
||||
Create Date: 2024-01-12 02:08:14.962703
|
||||
|
||||
"""
|
||||
import sqlalchemy as sa
|
||||
from alembic import op
|
||||
from sqlalchemy.dialects import mysql
|
||||
from sqlalchemy.sql import text
|
||||
|
||||
# revision identifiers, used by Alembic.
|
||||
revision = "0015_platform_id_refactor"
|
||||
down_revision = "0014_asset_files"
|
||||
branch_labels = None
|
||||
depends_on = None
|
||||
|
||||
SIZE_UNIT_TO_BYTES = {
|
||||
"B": 1,
|
||||
"KB": 1024,
|
||||
"MB": 1024**2,
|
||||
"GB": 1024**3,
|
||||
"TB": 1024**4,
|
||||
"PB": 1024**5,
|
||||
}
|
||||
|
||||
|
||||
def upgrade() -> None:
|
||||
# Drop platform_slug foreign key on all tables
|
||||
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")
|
||||
|
||||
# Change platforms primary key
|
||||
with op.batch_alter_table("platforms", schema=None) as batch_op:
|
||||
batch_op.drop_constraint(constraint_name="PRIMARY", type_="primary")
|
||||
batch_op.drop_column("n_roms")
|
||||
|
||||
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"
|
||||
)
|
||||
|
||||
# Create platform id foreign key
|
||||
with op.batch_alter_table("roms", schema=None) as batch_op:
|
||||
batch_op.drop_column("p_sgdb_id")
|
||||
batch_op.drop_column("p_igdb_id")
|
||||
batch_op.drop_column("p_name")
|
||||
batch_op.add_column(sa.Column("file_size_bytes", sa.Integer(), nullable=False))
|
||||
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")
|
||||
|
||||
connection = op.get_bind()
|
||||
result = connection.execute(text("SELECT id, file_size, file_size_units FROM roms"))
|
||||
|
||||
# Process the data and prepare for bulk update
|
||||
updates = []
|
||||
for row in result:
|
||||
file_size_bytes = int(row[1] * SIZE_UNIT_TO_BYTES.get(row[2], 1))
|
||||
updates.append({"id": row[0], "file_size_bytes": file_size_bytes})
|
||||
|
||||
if updates:
|
||||
# Perform bulk update
|
||||
connection.execute(
|
||||
text("UPDATE roms SET file_size_bytes = :file_size_bytes WHERE id = :id"),
|
||||
updates,
|
||||
)
|
||||
|
||||
# Clean roms table
|
||||
with op.batch_alter_table("roms", schema=None) as batch_op:
|
||||
batch_op.drop_column("file_size")
|
||||
batch_op.drop_column("file_size_units")
|
||||
|
||||
|
||||
def downgrade() -> None:
|
||||
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.drop_column("file_size_bytes")
|
||||
batch_op.add_column(
|
||||
sa.Column("file_size_units", sa.String(length=10), nullable=False)
|
||||
)
|
||||
batch_op.add_column(sa.Column("file_size", sa.Float(), nullable=False))
|
||||
|
||||
op.execute(
|
||||
"update roms inner join platforms on roms.platform_id = platforms.id set roms.platform_slug = platforms.slug"
|
||||
)
|
||||
|
||||
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)
|
||||
)
|
||||
|
||||
op.execute(
|
||||
"update saves inner join roms on saves.rom_id = roms.id set saves.platform_slug = roms.platform_slug"
|
||||
)
|
||||
|
||||
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)
|
||||
)
|
||||
|
||||
op.execute(
|
||||
"update screenshots inner join roms on screenshots.rom_id = roms.id set screenshots.platform_slug = roms.platform_slug"
|
||||
)
|
||||
|
||||
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)
|
||||
)
|
||||
|
||||
op.execute(
|
||||
"update states inner join roms on states.rom_id = roms.id set states.platform_slug = roms.platform_slug"
|
||||
)
|
||||
|
||||
with op.batch_alter_table("platforms", schema=None) as batch_op:
|
||||
batch_op.drop_column("id")
|
||||
batch_op.create_primary_key(constraint_name=None, columns=["slug"])
|
||||
batch_op.add_column(
|
||||
sa.Column("n_roms", sa.Integer(), autoincrement=False, nullable=True)
|
||||
)
|
||||
|
||||
with op.batch_alter_table("saves", schema=None) as batch_op:
|
||||
batch_op.create_foreign_key(
|
||||
"saves_ibfk_1", "platforms", ["platform_slug"], ["slug"], ondelete="CASCADE"
|
||||
)
|
||||
|
||||
with op.batch_alter_table("screenshots", schema=None) as batch_op:
|
||||
batch_op.create_foreign_key(
|
||||
"screenshots_ibfk_1",
|
||||
"platforms",
|
||||
["platform_slug"],
|
||||
["slug"],
|
||||
ondelete="CASCADE",
|
||||
)
|
||||
|
||||
with op.batch_alter_table("states", schema=None) as batch_op:
|
||||
batch_op.create_foreign_key(
|
||||
"states_ibfk_1", "platforms", ["platform_slug"], ["slug"], ondelete="CASCADE"
|
||||
)
|
||||
|
||||
with op.batch_alter_table("roms", schema=None) as batch_op:
|
||||
batch_op.create_foreign_key(
|
||||
"fk_platform_roms", "platforms", ["platform_slug"], ["slug"], ondelete="CASCADE"
|
||||
)
|
||||
batch_op.drop_column("platform_id")
|
||||
@@ -1,38 +0,0 @@
|
||||
"""empty message
|
||||
|
||||
Revision ID: 0016_file_size_bytes_bigint
|
||||
Revises: 0015_platform_id_refactor
|
||||
Create Date: 2024-01-18 16:53:14.108703
|
||||
|
||||
"""
|
||||
from alembic import op
|
||||
import sqlalchemy as sa
|
||||
from sqlalchemy.dialects import mysql
|
||||
|
||||
# revision identifiers, used by Alembic.
|
||||
revision = '0016_file_size_bytes_bigint'
|
||||
down_revision = '0015_platform_id_refactor'
|
||||
branch_labels = None
|
||||
depends_on = None
|
||||
|
||||
|
||||
def upgrade() -> None:
|
||||
# ### commands auto generated by Alembic - please adjust! ###
|
||||
with op.batch_alter_table('roms', schema=None) as batch_op:
|
||||
batch_op.alter_column('file_size_bytes',
|
||||
existing_type=mysql.INTEGER(display_width=11),
|
||||
type_=sa.BigInteger(),
|
||||
existing_nullable=False)
|
||||
|
||||
# ### end Alembic commands ###
|
||||
|
||||
|
||||
def downgrade() -> None:
|
||||
# ### commands auto generated by Alembic - please adjust! ###
|
||||
with op.batch_alter_table('roms', schema=None) as batch_op:
|
||||
batch_op.alter_column('file_size_bytes',
|
||||
existing_type=sa.BigInteger(),
|
||||
type_=mysql.INTEGER(display_width=11),
|
||||
existing_nullable=False)
|
||||
|
||||
# ### end Alembic commands ###
|
||||
@@ -1,52 +0,0 @@
|
||||
"""empty message
|
||||
|
||||
Revision ID: 0017_file_name_no_ext
|
||||
Revises: 0016_file_size_bytes_bigint
|
||||
Create Date: 2024-01-20 13:54:32.458301
|
||||
|
||||
"""
|
||||
from alembic import op
|
||||
import sqlalchemy as sa
|
||||
|
||||
|
||||
# revision identifiers, used by Alembic.
|
||||
revision = '0017_file_name_no_ext'
|
||||
down_revision = '0016_file_size_bytes_bigint'
|
||||
branch_labels = None
|
||||
depends_on = None
|
||||
|
||||
|
||||
def upgrade() -> None:
|
||||
with op.batch_alter_table('roms', schema=None) as batch_op:
|
||||
batch_op.add_column(sa.Column('file_name_no_ext', sa.String(length=450), nullable=False))
|
||||
|
||||
op.execute("UPDATE roms SET file_name_no_ext = regexp_replace(file_name, '\\.[a-z]{2,}$', '')")
|
||||
|
||||
with op.batch_alter_table('saves', schema=None) as batch_op:
|
||||
batch_op.add_column(sa.Column('file_name_no_ext', sa.String(length=450), nullable=False))
|
||||
|
||||
op.execute("UPDATE saves SET file_name_no_ext = regexp_replace(file_name, '\\.[a-z]{2,}$', '')")
|
||||
|
||||
with op.batch_alter_table('screenshots', schema=None) as batch_op:
|
||||
batch_op.add_column(sa.Column('file_name_no_ext', sa.String(length=450), nullable=False))
|
||||
|
||||
op.execute("UPDATE screenshots SET file_name_no_ext = regexp_replace(file_name, '\\.[a-z]{2,}$', '')")
|
||||
|
||||
with op.batch_alter_table('states', schema=None) as batch_op:
|
||||
batch_op.add_column(sa.Column('file_name_no_ext', sa.String(length=450), nullable=False))
|
||||
|
||||
op.execute("UPDATE states SET file_name_no_ext = regexp_replace(file_name, '\\.[a-z]{2,}$', '')")
|
||||
|
||||
|
||||
def downgrade() -> None:
|
||||
with op.batch_alter_table('states', schema=None) as batch_op:
|
||||
batch_op.drop_column('file_name_no_ext')
|
||||
|
||||
with op.batch_alter_table('screenshots', schema=None) as batch_op:
|
||||
batch_op.drop_column('file_name_no_ext')
|
||||
|
||||
with op.batch_alter_table('saves', schema=None) as batch_op:
|
||||
batch_op.drop_column('file_name_no_ext')
|
||||
|
||||
with op.batch_alter_table('roms', schema=None) as batch_op:
|
||||
batch_op.drop_column('file_name_no_ext')
|
||||
@@ -1,68 +0,0 @@
|
||||
"""empty message
|
||||
|
||||
Revision ID: 0018_increase_file_extension
|
||||
Revises: 0017_file_name_no_ext
|
||||
Create Date: 2024-01-27 13:00:54.042607
|
||||
|
||||
"""
|
||||
from alembic import op
|
||||
import sqlalchemy as sa
|
||||
from sqlalchemy.dialects import mysql
|
||||
|
||||
# revision identifiers, used by Alembic.
|
||||
revision = "0018_increase_file_extension"
|
||||
down_revision = "0017_file_name_no_ext"
|
||||
branch_labels = None
|
||||
depends_on = None
|
||||
|
||||
|
||||
def upgrade() -> None:
|
||||
with op.batch_alter_table("saves", schema=None) as batch_op:
|
||||
batch_op.alter_column(
|
||||
"file_extension",
|
||||
existing_type=mysql.VARCHAR(length=10),
|
||||
type_=sa.String(length=100),
|
||||
existing_nullable=False,
|
||||
)
|
||||
|
||||
with op.batch_alter_table("screenshots", schema=None) as batch_op:
|
||||
batch_op.alter_column(
|
||||
"file_extension",
|
||||
existing_type=mysql.VARCHAR(length=10),
|
||||
type_=sa.String(length=100),
|
||||
existing_nullable=False,
|
||||
)
|
||||
|
||||
with op.batch_alter_table("states", schema=None) as batch_op:
|
||||
batch_op.alter_column(
|
||||
"file_extension",
|
||||
existing_type=mysql.VARCHAR(length=10),
|
||||
type_=sa.String(length=100),
|
||||
existing_nullable=False,
|
||||
)
|
||||
|
||||
|
||||
def downgrade() -> None:
|
||||
with op.batch_alter_table("states", schema=None) as batch_op:
|
||||
batch_op.alter_column(
|
||||
"file_extension",
|
||||
existing_type=sa.String(length=100),
|
||||
type_=mysql.VARCHAR(length=10),
|
||||
existing_nullable=False,
|
||||
)
|
||||
|
||||
with op.batch_alter_table("screenshots", schema=None) as batch_op:
|
||||
batch_op.alter_column(
|
||||
"file_extension",
|
||||
existing_type=sa.String(length=100),
|
||||
type_=mysql.VARCHAR(length=10),
|
||||
existing_nullable=False,
|
||||
)
|
||||
|
||||
with op.batch_alter_table("saves", schema=None) as batch_op:
|
||||
batch_op.alter_column(
|
||||
"file_extension",
|
||||
existing_type=sa.String(length=100),
|
||||
type_=mysql.VARCHAR(length=10),
|
||||
existing_nullable=False,
|
||||
)
|
||||
@@ -1,39 +0,0 @@
|
||||
"""empty message
|
||||
|
||||
Revision ID: 0019_add_games_extra_metadata
|
||||
Revises: 0018_increase_file_extension
|
||||
Create Date: 2024-02-02 16:47:26.098480
|
||||
|
||||
"""
|
||||
|
||||
from alembic import op
|
||||
import sqlalchemy as sa
|
||||
from sqlalchemy.dialects import mysql
|
||||
|
||||
# revision identifiers, used by Alembic.
|
||||
revision = "0019_add_games_extra_metadata"
|
||||
down_revision = "0018_increase_file_extension"
|
||||
branch_labels = None
|
||||
depends_on = None
|
||||
|
||||
|
||||
def upgrade() -> None:
|
||||
with op.batch_alter_table("roms", schema=None) as batch_op:
|
||||
batch_op.add_column(sa.Column("igdb_metadata", mysql.JSON(), nullable=True))
|
||||
batch_op.alter_column(
|
||||
"file_extension", existing_type=mysql.VARCHAR(length=100), nullable=False
|
||||
)
|
||||
|
||||
with op.batch_alter_table("roms", schema=None) as batch_op:
|
||||
batch_op.execute("UPDATE roms SET igdb_metadata = '\\{\\}'")
|
||||
batch_op.execute(
|
||||
"UPDATE roms SET path_cover_s = '', path_cover_l = '', url_cover = '' where url_cover = 'https://images.igdb.com/igdb/image/upload/t_cover_big/nocover.png'"
|
||||
)
|
||||
|
||||
|
||||
def downgrade() -> None:
|
||||
with op.batch_alter_table("roms", schema=None) as batch_op:
|
||||
batch_op.alter_column(
|
||||
"file_extension", existing_type=mysql.VARCHAR(length=100), nullable=True
|
||||
)
|
||||
batch_op.drop_column("igdb_metadata")
|
||||
@@ -1,56 +0,0 @@
|
||||
"""empty message
|
||||
|
||||
Revision ID: 0020_assets_user_id
|
||||
Revises: 0019_add_games_extra_metadata
|
||||
Create Date: 2024-02-01 17:08:02.103046
|
||||
|
||||
"""
|
||||
from alembic import op
|
||||
import sqlalchemy as sa
|
||||
|
||||
|
||||
# revision identifiers, used by Alembic.
|
||||
revision = "0020_assets_user_id"
|
||||
down_revision = "0019_add_games_extra_metadata"
|
||||
branch_labels = None
|
||||
depends_on = None
|
||||
|
||||
|
||||
def upgrade() -> None:
|
||||
# ### commands auto generated by Alembic - please adjust! ###
|
||||
with op.batch_alter_table("saves", schema=None) as batch_op:
|
||||
batch_op.add_column(sa.Column("user_id", sa.Integer(), nullable=False))
|
||||
batch_op.create_foreign_key(
|
||||
"saves_user_FK", "users", ["user_id"], ["id"], ondelete="CASCADE"
|
||||
)
|
||||
|
||||
with op.batch_alter_table("screenshots", schema=None) as batch_op:
|
||||
batch_op.add_column(sa.Column("user_id", sa.Integer(), nullable=False))
|
||||
batch_op.create_foreign_key(
|
||||
"screenshots_user_FK", "users", ["user_id"], ["id"], ondelete="CASCADE"
|
||||
)
|
||||
|
||||
with op.batch_alter_table("states", schema=None) as batch_op:
|
||||
batch_op.add_column(sa.Column("user_id", sa.Integer(), nullable=False))
|
||||
batch_op.create_foreign_key(
|
||||
"states_user_FK", "users", ["user_id"], ["id"], ondelete="CASCADE"
|
||||
)
|
||||
|
||||
# ### end Alembic commands ###
|
||||
|
||||
|
||||
def downgrade() -> None:
|
||||
# ### commands auto generated by Alembic - please adjust! ###
|
||||
with op.batch_alter_table("states", schema=None) as batch_op:
|
||||
batch_op.drop_constraint("states_user_FK", type_="foreignkey")
|
||||
batch_op.drop_column("user_id")
|
||||
|
||||
with op.batch_alter_table("screenshots", schema=None) as batch_op:
|
||||
batch_op.drop_constraint("screenshots_user_FK", type_="foreignkey")
|
||||
batch_op.drop_column("user_id")
|
||||
|
||||
with op.batch_alter_table("saves", schema=None) as batch_op:
|
||||
batch_op.drop_constraint("saves_user_FK", type_="foreignkey")
|
||||
batch_op.drop_column("user_id")
|
||||
|
||||
# ### end Alembic commands ###
|
||||
@@ -1,6 +1,6 @@
|
||||
from functools import cached_property
|
||||
from models.base import BaseModel
|
||||
from sqlalchemy import Column, DateTime, ForeignKey, Integer, String, func
|
||||
from sqlalchemy import Column, DateTime, ForeignKey, Integer, String, func, BigInteger
|
||||
from sqlalchemy.orm import relationship
|
||||
from typing import Optional
|
||||
|
||||
@@ -22,7 +22,7 @@ class BaseAsset(BaseModel):
|
||||
file_name_no_ext = Column(String(length=450), nullable=False)
|
||||
file_extension = Column(String(length=100), nullable=False)
|
||||
file_path = Column(String(length=1000), nullable=False)
|
||||
file_size_bytes = Column(Integer(), default=0, nullable=False)
|
||||
file_size_bytes = Column(BigInteger(), default=0, nullable=False)
|
||||
|
||||
rom_id = Column(
|
||||
Integer(), ForeignKey("roms.id", ondelete="CASCADE"), nullable=False
|
||||
|
||||
Reference in New Issue
Block a user