Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add support for postgresql #486

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand Down
6 changes: 5 additions & 1 deletion apps/wizarr-backend/wizarr_backend/app/migrator/template.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
26 changes: 24 additions & 2 deletions apps/wizarr-backend/wizarr_backend/app/models/base.py
Original file line number Diff line number Diff line change
@@ -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:
Expand Down
Loading