34 lines
945 B
Python
34 lines
945 B
Python
import sqlite3
|
|
import sys
|
|
|
|
|
|
def migrate_database():
|
|
try:
|
|
# Connect to the database
|
|
db = sqlite3.connect("pet_pictures.db")
|
|
cursor = db.cursor()
|
|
|
|
# Check if description column exists
|
|
cursor.execute("PRAGMA table_info(pet_pictures)")
|
|
columns = [column[1] for column in cursor.fetchall()]
|
|
|
|
if "description" not in columns:
|
|
print("Adding description column to pet_pictures table...")
|
|
cursor.execute("ALTER TABLE pet_pictures ADD COLUMN description TEXT")
|
|
db.commit()
|
|
print("Migration completed successfully!")
|
|
else:
|
|
print("Description column already exists. No migration needed.")
|
|
|
|
except sqlite3.Error as e:
|
|
print(f"An error occurred: {e}")
|
|
sys.exit(1)
|
|
finally:
|
|
if db:
|
|
db.close()
|
|
|
|
|
|
if __name__ == "__main__":
|
|
print("Starting database migration...")
|
|
migrate_database()
|