Files
PassKeeper/reset_db.py
T
2026-04-16 08:27:07 -04:00

23 lines
748 B
Python

"""
reset_db.py — Drop and recreate all tables from the current models.
WARNING: This deletes all existing data. Development use only.
Run with: python reset_db.py
"""
from app import create_app, db
app = create_app('development')
with app.app_context():
print('Dropping all tables...')
with db.engine.connect() as conn:
conn.execute(db.text('SET FOREIGN_KEY_CHECKS=0'))
for table in reversed(db.metadata.sorted_tables):
print(f' dropping {table.name}')
conn.execute(db.text(f'DROP TABLE IF EXISTS `{table.name}`'))
conn.execute(db.text('SET FOREIGN_KEY_CHECKS=1'))
conn.commit()
print('Creating all tables...')
db.create_all()
print('Done. All tables recreated.')