Add some QoL scripts for restoring a database and extending a user

license
This commit is contained in:
Ramon Wenger 2023-05-23 12:31:57 +02:00
parent 6f4d50b033
commit 5e78d08c48
2 changed files with 35 additions and 0 deletions

11
bin/restore-database.sh Executable file
View File

@ -0,0 +1,11 @@
#!/bin/bash
while getopts d:f: flag
do
case "${flag}" in
d) database=${OPTARG};;
f) filename=${OPTARG};;
esac
done
pg_restore --verbose --clean --no-acl --no-owner -d $database $filename

View File

@ -0,0 +1,24 @@
from datetime import date, timedelta
from django.core.management import BaseCommand
from users.models import User
class Command(BaseCommand):
def add_arguments(self, parser):
parser.add_argument("username")
def handle(self, *args, **options):
username = options["username"]
try:
user = User.objects.get(username=username)
today = date.today()
delta = timedelta(180)
user.license_expiry_date = today + delta
user.save()
self.stdout.write(
f"new date set for user{user.username}: {user.license_expiry_date}"
)
except Exception as e:
self.stdout.write(e)