notebookVb
@@ -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()
|
||||
|
After Width: | Height: | Size: 9.7 MiB |
|
After Width: | Height: | Size: 5.7 MiB |
|
After Width: | Height: | Size: 637 KiB |
|
After Width: | Height: | Size: 8.9 MiB |
|
After Width: | Height: | Size: 7.9 MiB |
|
After Width: | Height: | Size: 3.0 MiB |
|
After Width: | Height: | Size: 297 KiB |
@@ -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}")
|
||||
@@ -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}")
|
||||