Reverting back to admin pages as login and updates in the mobile api
This commit is contained in:
40
db_reset.py
Normal file
40
db_reset.py
Normal file
@@ -0,0 +1,40 @@
|
||||
# reset_db.py
|
||||
import os
|
||||
import sys
|
||||
import django
|
||||
from django.core.management import call_command
|
||||
from django.db import connection
|
||||
|
||||
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "eventify.settings")
|
||||
django.setup()
|
||||
|
||||
def reset_postgres_schema():
|
||||
user = connection.settings_dict.get("USER", "postgres")
|
||||
with connection.cursor() as cursor:
|
||||
cursor.execute("""
|
||||
DROP SCHEMA public CASCADE;
|
||||
CREATE SCHEMA public;
|
||||
GRANT ALL ON SCHEMA public TO {user};
|
||||
GRANT ALL ON SCHEMA public TO public;
|
||||
""".format(user=user))
|
||||
|
||||
def main():
|
||||
if "--force" not in sys.argv:
|
||||
print("Refusing to run without --force (this DROPS ALL TABLES).")
|
||||
sys.exit(1)
|
||||
|
||||
engine = connection.settings_dict.get("ENGINE", "")
|
||||
if "postgresql" not in engine:
|
||||
print("This script is intended for PostgreSQL. Aborting.")
|
||||
sys.exit(1)
|
||||
|
||||
print("Dropping all tables by recreating public schema…")
|
||||
reset_postgres_schema()
|
||||
|
||||
print("Running migrations…")
|
||||
call_command("migrate", interactive=False)
|
||||
|
||||
print("Done.")
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Reference in New Issue
Block a user