migrations moved outside uvicorn startup

This commit is contained in:
zurdi zurdo
2023-04-10 20:14:01 +02:00
parent 324260e6c9
commit 8a34acddc8
4 changed files with 11 additions and 70 deletions

View File

@@ -1,59 +0,0 @@
"""first commit
Revision ID: 1.6.2
Revises:
Create Date: 2023-04-10 11:50:44.824818
"""
from alembic import op
import sqlalchemy as sa
# revision identifiers, used by Alembic.
revision = '1.6.2'
down_revision = None
branch_labels = None
depends_on = None
def upgrade() -> None:
# ### commands auto generated by Alembic - please adjust! ###
op.create_table('platforms',
sa.Column('igdb_id', sa.String(length=10), nullable=True),
sa.Column('sgdb_id', sa.String(length=10), nullable=True),
sa.Column('slug', sa.String(length=50), nullable=False),
sa.Column('name', sa.String(length=400), nullable=True),
sa.Column('logo_path', sa.String(length=1000), nullable=True),
sa.Column('n_roms', sa.Integer(), nullable=True),
sa.PrimaryKeyConstraint('slug')
)
op.create_table('roms',
sa.Column('r_igdb_id', sa.String(length=10), nullable=True),
sa.Column('p_igdb_id', sa.String(length=10), nullable=True),
sa.Column('r_sgdb_id', sa.String(length=10), nullable=True),
sa.Column('p_sgdb_id', sa.String(length=10), nullable=True),
sa.Column('p_slug', sa.String(length=50), nullable=False),
sa.Column('file_name', sa.String(length=450), nullable=False),
sa.Column('file_name_no_tags', sa.String(length=450), nullable=True),
sa.Column('file_extension', sa.String(length=10), nullable=True),
sa.Column('file_path', sa.String(length=1000), nullable=True),
sa.Column('file_size', sa.Float(), nullable=True),
sa.Column('name', sa.String(length=350), nullable=True),
sa.Column('r_slug', sa.String(length=100), nullable=True),
sa.Column('summary', sa.Text(), nullable=True),
sa.Column('path_cover_s', sa.Text(), nullable=True),
sa.Column('path_cover_l', sa.Text(), nullable=True),
sa.Column('has_cover', sa.Boolean(), nullable=True),
sa.Column('region', sa.String(length=20), nullable=True),
sa.Column('revision', sa.String(length=20), nullable=True),
sa.Column('tags', sa.JSON(), nullable=True),
sa.PrimaryKeyConstraint('p_slug', 'file_name')
)
# ### end Alembic commands ###
def downgrade() -> None:
# ### commands auto generated by Alembic - please adjust! ###
op.drop_table('roms')
op.drop_table('platforms')
# ### end Alembic commands ###

View File

@@ -1,7 +1,7 @@
"""rom - add multi
Revision ID: 1.6.3
Revises: 1.6.2
Revises:
Create Date: 2023-04-10 16:21:34.680282
"""
@@ -11,7 +11,7 @@ import sqlalchemy as sa
# revision identifiers, used by Alembic.
revision = '1.6.3'
down_revision = '1.6.2'
down_revision = None
branch_labels = None
depends_on = None

View File

@@ -18,12 +18,7 @@ fastapi.allow_cors(app)
@app.on_event("startup")
def startup() -> None:
"""Startup application."""
log.info("Applying migrations...")
try:
subprocess.run(['alembic', 'upgrade', 'head'], check=True)
except CalledProcessError as e:
log.critical(f"Could not apply migrations: {e}")
sys.exit(4)
pass
@app.put("/scan")
@@ -115,4 +110,10 @@ async def search_rom_igdb(req: Request) -> dict:
if __name__ == '__main__':
uvicorn.run("main:app", host=DEV_HOST, port=DEV_PORT, reload=True)
log.info("Applying migrations...")
try:
subprocess.run(['alembic', 'upgrade', 'head'], check=True)
except CalledProcessError as e:
log.critical(f"Could not apply migrations: {e}")
sys.exit(4)
uvicorn.run("main:app", host=DEV_HOST, port=DEV_PORT, reload=False, workers=4)

View File

@@ -1,11 +1,10 @@
import axios from 'axios'
import JSZip from "jszip"
import { saveAs } from 'file-saver'
export async function downloadRom(rom, emitter) {
console.log("Downloading "+rom.file_name)
emitter.emit('snackbarScan', {'msg': "Gathering "+rom.file_name+"...", 'icon': 'mdi-download', 'color': 'green'})
emitter.emit('snackbarScan', {'msg': "Downloading "+rom.file_name+"...", 'icon': 'mdi-download', 'color': 'green'})
if(rom.multi){
var zipFilename = rom.file_name+".zip"
const zip = new JSZip()