Skip to content

🛡️ Warracker is an open source, self-hostable warranty tracker to monitor expirations, store receipts, files. You own the data, your rules!

Fixing database

sassanixc07d2079a223
diff --git a/Dockerfile b/Dockerfile
index 49c1745..780b6a8 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -53,7 +53,7 @@ RUN echo 'server {\n\
\n\
# Proxy API requests to backend\n\
location /api/ {\n\
- proxy_pass http://localhost:5000;\n\
+ proxy_pass http://127.0.0.1:5000;\n\
proxy_set_header Host $host;\n\
proxy_set_header X-Real-IP $remote_addr;\n\
}\n\
diff --git a/backend/app.py b/backend/app.py
index 426d02c..ebd65cf 100644
--- a/backend/app.py
+++ b/backend/app.py
@@ -2,7 +2,7 @@ from flask import Flask, request, jsonify, send_from_directory
import psycopg2
from psycopg2 import pool
import os
-from datetime import datetime, timedelta
+from datetime import datetime, timedelta, date
from werkzeug.utils import secure_filename
from flask_cors import CORS
import logging
@@ -98,7 +98,7 @@ def get_warranties():
warranty_dict = dict(zip(columns, row))
# Convert date objects to ISO format strings for JSON serialization
for key, value in warranty_dict.items():
- if isinstance(value, datetime.date):
+ if isinstance(value, (datetime, date)):
warranty_dict[key] = value.isoformat()
warranties_list.append(warranty_dict)
diff --git a/backend/init.sql b/backend/init.sql
index 0ddd2f4..1a7997a 100644
--- a/backend/init.sql
+++ b/backend/init.sql
@@ -2,17 +2,13 @@
CREATE TABLE warranties (
id SERIAL PRIMARY KEY,
- item_name VARCHAR(255) NOT NULL,
- serial_number VARCHAR(255),
- purchase_date DATE,
- expiration_date DATE NOT NULL,
- warranty_provider VARCHAR(255),
- invoice_image VARCHAR(255), -- Filename or path to the uploaded invoice image
- notes TEXT, -- Any additional notes about the warranty
- created_at TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP,
- updated_at TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP
+ product_name VARCHAR(255) NOT NULL,
+ purchase_date DATE NOT NULL,
+ warranty_years INTEGER NOT NULL,
+ expiration_date DATE,
+ invoice_path TEXT,
+ created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
--- Optionally add indexes for faster querying (if needed)
--- CREATE INDEX idx_expiration_date ON warranties (expiration_date);
--- CREATE INDEX idx_item_name ON warranties (item_name);
\ No newline at end of file
+CREATE INDEX idx_expiration_date ON warranties(expiration_date);
+CREATE INDEX idx_product_name ON warranties(product_name);
\ No newline at end of file