From 9bc9d519c0667a15cb09be45b2ede57db430012c Mon Sep 17 00:00:00 2001 From: ChaoticByte <9070224-ChaoticByte@users.noreply.gitlab.com> Date: Sat, 11 Feb 2023 20:21:27 +0100 Subject: [PATCH] Added setup migration for globals and userdeposits view, added create-admin script #16 --- app/migrations/0002_setup.py | 34 ++++++++++++++++++++++++++++++++++ scripts/create-admin.sh | 19 +++++++++++++++++++ 2 files changed, 53 insertions(+) create mode 100644 app/migrations/0002_setup.py create mode 100755 scripts/create-admin.sh diff --git a/app/migrations/0002_setup.py b/app/migrations/0002_setup.py new file mode 100644 index 0000000..43ec889 --- /dev/null +++ b/app/migrations/0002_setup.py @@ -0,0 +1,34 @@ +# GlobalValues Data migration #1 + +from django.db import migrations + + +def create_globals(apps, schema_editor): + Global = apps.get_model("app", "Global") + Global.objects.create( + name="global_message", + comment="Here you can set a global message that will be shown to every user", + value_float=0.0, + value_string="") + Global.objects.create( + name="admin_info", + comment="Here you can set am infotext that will be displayed on the admin panel", + value_float=0.0, + value_string="") + + +class Migration(migrations.Migration): + + dependencies = [ + ('app', '0001_initial'), + ] + + operations = [ + # create globals + migrations.RunPython(create_globals), + # create view for userdeposits + migrations.RunSQL(""" + create or replace view app_userdeposits_view as + select * from app_registertransaction + where is_user_deposit = true;""") + ] diff --git a/scripts/create-admin.sh b/scripts/create-admin.sh new file mode 100755 index 0000000..783e509 --- /dev/null +++ b/scripts/create-admin.sh @@ -0,0 +1,19 @@ +#!/usr/bin/env bash +# Copyright 2023 Julian Müller (ChaoticByte) + +# change to correct directory, if necessary +script_absolute=$(realpath "$0") +script_directory=$(dirname "$script_absolute") +desired_directory=$(realpath "$script_directory"/..) +if [ "$PWD" != "$desired_directory" ]; then + echo "Changing to project directory..." + cd "$desired_directory" +fi + +echo "Activating venv..." +source ./venv/bin/activate + +echo "Applying migrations..." +./manage.py migrate + +./manage.py createsuperuser