#!/bin/python3

import sqlite3
from pathlib import Path


DB_NAME = Path(__file__).parent / "calendar.db"


try:
    conn = sqlite3.connect(DB_NAME)
    conn.execute("PRAGMA foreign_keys = ON;")
    cur = conn.cursor()

    # Migrations


    conn.commit()
    conn.close()

    print("Database updated.")

except sqlite3.Error as e:
    print(f"Database error: {e}")

    try:
        conn.rollback()
        conn.close()
    except (NameError, sqlite3.Error):
        pass

    raise SystemExit(1)

except Exception as e:
    print(f"Error: {e}")

    try:
        conn.rollback()
        conn.close()
    except (NameError, sqlite3.Error):
        pass

    raise SystemExit(1)