added a clear_db to start fresh with only an admin
This commit is contained in:
+56
@@ -0,0 +1,56 @@
|
||||
"""Database seeding script for Team Tryouts application.
|
||||
|
||||
Wipes all data and creates an admin user. Run manually with:
|
||||
python -m app.supporting_scripts.seed
|
||||
"""
|
||||
|
||||
from app.extensions import db, hash_password
|
||||
from app.models import Admin
|
||||
|
||||
|
||||
def seed_database():
|
||||
"""Delete all existing data and create a single admin account."""
|
||||
|
||||
# Delete all data in FK-safe order
|
||||
print("Deleting existing data...")
|
||||
tables = [
|
||||
'one_on_one_requests',
|
||||
'player_disponibilities', 'coach_availabilities',
|
||||
'match_participants', 'team_match_participants',
|
||||
'matches', 'team_matches',
|
||||
'team_players', 'team_members', 'teams',
|
||||
'evaluations', 'tryout_registrations', 'tryouts',
|
||||
'org_team_coaches', 'org_team_managers',
|
||||
'team_notes', 'personal_notes',
|
||||
'user_gamertags',
|
||||
'org_teams',
|
||||
'users',
|
||||
]
|
||||
for table in tables:
|
||||
db.session.execute(db.text(f'DELETE FROM {table}'))
|
||||
db.session.commit()
|
||||
print("[OK] All data deleted.")
|
||||
|
||||
# Create the admin user
|
||||
admin = Admin(
|
||||
username='admin',
|
||||
password_hash=hash_password('password'),
|
||||
role='admin',
|
||||
full_name='Admin',
|
||||
email='[email protected]',
|
||||
)
|
||||
db.session.add(admin)
|
||||
db.session.commit()
|
||||
|
||||
print("[OK] Created admin user")
|
||||
print("\n=== Admin Credentials ===")
|
||||
print("Username: admin")
|
||||
print("Password: password")
|
||||
print("\n[SUCCESS] Database reset and seeded!")
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
from app.app import create_app
|
||||
app = create_app()
|
||||
with app.app_context():
|
||||
seed_database()
|
||||
Reference in New Issue
Block a user