Compare commits
2 Commits
e63fecab5d
...
0f7c49e063
| Author | SHA1 | Date | |
|---|---|---|---|
| 0f7c49e063 | |||
| ef8854d39d |
27
init_db.py
27
init_db.py
@@ -1,12 +1,33 @@
|
|||||||
from app import app, db, User
|
from app import app, db, User
|
||||||
from flask_migrate import upgrade
|
from flask_migrate import upgrade
|
||||||
|
from sqlalchemy import text
|
||||||
|
|
||||||
def init_db():
|
def init_db():
|
||||||
with app.app_context():
|
with app.app_context():
|
||||||
# Create all tables
|
try:
|
||||||
db.create_all()
|
# Try to run migrations first
|
||||||
# Run any pending migrations
|
|
||||||
upgrade()
|
upgrade()
|
||||||
|
except Exception as e:
|
||||||
|
print(f"Migration error (this is normal if tables exist): {e}")
|
||||||
|
|
||||||
|
# Check if section_id column exists in plant table
|
||||||
|
try:
|
||||||
|
result = db.session.execute(text("SELECT section_id FROM plant LIMIT 1"))
|
||||||
|
print("section_id column exists")
|
||||||
|
except Exception:
|
||||||
|
print("Adding section_id column to plant table")
|
||||||
|
try:
|
||||||
|
# Add section_id column if it doesn't exist
|
||||||
|
db.session.execute(text("""
|
||||||
|
ALTER TABLE plant
|
||||||
|
ADD COLUMN IF NOT EXISTS section_id INTEGER
|
||||||
|
REFERENCES section(id)
|
||||||
|
"""))
|
||||||
|
db.session.commit()
|
||||||
|
print("Added section_id column successfully")
|
||||||
|
except Exception as e:
|
||||||
|
print(f"Error adding section_id column: {e}")
|
||||||
|
db.session.rollback()
|
||||||
|
|
||||||
# Create default admin user if it doesn't exist
|
# Create default admin user if it doesn't exist
|
||||||
admin = User.query.filter_by(username='admin').first()
|
admin = User.query.filter_by(username='admin').first()
|
||||||
|
|||||||
@@ -68,21 +68,21 @@
|
|||||||
<div class="prose max-w-none mb-4 text-[#4e6b50]">{{ plant.description|safe }}</div>
|
<div class="prose max-w-none mb-4 text-[#4e6b50]">{{ plant.description|safe }}</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
{% if products %}
|
{% if plant.care_guide or products %}
|
||||||
<div class="mb-8 mt-4">
|
|
||||||
<span class="font-semibold text-[#4e6b50]">Products:</span>
|
|
||||||
<span class="flex flex-wrap gap-2 mt-1">
|
|
||||||
{% for product in products %}
|
|
||||||
<span class="inline-block bg-[#e6ebe0] text-[#3e5637] px-3 py-1 rounded text-xs font-semibold border border-[#d0e7d2]">{{ product.name }}</span>
|
|
||||||
{% endfor %}
|
|
||||||
</span>
|
|
||||||
</div>
|
|
||||||
{% endif %}
|
|
||||||
{% if plant.care_guide %}
|
|
||||||
<div class="mt-12">
|
<div class="mt-12">
|
||||||
<h2 class="text-2xl font-bold text-[#6b8f71] mb-3">Care Guide</h2>
|
<h2 class="text-2xl font-bold text-[#6b8f71] mb-3">Care Guide</h2>
|
||||||
<div class="prose max-w-none bg-[#f8f9fa] border border-[#e6ebe0] rounded-xl p-6 text-[#3e5637] shadow" style="min-height:80px;">
|
<div class="prose max-w-none bg-[#f8f9fa] border border-[#e6ebe0] rounded-xl p-6 text-[#3e5637] shadow" style="min-height:80px;">
|
||||||
{{ plant.care_guide|safe }}
|
{{ plant.care_guide|safe }}
|
||||||
|
{% if products %}
|
||||||
|
<div class="mt-6">
|
||||||
|
<h3 class="text-lg font-semibold text-[#4e6b50] mb-2">Recommended Products</h3>
|
||||||
|
<div class="flex flex-wrap gap-2">
|
||||||
|
{% for product in products %}
|
||||||
|
<span class="inline-block bg-[#e6ebe0] text-[#3e5637] px-3 py-1 rounded text-sm font-semibold border border-[#d0e7d2]">{{ product.name }}</span>
|
||||||
|
{% endfor %}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{% endif %}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|||||||
Reference in New Issue
Block a user