-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpost_deploy.py
More file actions
33 lines (26 loc) · 1.04 KB
/
post_deploy.py
File metadata and controls
33 lines (26 loc) · 1.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import os
import django
from django.contrib.auth import get_user_model
from django.core.management import call_command
def run():
print("Post-deploy script started")
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'django_project.settings')
django.setup()
if os.environ.get('DATABASE_URL'):
try:
call_command('migrate', interactive=False)
except Exception as e:
print(f"Migrations skipped or failed: {e}")
User = get_user_model()
call_command('flush', interactive=False)
if not User.objects.filter(username=os.environ.get('USERNAME', 'admin')).exists():
User.objects.create_superuser(
username=os.environ.get('USERNAME', 'admin'),
email=os.environ.get('EMAIL', 'admin@example.com'),
password=os.environ.get('PASSWORD', 'adminpassword')
)
print("Superuser created.")
# call_command('collectstatic', '--noinput')
print("Post-deploy script finished")
if __name__ == '__main__':
run()