Skip to content

Commit 6a86c9a

Browse files
committed
Implement Automated Table Structure Creation and Default Admin User Insertion
1 parent 41cef09 commit 6a86c9a

40 files changed

+605
-610
lines changed

backend/app.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from flask_jwt_extended import JWTManager
55
from dotenv import load_dotenv
66
import os
7-
7+
from utils.db import init_db
88
from routes.semgrep import semgrep_bp
99
from routes.History import history_bp
1010
from routes.user_routes import user_bp
@@ -22,10 +22,6 @@
2222
load_dotenv()
2323

2424
app = Flask(__name__)
25-
26-
27-
28-
csrf = CSRFProtect(app)
2925
CORS(app)
3026
bcrypt = Bcrypt(app)
3127

@@ -37,6 +33,9 @@
3733
app.config["JWT_REFRESH_TOKEN_EXPIRES"] = 86400 # 24 hours
3834
jwt = JWTManager(app)
3935

36+
# Initialize database
37+
init_db(app)
38+
4039
# Register Blueprints
4140
app.register_blueprint(user_bp, url_prefix="/")
4241
app.register_blueprint(github_bp, url_prefix="/")
@@ -51,5 +50,5 @@
5150
app.register_blueprint(t5_base_bp, url_prefix="/")
5251
app.register_blueprint(admin_bp, url_prefix="/")
5352

54-
if __name__ == "__main__":
55-
app.run(debug=True, port=5000)
53+
if __name__ == "__main__" :
54+
app.run(debug=True, port=5000)
1.52 KB
Binary file not shown.
1.35 KB
Binary file not shown.
1.14 KB
Binary file not shown.
1.88 KB
Binary file not shown.
2.21 KB
Binary file not shown.
1.47 KB
Binary file not shown.
1.46 KB
Binary file not shown.

backend/models/file_content.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
from flask_sqlalchemy import SQLAlchemy
2+
from datetime import datetime
3+
import pytz
4+
from utils.db import db
5+
from models.scan_history import ScanHistory
6+
7+
class FileContent(db.Model):
8+
__tablename__ = "file_contents"
9+
id = db.Column(db.Integer, primary_key=True)
10+
scan_id = db.Column(db.Integer, db.ForeignKey("scan_history.id", ondelete="CASCADE"))
11+
file_path = db.Column(db.Text, nullable=False)
12+
content = db.Column(db.Text, nullable=False)
13+
input_type = db.Column(db.String(50), nullable=False)
14+
created_at = db.Column(db.DateTime, default=datetime.now(pytz.UTC))
15+
16+
scan = db.relationship("ScanHistory", backref="file_contents")

backend/models/github_user.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
from flask_sqlalchemy import SQLAlchemy
2+
from datetime import datetime
3+
import pytz
4+
from utils.db import db
5+
from models.user import User
6+
7+
class GithubUser(db.Model):
8+
__tablename__ = "github_users"
9+
user_id = db.Column(db.Integer, db.ForeignKey("users.id", ondelete="CASCADE"), primary_key=True)
10+
github_id = db.Column(db.String(255), unique=True, nullable=False)
11+
access_token = db.Column(db.Text)
12+
created_at = db.Column(db.DateTime, default=datetime.now(pytz.UTC))
13+
14+
user = db.relationship("User", backref="github_user")

0 commit comments

Comments
 (0)