Skip to content

Commit

Permalink
Fixed Postgres issues while creating new database with v1.3.0. #2249
Browse files Browse the repository at this point in the history
  • Loading branch information
morpheus65535 committed Sep 21, 2023
1 parent e06aad7 commit e2d0647
Showing 3 changed files with 62 additions and 8 deletions.
6 changes: 3 additions & 3 deletions bazarr/app/database.py
Original file line number Diff line number Diff line change
@@ -9,7 +9,7 @@
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 changes: 54 additions & 0 deletions migrations/versions/cee6a710cb71_.py
Original file line number Diff line number Diff line change
@@ -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 ###
10 changes: 5 additions & 5 deletions migrations/versions/dc09994b7e65_.py
Original file line number Diff line number Diff line change
@@ -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 ###

0 comments on commit e2d0647

Please sign in to comment.