diff --git a/create_schema.py b/create_schema.py new file mode 100644 index 0000000..441b75c --- /dev/null +++ b/create_schema.py @@ -0,0 +1,89 @@ +import psycopg2 +from psycopg2.extensions import ISOLATION_LEVEL_AUTOCOMMIT + +# Pripojeni k postgres databazi +conn = psycopg2.connect( + host="192.168.1.76", + port=5432, + user="vladimir.buzalka", + password="Vlado7309208104++", + database="postgres" +) +conn.set_isolation_level(ISOLATION_LEVEL_AUTOCOMMIT) +cursor = conn.cursor() + +# Vytvoreni databaze +try: + cursor.execute("DROP DATABASE IF EXISTS fotky_buzalkovi;") + print("[OK] Stara databaze smazana") +except: + pass + +cursor.execute("CREATE DATABASE fotky_buzalkovi;") +print("[OK] Databaze fotky_buzalkovi vytvorena") +conn.close() + +# Pripojeni k nove databazi +conn = psycopg2.connect( + host="192.168.1.76", + port=5432, + user="vladimir.buzalka", + password="Vlado7309208104++", + database="fotky_buzalkovi" +) +cursor = conn.cursor() + +# Vytvoreni tabulek +cursor.execute(""" +CREATE TABLE cameras ( + id SERIAL PRIMARY KEY, + model VARCHAR(255) UNIQUE, + created_at TIMESTAMP DEFAULT NOW() +); +""") + +cursor.execute(""" +CREATE TABLE photos ( + id BIGSERIAL PRIMARY KEY, + file_name VARCHAR(255) NOT NULL, + file_path VARCHAR(1000) NOT NULL, + file_hash VARCHAR(64) UNIQUE, + + camera_id INT, + taken_at TIMESTAMP, + width INT, + height INT, + file_size BIGINT, + + exif_data JSONB, + processing_status VARCHAR(50) DEFAULT 'pending', + created_at TIMESTAMP DEFAULT NOW(), + + FOREIGN KEY (camera_id) REFERENCES cameras(id), + INDEX idx_taken_at (taken_at), + INDEX idx_camera (camera_id), + INDEX idx_file_hash (file_hash) +); +""") + +cursor.execute(""" +CREATE TABLE photo_tags ( + id BIGSERIAL PRIMARY KEY, + photo_id BIGINT NOT NULL, + tag VARCHAR(100), + FOREIGN KEY (photo_id) REFERENCES photos(id) ON DELETE CASCADE, + INDEX idx_tag (tag) +); +""") + +# Vytvoreni indexu pro EXIF data +cursor.execute("CREATE INDEX idx_exif_camera ON photos USING GIN (exif_data);") + +conn.commit() +print("[OK] Schéma vytvoreno:") +print(" - cameras") +print(" - photos") +print(" - photo_tags") +print(" - indexy pro EXIF a vyhledavani") + +conn.close() diff --git a/demo_fotky/2026-04-22 09.05.08.jpg b/demo_fotky/2026-04-22 09.05.08.jpg new file mode 100644 index 0000000..965d6f7 Binary files /dev/null and b/demo_fotky/2026-04-22 09.05.08.jpg differ diff --git a/demo_fotky/2026-04-24 15.15.47.jpg b/demo_fotky/2026-04-24 15.15.47.jpg new file mode 100644 index 0000000..34c1893 Binary files /dev/null and b/demo_fotky/2026-04-24 15.15.47.jpg differ diff --git a/demo_fotky/2026-05-02 10.04.44.png b/demo_fotky/2026-05-02 10.04.44.png new file mode 100644 index 0000000..cfed9e3 Binary files /dev/null and b/demo_fotky/2026-05-02 10.04.44.png differ diff --git a/demo_fotky/2026-05-18 06.22.37.jpg b/demo_fotky/2026-05-18 06.22.37.jpg new file mode 100644 index 0000000..697764e Binary files /dev/null and b/demo_fotky/2026-05-18 06.22.37.jpg differ diff --git a/demo_fotky/2026-05-18 06.22.41.jpg b/demo_fotky/2026-05-18 06.22.41.jpg new file mode 100644 index 0000000..1f3d2e7 Binary files /dev/null and b/demo_fotky/2026-05-18 06.22.41.jpg differ diff --git a/demo_fotky/2026-05-18 13.54.47.jpg b/demo_fotky/2026-05-18 13.54.47.jpg new file mode 100644 index 0000000..f46b1e3 Binary files /dev/null and b/demo_fotky/2026-05-18 13.54.47.jpg differ diff --git a/demo_fotky/2026-05-18 14.10.59.jpg b/demo_fotky/2026-05-18 14.10.59.jpg new file mode 100644 index 0000000..4463839 Binary files /dev/null and b/demo_fotky/2026-05-18 14.10.59.jpg differ diff --git a/test_db_connection.py b/test_db_connection.py new file mode 100644 index 0000000..4e2c579 --- /dev/null +++ b/test_db_connection.py @@ -0,0 +1,38 @@ +import psycopg2 +import sys + +try: + conn = psycopg2.connect( + host="192.168.1.76", + port=5432, + user="vladimir.buzalka", + password="Vlado7309208104++", + database="postgres" + ) + cursor = conn.cursor() + cursor.execute("SELECT version();") + version = cursor.fetchone() + print("[OK] PostgreSQL pripojeni uspesne!") + print(f"Verze: {version[0][:100]}") + + # Test MongoDB + try: + from pymongo import MongoClient + mongo_conn = MongoClient("mongodb://localhost:27017/", serverSelectionTimeoutMS=2000) + mongo_conn.admin.command('ping') + print("[OK] MongoDB dostupny") + except Exception as e: + print(f"[WARN] MongoDB: {str(e)[:50]}") + + # Test Redis + try: + import redis + redis_conn = redis.Redis(host='localhost', port=6379, socket_connect_timeout=2) + redis_conn.ping() + print("[OK] Redis dostupny") + except Exception as e: + print(f"[WARN] Redis: {str(e)[:50]}") + + conn.close() +except Exception as e: + print(f"[ERROR] PostgreSQL: {e}") diff --git a/test_mongo.py b/test_mongo.py new file mode 100644 index 0000000..ea21196 --- /dev/null +++ b/test_mongo.py @@ -0,0 +1,58 @@ +from pymongo import MongoClient +from pymongo.errors import ServerSelectionTimeoutError + +try: + client = MongoClient( + "mongodb://192.168.1.76:27017/", + serverSelectionTimeoutMS=5000, + connectTimeoutMS=5000 + ) + + # Test pripojeni + client.admin.command('ping') + print("[OK] MongoDB pripojeni uspesne!") + + # Zobraz info + print(f"Server info: {client.server_info()}") + + # Vytvor databazi + db = client['fotky_buzalkovi'] + print(f"[OK] Databaze 'fotky_buzalkovi' vytvorena/existuje") + + # Vytvor kolekce s validaci + db.create_collection( + "photos", + validator={ + "$jsonSchema": { + "bsonType": "object", + "required": ["file_name", "file_path"], + "properties": { + "file_name": {"bsonType": "string"}, + "file_path": {"bsonType": "string"}, + "file_hash": {"bsonType": "string"}, + "camera": {"bsonType": "string"}, + "taken_at": {"bsonType": "date"}, + "width": {"bsonType": "int"}, + "height": {"bsonType": "int"}, + "file_size": {"bsonType": "int"}, + "exif": {"bsonType": "object"}, + "tags": {"bsonType": "array"} + } + } + } + ) + print("[OK] Kolekce 'photos' vytvorena") + + # Vytvor indexy + db.photos.create_index("file_hash", unique=True) + db.photos.create_index("taken_at") + db.photos.create_index("camera") + db.photos.create_index("tags") + print("[OK] Indexy vytvoreny") + + client.close() + +except ServerSelectionTimeoutError as e: + print(f"[ERROR] Timeout - MongoDB neni dostupny: {e}") +except Exception as e: + print(f"[ERROR] {e}")