Spaces:
Paused
Paused
Commit
·
10ccff6
1
Parent(s):
2c55e63
Final production-ready setup for Hugging Face Space
Browse files
backend/models/database.py
CHANGED
|
@@ -51,16 +51,17 @@ class Application(db.Model):
|
|
| 51 |
except:
|
| 52 |
return {}
|
| 53 |
|
| 54 |
-
# Initialize the database
|
| 55 |
def init_db(app):
|
| 56 |
"""Initialize the database with the Flask app."""
|
| 57 |
db.init_app(app)
|
| 58 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 59 |
with app.app_context():
|
| 60 |
-
from backend.models.user import User
|
| 61 |
db.create_all()
|
| 62 |
|
| 63 |
-
# Add sample data if jobs table is empty
|
| 64 |
if Job.query.count() == 0:
|
| 65 |
sample_jobs = [
|
| 66 |
Job(
|
|
@@ -86,8 +87,6 @@ def init_db(app):
|
|
| 86 |
),
|
| 87 |
]
|
| 88 |
|
| 89 |
-
|
| 90 |
-
db.session.add(job)
|
| 91 |
-
|
| 92 |
db.session.commit()
|
| 93 |
print("Sample jobs added to database.")
|
|
|
|
| 51 |
except:
|
| 52 |
return {}
|
| 53 |
|
|
|
|
| 54 |
def init_db(app):
|
| 55 |
"""Initialize the database with the Flask app."""
|
| 56 |
db.init_app(app)
|
| 57 |
|
| 58 |
+
# Import all models before db.create_all()
|
| 59 |
+
import backend.models.user # <-- Don't just import User directly
|
| 60 |
+
import backend.models.database # Your Job and Application classes are here
|
| 61 |
+
|
| 62 |
with app.app_context():
|
|
|
|
| 63 |
db.create_all()
|
| 64 |
|
|
|
|
| 65 |
if Job.query.count() == 0:
|
| 66 |
sample_jobs = [
|
| 67 |
Job(
|
|
|
|
| 87 |
),
|
| 88 |
]
|
| 89 |
|
| 90 |
+
db.session.add_all(sample_jobs)
|
|
|
|
|
|
|
| 91 |
db.session.commit()
|
| 92 |
print("Sample jobs added to database.")
|