mirror of
https://github.com/morpheus65535/bazarr.git
synced 2024-11-10 09:02:44 +08:00
Fixed Postgres issues while creating new database with v1.3.0. #2249
This commit is contained in:
parent
e06aad7fc6
commit
e2d0647d55
3 changed files with 62 additions and 8 deletions
|
@ -9,7 +9,7 @@ import flask_migrate
|
|||
from dogpile.cache import make_region
|
||||
from datetime import datetime
|
||||
|
||||
from sqlalchemy import create_engine, inspect, DateTime, ForeignKey, Integer, LargeBinary, Text, func, text
|
||||
from sqlalchemy import create_engine, inspect, DateTime, ForeignKey, Integer, LargeBinary, Text, func, text, BigInteger
|
||||
# importing here to be indirectly imported in other modules later
|
||||
from sqlalchemy import update, delete, select, func # noqa W0611
|
||||
from sqlalchemy.orm import scoped_session, sessionmaker, mapped_column
|
||||
|
@ -128,7 +128,7 @@ class TableEpisodes(Base):
|
|||
episode_file_id = mapped_column(Integer)
|
||||
failedAttempts = mapped_column(Text)
|
||||
ffprobe_cache = mapped_column(LargeBinary)
|
||||
file_size = mapped_column(Integer)
|
||||
file_size = mapped_column(BigInteger)
|
||||
format = mapped_column(Text)
|
||||
missing_subtitles = mapped_column(Text)
|
||||
monitored = mapped_column(Text)
|
||||
|
@ -201,7 +201,7 @@ class TableMovies(Base):
|
|||
failedAttempts = mapped_column(Text)
|
||||
fanart = mapped_column(Text)
|
||||
ffprobe_cache = mapped_column(LargeBinary)
|
||||
file_size = mapped_column(Integer)
|
||||
file_size = mapped_column(BigInteger)
|
||||
format = mapped_column(Text)
|
||||
imdbId = mapped_column(Text)
|
||||
missing_subtitles = mapped_column(Text)
|
||||
|
|
54
migrations/versions/cee6a710cb71_.py
Normal file
54
migrations/versions/cee6a710cb71_.py
Normal file
|
@ -0,0 +1,54 @@
|
|||
"""empty message
|
||||
|
||||
Revision ID: cee6a710cb71
|
||||
Revises: 195144da1f7e
|
||||
Create Date: 2023-09-20 23:11:15.678439
|
||||
|
||||
"""
|
||||
from alembic import op
|
||||
import sqlalchemy as sa
|
||||
|
||||
|
||||
# revision identifiers, used by Alembic.
|
||||
revision = 'cee6a710cb71'
|
||||
down_revision = '195144da1f7e'
|
||||
branch_labels = None
|
||||
depends_on = None
|
||||
|
||||
|
||||
def upgrade():
|
||||
# ### commands auto generated by Alembic - please adjust! ###
|
||||
with op.batch_alter_table('table_episodes', schema=None) as batch_op:
|
||||
batch_op.alter_column('file_size',
|
||||
existing_type=sa.INTEGER(),
|
||||
type_=sa.BigInteger(),
|
||||
existing_nullable=True,
|
||||
existing_server_default=sa.text('0'))
|
||||
|
||||
with op.batch_alter_table('table_movies', schema=None) as batch_op:
|
||||
batch_op.alter_column('file_size',
|
||||
existing_type=sa.INTEGER(),
|
||||
type_=sa.BigInteger(),
|
||||
existing_nullable=True,
|
||||
existing_server_default=sa.text('0'))
|
||||
|
||||
# ### end Alembic commands ###
|
||||
|
||||
|
||||
def downgrade():
|
||||
# ### commands auto generated by Alembic - please adjust! ###
|
||||
with op.batch_alter_table('table_movies', schema=None) as batch_op:
|
||||
batch_op.alter_column('file_size',
|
||||
existing_type=sa.BigInteger(),
|
||||
type_=sa.INTEGER(),
|
||||
existing_nullable=True,
|
||||
existing_server_default=sa.text('0'))
|
||||
|
||||
with op.batch_alter_table('table_episodes', schema=None) as batch_op:
|
||||
batch_op.alter_column('file_size',
|
||||
existing_type=sa.BigInteger(),
|
||||
type_=sa.INTEGER(),
|
||||
existing_nullable=True,
|
||||
existing_server_default=sa.text('0'))
|
||||
|
||||
# ### end Alembic commands ###
|
|
@ -72,7 +72,7 @@ def upgrade():
|
|||
# Update series table
|
||||
with op.batch_alter_table('table_shows', recreate=should_recreate) as batch_op:
|
||||
if bind.engine.name == 'postgresql':
|
||||
batch_op.execute('ALTER TABLE table_shows DROP CONSTRAINT IF EXISTS table_shows_pkey;')
|
||||
batch_op.execute('ALTER TABLE table_shows DROP CONSTRAINT IF EXISTS table_shows_pkey CASCADE;')
|
||||
batch_op.execute(sa.update(TableShows)
|
||||
.values({TableShows.profileId: None})
|
||||
.where(TableShows.profileId.not_in(sa.select(TableLanguagesProfiles.profileId))))
|
||||
|
@ -101,7 +101,7 @@ def upgrade():
|
|||
# Update episodes table
|
||||
with op.batch_alter_table('table_episodes') as batch_op:
|
||||
if bind.engine.name == 'postgresql':
|
||||
batch_op.execute('ALTER TABLE table_episodes DROP CONSTRAINT IF EXISTS table_episodes_pkey;')
|
||||
batch_op.execute('ALTER TABLE table_episodes DROP CONSTRAINT IF EXISTS table_episodes_pkey CASCADE;')
|
||||
batch_op.execute(sa.delete(TableEpisodes).where(TableEpisodes.sonarrSeriesId.not_in(
|
||||
sa.select(TableShows.sonarrSeriesId))))
|
||||
batch_op.alter_column(column_name='sonarrSeriesId', existing_type=sa.INTEGER(), nullable=True)
|
||||
|
@ -180,14 +180,14 @@ def upgrade():
|
|||
with op.batch_alter_table('table_shows_rootfolder') as batch_op:
|
||||
if bind.engine.name == 'postgresql':
|
||||
batch_op.execute('ALTER TABLE table_shows_rootfolder DROP CONSTRAINT IF EXISTS '
|
||||
'table_shows_rootfolder_pkey;')
|
||||
'table_shows_rootfolder_pkey CASCADE;')
|
||||
batch_op.alter_column(column_name='id', existing_type=sa.INTEGER(), nullable=False, autoincrement=True)
|
||||
batch_op.create_primary_key(constraint_name='pk_table_shows_rootfolder', columns=['id'])
|
||||
|
||||
# Update movies table
|
||||
with op.batch_alter_table('table_movies', recreate=should_recreate) as batch_op:
|
||||
if bind.engine.name == 'postgresql':
|
||||
batch_op.execute('ALTER TABLE table_movies DROP CONSTRAINT IF EXISTS table_movies_pkey;')
|
||||
batch_op.execute('ALTER TABLE table_movies DROP CONSTRAINT IF EXISTS table_movies_pkey CASCADE;')
|
||||
batch_op.execute(sa.update(TableMovies)
|
||||
.values({TableMovies.profileId: None})
|
||||
.where(TableMovies.profileId.not_in(sa.select(TableLanguagesProfiles.profileId))))
|
||||
|
@ -261,7 +261,7 @@ def upgrade():
|
|||
with op.batch_alter_table('table_movies_rootfolder') as batch_op:
|
||||
if bind.engine.name == 'postgresql':
|
||||
batch_op.execute('ALTER TABLE table_movies_rootfolder DROP CONSTRAINT IF EXISTS '
|
||||
'table_movies_rootfolder_pkey;')
|
||||
'table_movies_rootfolder_pkey CASCADE;')
|
||||
batch_op.alter_column(column_name='id', existing_type=sa.INTEGER(), nullable=False, autoincrement=True)
|
||||
batch_op.create_primary_key(constraint_name='pk_table_movies_rootfolder', columns=['id'])
|
||||
# ### end Alembic commands ###
|
||||
|
|
Loading…
Reference in a new issue