-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupdate_db.py
45 lines (37 loc) · 1.33 KB
/
update_db.py
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
34
35
36
37
38
39
40
41
42
43
44
45
from flask import Flask
from flask_sqlalchemy import SQLAlchemy
from models import db, User, Scan, ScanResult
import os
def create_app():
app = Flask(__name__)
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///vulnscan.db'
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
db.init_app(app)
return app
def update_database():
app = create_app()
with app.app_context():
# Backup existing database
if os.path.exists('vulnscan.db'):
print("Backing up existing database...")
import shutil
shutil.copy2('vulnscan.db', 'vulnscan.db.backup')
print("Dropping all tables...")
db.drop_all()
print("Creating new tables with updated schema...")
db.create_all()
# Create default admin user
admin = User.query.filter_by(username='admin').first()
if not admin:
admin = User(
username='admin',
email='admin@example.com',
is_admin=True
)
admin.set_password('admin') # Change this in production!
db.session.add(admin)
db.session.commit()
print("Created admin user")
print("Database update completed successfully!")
if __name__ == '__main__':
update_database()