36 lines
1.4 KiB
Python
36 lines
1.4 KiB
Python
"""
|
|
This script updates the database to add the 'information' field to the ContactInfo model.
|
|
Run this script once to update your existing database.
|
|
"""
|
|
|
|
from app import create_app, db
|
|
from app.models import ContactInfo
|
|
from sqlalchemy import text
|
|
|
|
app = create_app()
|
|
|
|
def add_information_field():
|
|
"""Add the information field to the ContactInfo table if it doesn't exist."""
|
|
with app.app_context():
|
|
# Check if the column already exists
|
|
result = db.session.execute(text("PRAGMA table_info(contact_info)")).fetchall()
|
|
columns = [row[1] for row in result]
|
|
|
|
if 'information' not in columns:
|
|
print("Adding 'information' column to ContactInfo table...")
|
|
db.session.execute(text("ALTER TABLE contact_info ADD COLUMN information TEXT"))
|
|
|
|
# Add default information to existing contact info
|
|
contact_info = ContactInfo.query.first()
|
|
if contact_info:
|
|
contact_info.information = "Welcome to our Digital Garage Sale! This is a place to find unique pre-owned items at great prices."
|
|
db.session.commit()
|
|
print("Added default information text to existing contact info.")
|
|
|
|
print("Database update complete!")
|
|
else:
|
|
print("The 'information' column already exists in the ContactInfo table.")
|
|
|
|
if __name__ == "__main__":
|
|
add_information_field()
|