diff --git a/apps/wizarr-backend/wizarr_backend/app/migrator/migrations/2023-10-10_21-34-32.py b/apps/wizarr-backend/wizarr_backend/app/migrator/migrations/2023-10-10_21-34-32.py index b209e187..061d19e1 100644 --- a/apps/wizarr-backend/wizarr_backend/app/migrator/migrations/2023-10-10_21-34-32.py +++ b/apps/wizarr-backend/wizarr_backend/app/migrator/migrations/2023-10-10_21-34-32.py @@ -9,13 +9,17 @@ from datetime import datetime from app import db +from os import environ # Do not change the name of this file, # migrations are run in order of their filenames date and time def run(): # Use migrator to perform actions on the database - migrator = SqliteMigrator(db) + if environ.get('POSTGRES_ENABLED', 'false').lower() == 'true': + migrator = PostgresqlMigrator(db) + else: + migrator = SqliteMigrator(db) # Add duration column to the invitations table with a default value of null # if the column already exists, do nothing diff --git a/apps/wizarr-backend/wizarr_backend/app/migrator/migrations/2023-10-11_20-19-17.py b/apps/wizarr-backend/wizarr_backend/app/migrator/migrations/2023-10-11_20-19-17.py index 9733c4a5..55ca43ea 100644 --- a/apps/wizarr-backend/wizarr_backend/app/migrator/migrations/2023-10-11_20-19-17.py +++ b/apps/wizarr-backend/wizarr_backend/app/migrator/migrations/2023-10-11_20-19-17.py @@ -8,13 +8,17 @@ from playhouse.migrate import * from app import db +from os import environ # Do not change the name of this file, # migrations are run in order of their filenames date and time def run(): # Use migrator to perform actions on the database - migrator = SqliteMigrator(db) + if environ.get('POSTGRES_ENABLED', 'false').lower() == 'true': + migrator = PostgresqlMigrator(db) + else: + migrator = SqliteMigrator(db) # Update all rows in the invitations table that have expires columns with textual "None" to actual None diff --git a/apps/wizarr-backend/wizarr_backend/app/migrator/migrations/2023-10-11_20-48-19.py b/apps/wizarr-backend/wizarr_backend/app/migrator/migrations/2023-10-11_20-48-19.py index 6ef1f315..8916447d 100644 --- a/apps/wizarr-backend/wizarr_backend/app/migrator/migrations/2023-10-11_20-48-19.py +++ b/apps/wizarr-backend/wizarr_backend/app/migrator/migrations/2023-10-11_20-48-19.py @@ -8,13 +8,17 @@ from playhouse.migrate import * from app import db +from os import environ # Do not change the name of this file, # migrations are run in order of their filenames date and time def run(): # Use migrator to perform actions on the database - migrator = SqliteMigrator(db) + if environ.get('POSTGRES_ENABLED', 'false').lower() == 'true': + migrator = PostgresqlMigrator(db) + else: + migrator = SqliteMigrator(db) # Migrate old V2 settings to new V3 settings # Only run this migration if admin_username and admin_password exist in the settings table diff --git a/apps/wizarr-backend/wizarr_backend/app/migrator/migrations/2023-10-11_23-11-06.py b/apps/wizarr-backend/wizarr_backend/app/migrator/migrations/2023-10-11_23-11-06.py index 2f4947e5..69dd174c 100644 --- a/apps/wizarr-backend/wizarr_backend/app/migrator/migrations/2023-10-11_23-11-06.py +++ b/apps/wizarr-backend/wizarr_backend/app/migrator/migrations/2023-10-11_23-11-06.py @@ -8,13 +8,17 @@ from playhouse.migrate import * from app import db +from os import environ # Do not change the name of this file, # migrations are run in order of their filenames date and time def run(): # Use migrator to perform actions on the database - migrator = SqliteMigrator(db) + if environ.get('POSTGRES_ENABLED', 'false').lower() == 'true': + migrator = PostgresqlMigrator(db) + else: + migrator = SqliteMigrator(db) # Move libraries from the settings table to the libraries table with db.transaction(): diff --git a/apps/wizarr-backend/wizarr_backend/app/migrator/migrations/2023-10-11_23-33-47.py b/apps/wizarr-backend/wizarr_backend/app/migrator/migrations/2023-10-11_23-33-47.py index c9f40284..f087567e 100644 --- a/apps/wizarr-backend/wizarr_backend/app/migrator/migrations/2023-10-11_23-33-47.py +++ b/apps/wizarr-backend/wizarr_backend/app/migrator/migrations/2023-10-11_23-33-47.py @@ -8,13 +8,17 @@ from playhouse.migrate import * from app import db +from os import environ # Do not change the name of this file, # migrations are run in order of their filenames date and time def run(): # Use migrator to perform actions on the database - migrator = SqliteMigrator(db) + if environ.get('POSTGRES_ENABLED', 'false').lower() == 'true': + migrator = PostgresqlMigrator(db) + else: + migrator = SqliteMigrator(db) # Update all invitations libraries from there old name format to there id format with db.transaction(): diff --git a/apps/wizarr-backend/wizarr_backend/app/migrator/migrations/2023-10-14_21-46-16.py b/apps/wizarr-backend/wizarr_backend/app/migrator/migrations/2023-10-14_21-46-16.py index 62b64c48..df675e9f 100644 --- a/apps/wizarr-backend/wizarr_backend/app/migrator/migrations/2023-10-14_21-46-16.py +++ b/apps/wizarr-backend/wizarr_backend/app/migrator/migrations/2023-10-14_21-46-16.py @@ -8,13 +8,17 @@ from playhouse.migrate import * from app import db +from os import environ # Do not change the name of this file, # migrations are run in order of their filenames date and time def run(): # Use migrator to perform actions on the database - migrator = SqliteMigrator(db) + if environ.get('POSTGRES_ENABLED', 'false').lower() == 'true': + migrator = PostgresqlMigrator(db) + else: + migrator = SqliteMigrator(db) # Add new Column to users table called tutorial, its a boolean field with a default value of False with db.transaction(): diff --git a/apps/wizarr-backend/wizarr_backend/app/migrator/migrations/2023-10-28_19-21-23.py b/apps/wizarr-backend/wizarr_backend/app/migrator/migrations/2023-10-28_19-21-23.py index 01bfc894..efbbc364 100644 --- a/apps/wizarr-backend/wizarr_backend/app/migrator/migrations/2023-10-28_19-21-23.py +++ b/apps/wizarr-backend/wizarr_backend/app/migrator/migrations/2023-10-28_19-21-23.py @@ -8,13 +8,17 @@ from playhouse.migrate import * from app import db +from os import environ # Do not change the name of this file, # migrations are run in order of their filenames date and time def run(): # Use migrator to perform actions on the database - migrator = SqliteMigrator(db) + if environ.get('POSTGRES_ENABLED', 'false').lower() == 'true': + migrator = PostgresqlMigrator(db) + else: + migrator = SqliteMigrator(db) # Add columns name server_id to requests table with db.transaction(): diff --git a/apps/wizarr-backend/wizarr_backend/app/migrator/migrations/2023-10-29_16-35-41.py b/apps/wizarr-backend/wizarr_backend/app/migrator/migrations/2023-10-29_16-35-41.py index 2b2ca2c7..c72df734 100644 --- a/apps/wizarr-backend/wizarr_backend/app/migrator/migrations/2023-10-29_16-35-41.py +++ b/apps/wizarr-backend/wizarr_backend/app/migrator/migrations/2023-10-29_16-35-41.py @@ -8,13 +8,17 @@ from playhouse.migrate import * from app import db +from os import environ # Do not change the name of this file, # migrations are run in order of their filenames date and time def run(): # Use migrator to perform actions on the database - migrator = SqliteMigrator(db) + if environ.get('POSTGRES_ENABLED', 'false').lower() == 'true': + migrator = PostgresqlMigrator(db) + else: + migrator = SqliteMigrator(db) # Add columns auth to users table with db.transaction(): diff --git a/apps/wizarr-backend/wizarr_backend/app/migrator/migrations/2024-04-19_18-46-37.py b/apps/wizarr-backend/wizarr_backend/app/migrator/migrations/2024-04-19_18-46-37.py index ed788cb5..7107ed63 100644 --- a/apps/wizarr-backend/wizarr_backend/app/migrator/migrations/2024-04-19_18-46-37.py +++ b/apps/wizarr-backend/wizarr_backend/app/migrator/migrations/2024-04-19_18-46-37.py @@ -8,14 +8,17 @@ from playhouse.migrate import * from app import db +from os import environ # Do not change the name of this file, # migrations are run in order of their filenames date and time - def run(): # Use migrator to perform actions on the database - migrator = SqliteMigrator(db) + if environ.get('POSTGRES_ENABLED', 'false').lower() == 'true': + migrator = PostgresqlMigrator(db) + else: + migrator = SqliteMigrator(db) # Add new Column to users table called tutorial, its a boolean field with a default value of False with db.transaction(): diff --git a/apps/wizarr-backend/wizarr_backend/app/migrator/migrations/2024-04-22_19-17-37.py b/apps/wizarr-backend/wizarr_backend/app/migrator/migrations/2024-04-22_19-17-37.py index 047e200c..ec6ea857 100644 --- a/apps/wizarr-backend/wizarr_backend/app/migrator/migrations/2024-04-22_19-17-37.py +++ b/apps/wizarr-backend/wizarr_backend/app/migrator/migrations/2024-04-22_19-17-37.py @@ -8,14 +8,17 @@ from playhouse.migrate import * from app import db +from os import environ # Do not change the name of this file, # migrations are run in order of their filenames date and time - def run(): # Use migrator to perform actions on the database - migrator = SqliteMigrator(db) + if environ.get('POSTGRES_ENABLED', 'false').lower() == 'true': + migrator = PostgresqlMigrator(db) + else: + migrator = SqliteMigrator(db) # Add new Column to users table called tutorial, its a boolean field with a default value of False with db.transaction(): diff --git a/apps/wizarr-backend/wizarr_backend/app/migrator/migrations/2024-04-30_16-44-17.py b/apps/wizarr-backend/wizarr_backend/app/migrator/migrations/2024-04-30_16-44-17.py index e4e4ba69..9be664c4 100644 --- a/apps/wizarr-backend/wizarr_backend/app/migrator/migrations/2024-04-30_16-44-17.py +++ b/apps/wizarr-backend/wizarr_backend/app/migrator/migrations/2024-04-30_16-44-17.py @@ -8,13 +8,17 @@ from playhouse.migrate import * from app import db +from os import environ # Do not change the name of this file, # migrations are run in order of their filenames date and time def run(): # Use migrator to perform actions on the database - migrator = SqliteMigrator(db) + if environ.get('POSTGRES_ENABLED', 'false').lower() == 'true': + migrator = PostgresqlMigrator(db) + else: + migrator = SqliteMigrator(db) # Add new Column to users table, its a boolean field with a default value of True with db.transaction(): diff --git a/apps/wizarr-backend/wizarr_backend/app/migrator/migrations/2024-05-03_22-33-10.py b/apps/wizarr-backend/wizarr_backend/app/migrator/migrations/2024-05-03_22-33-10.py index 174a86c4..a55903bf 100644 --- a/apps/wizarr-backend/wizarr_backend/app/migrator/migrations/2024-05-03_22-33-10.py +++ b/apps/wizarr-backend/wizarr_backend/app/migrator/migrations/2024-05-03_22-33-10.py @@ -8,13 +8,17 @@ from playhouse.migrate import * from app import db +from os import environ # Do not change the name of this file, # migrations are run in order of their filenames date and time def run(): # Use migrator to perform actions on the database - migrator = SqliteMigrator(db) + if environ.get('POSTGRES_ENABLED', 'false').lower() == 'true': + migrator = PostgresqlMigrator(db) + else: + migrator = SqliteMigrator(db) # Remove column plex_home from invitations table with db.transaction(): diff --git a/apps/wizarr-backend/wizarr_backend/app/migrator/template.py b/apps/wizarr-backend/wizarr_backend/app/migrator/template.py index 5ff68b62..4b9126f3 100644 --- a/apps/wizarr-backend/wizarr_backend/app/migrator/template.py +++ b/apps/wizarr-backend/wizarr_backend/app/migrator/template.py @@ -8,10 +8,14 @@ from playhouse.migrate import * from app import db +from os import environ # Do not change the name of this file, # migrations are run in order of their filenames date and time def run(): # Use migrator to perform actions on the database - migrator = SqliteMigrator(db) + if environ.get('POSTGRES_ENABLED', 'false').lower() == 'true': + migrator = PostgresqlMigrator(db) + else: + migrator = SqliteMigrator(db) diff --git a/apps/wizarr-backend/wizarr_backend/app/models/base.py b/apps/wizarr-backend/wizarr_backend/app/models/base.py index 858092d6..8948f8a8 100644 --- a/apps/wizarr-backend/wizarr_backend/app/models/base.py +++ b/apps/wizarr-backend/wizarr_backend/app/models/base.py @@ -1,6 +1,28 @@ -from peewee import Model, SqliteDatabase +# +# CREATED ON VERSION: V{version} +# MIGRATION: {name} +# CREATED: {date} +# -db = SqliteDatabase("./database/database.db") +from peewee import Model, SqliteDatabase, PostgresqlDatabase +from os import environ + +if environ.get('POSTGRES_ENABLED', 'false').lower() == 'true': + required_vars = ['POSTGRES_DATABASE', 'POSTGRES_HOST', 'POSTGRES_PORT', 'POSTGRES_USER', 'POSTGRES_PASS'] + + missing_vars = [var for var in required_vars if not environ.get(var)] + if missing_vars: + raise EnvironmentError(f"The following environment variables are missing : {', '.join(missing_vars)}") + + db = PostgresqlDatabase( + environ['POSTGRES_DATABASE'], + user=environ['POSTGRES_USER'], + password=environ['POSTGRES_PASS'], + host=environ['POSTGRES_HOST'], + port=int(environ['POSTGRES_PORT']) + ) +else: + db = SqliteDatabase("./database/database.db") class BaseModel(Model): class Meta: