update_db.py 1.3 KB

123456789101112131415161718192021222324252627282930313233
  1. from app import create_app, db
  2. from sqlalchemy import text
  3. app = create_app()
  4. with app.app_context():
  5. # Add missing columns to tickets table
  6. try:
  7. with db.engine.connect() as conn:
  8. conn.execute(text("ALTER TABLE tickets ADD COLUMN closing_reason TEXT"))
  9. conn.execute(text("ALTER TABLE tickets ADD COLUMN closed_by_id INTEGER"))
  10. conn.execute(text("ALTER TABLE tickets ADD CONSTRAINT fk_tickets_closed_by FOREIGN KEY (closed_by_id) REFERENCES users(id)"))
  11. conn.commit()
  12. print("Added columns to tickets table.")
  13. except Exception as e:
  14. print(f"Error updating tickets table (might already exist): {e}")
  15. # Add is_hidden to ticket_comments table
  16. try:
  17. with db.engine.connect() as conn:
  18. conn.execute(text("ALTER TABLE ticket_comments ADD COLUMN is_hidden BOOLEAN DEFAULT FALSE"))
  19. conn.commit()
  20. print("Added is_hidden to ticket_comments table.")
  21. except Exception as e:
  22. print(f"Error updating ticket_comments table (might already exist): {e}")
  23. # Create missing tables (including link_codes)
  24. try:
  25. # This will create any missing tables, including ticket_comments and link_codes
  26. db.create_all()
  27. print("Created missing tables.")
  28. except Exception as e:
  29. print(f"Error creating tables: {e}")