Add bid tracker
This commit is contained in:
@@ -212,15 +212,16 @@ def initialize_database():
|
||||
""",
|
||||
"""
|
||||
CREATE TABLE IF NOT EXISTS websites (
|
||||
id INT AUTO_INCREMENT PRIMARY KEY,
|
||||
name VARCHAR(200) NOT NULL,
|
||||
url TEXT NOT NULL,
|
||||
check_type ENUM('daily','weekly') NOT NULL DEFAULT 'daily',
|
||||
note TEXT,
|
||||
is_active TINYINT(1) NOT NULL DEFAULT 1,
|
||||
created_by INT,
|
||||
created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
|
||||
updated_at DATETIME DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
|
||||
id INT AUTO_INCREMENT PRIMARY KEY,
|
||||
name VARCHAR(200) NOT NULL,
|
||||
url TEXT NOT NULL,
|
||||
check_type ENUM('daily','weekly') NOT NULL DEFAULT 'daily',
|
||||
visibility ENUM('all','assigned') NOT NULL DEFAULT 'all',
|
||||
note TEXT,
|
||||
is_active TINYINT(1) NOT NULL DEFAULT 1,
|
||||
created_by INT,
|
||||
created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
|
||||
updated_at DATETIME DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
|
||||
FOREIGN KEY (created_by) REFERENCES users(id) ON DELETE SET NULL
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
|
||||
""",
|
||||
@@ -228,19 +229,19 @@ def initialize_database():
|
||||
CREATE TABLE IF NOT EXISTS website_credentials (
|
||||
id INT AUTO_INCREMENT PRIMARY KEY,
|
||||
website_id INT NOT NULL,
|
||||
username VARCHAR(200) NOT NULL,
|
||||
password VARCHAR(255) NOT NULL,
|
||||
label VARCHAR(100),
|
||||
username VARCHAR(200),
|
||||
password TEXT,
|
||||
FOREIGN KEY (website_id) REFERENCES websites(id) ON DELETE CASCADE
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
|
||||
""",
|
||||
"""
|
||||
CREATE TABLE IF NOT EXISTS shift_checks (
|
||||
id INT AUTO_INCREMENT PRIMARY KEY,
|
||||
website_id INT NOT NULL,
|
||||
user_id INT NOT NULL,
|
||||
checked_at DATETIME DEFAULT CURRENT_TIMESTAMP,
|
||||
user_note TEXT,
|
||||
id INT AUTO_INCREMENT PRIMARY KEY,
|
||||
website_id INT NOT NULL,
|
||||
user_id INT NOT NULL,
|
||||
checked_at DATETIME DEFAULT CURRENT_TIMESTAMP,
|
||||
user_note TEXT,
|
||||
FOREIGN KEY (website_id) REFERENCES websites(id) ON DELETE CASCADE,
|
||||
FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
|
||||
@@ -253,7 +254,7 @@ def initialize_database():
|
||||
entity VARCHAR(100),
|
||||
entity_id INT,
|
||||
detail TEXT,
|
||||
logged_at DATETIME DEFAULT CURRENT_TIMESTAMP,
|
||||
created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
|
||||
FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE SET NULL
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
|
||||
""",
|
||||
@@ -261,9 +262,9 @@ def initialize_database():
|
||||
CREATE TABLE IF NOT EXISTS shifts (
|
||||
id INT AUTO_INCREMENT PRIMARY KEY,
|
||||
name VARCHAR(200) NOT NULL,
|
||||
days_of_week VARCHAR(20) NOT NULL DEFAULT '1234567',
|
||||
start_time TIME NOT NULL DEFAULT '00:00:00',
|
||||
end_time TIME NOT NULL DEFAULT '23:59:59',
|
||||
days_of_week VARCHAR(7) NOT NULL DEFAULT '23456',
|
||||
start_time TIME NOT NULL DEFAULT '08:00:00',
|
||||
end_time TIME NOT NULL DEFAULT '17:00:00',
|
||||
is_active TINYINT(1) NOT NULL DEFAULT 1,
|
||||
note TEXT,
|
||||
created_by INT,
|
||||
@@ -274,18 +275,18 @@ def initialize_database():
|
||||
""",
|
||||
"""
|
||||
CREATE TABLE IF NOT EXISTS shift_users (
|
||||
shift_id INT NOT NULL,
|
||||
user_id INT NOT NULL,
|
||||
shift_id INT NOT NULL,
|
||||
user_id INT NOT NULL,
|
||||
PRIMARY KEY (shift_id, user_id),
|
||||
FOREIGN KEY (shift_id) REFERENCES shifts(id) ON DELETE CASCADE,
|
||||
FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE
|
||||
FOREIGN KEY (shift_id) REFERENCES shifts(id) ON DELETE CASCADE,
|
||||
FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
|
||||
""",
|
||||
"""
|
||||
CREATE TABLE IF NOT EXISTS shift_websites (
|
||||
shift_id INT NOT NULL,
|
||||
website_id INT NOT NULL,
|
||||
sort_order INT NOT NULL DEFAULT 0,
|
||||
shift_id INT NOT NULL,
|
||||
website_id INT NOT NULL,
|
||||
sort_order INT NOT NULL DEFAULT 0,
|
||||
PRIMARY KEY (shift_id, website_id),
|
||||
FOREIGN KEY (shift_id) REFERENCES shifts(id) ON DELETE CASCADE,
|
||||
FOREIGN KEY (website_id) REFERENCES websites(id) ON DELETE CASCADE
|
||||
@@ -335,6 +336,34 @@ def initialize_database():
|
||||
FOREIGN KEY (created_by) REFERENCES users(id) ON DELETE SET NULL
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
|
||||
""",
|
||||
"""
|
||||
CREATE TABLE IF NOT EXISTS bid_tracker (
|
||||
id INT AUTO_INCREMENT PRIMARY KEY,
|
||||
title VARCHAR(300) NOT NULL,
|
||||
url TEXT NOT NULL,
|
||||
source VARCHAR(200) NULL,
|
||||
solicitation_number VARCHAR(100) NULL,
|
||||
status ENUM('open','monitoring','awarded','no_bid','cancelled')
|
||||
NOT NULL DEFAULT 'open',
|
||||
due_date DATE NULL,
|
||||
notes TEXT NULL,
|
||||
added_by INT,
|
||||
created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
|
||||
updated_at DATETIME DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
|
||||
FOREIGN KEY (added_by) REFERENCES users(id) ON DELETE SET NULL
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
|
||||
""",
|
||||
"""
|
||||
CREATE TABLE IF NOT EXISTS bid_updates (
|
||||
id INT AUTO_INCREMENT PRIMARY KEY,
|
||||
bid_id INT NOT NULL,
|
||||
user_id INT,
|
||||
content TEXT NOT NULL,
|
||||
created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
|
||||
FOREIGN KEY (bid_id) REFERENCES bid_tracker(id) ON DELETE CASCADE,
|
||||
FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE SET NULL
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
|
||||
""",
|
||||
]
|
||||
|
||||
conn = None
|
||||
@@ -365,7 +394,7 @@ def initialize_database():
|
||||
conn.commit()
|
||||
logger.info("Migration: added check_type column to websites table.")
|
||||
|
||||
# Add failed_attempts column to users if it doesn't exist
|
||||
# Add failed_attempts / locked_until columns to users if absent
|
||||
cursor.execute(
|
||||
"""
|
||||
SELECT COUNT(*) FROM information_schema.COLUMNS
|
||||
@@ -384,7 +413,7 @@ def initialize_database():
|
||||
conn.commit()
|
||||
logger.info("Migration: added failed_attempts and locked_until columns to users table.")
|
||||
|
||||
# Add visibility column to websites if it doesn't exist
|
||||
# Add visibility column to websites if absent
|
||||
cursor.execute(
|
||||
"""
|
||||
SELECT COUNT(*) FROM information_schema.COLUMNS
|
||||
@@ -402,10 +431,8 @@ def initialize_database():
|
||||
conn.commit()
|
||||
logger.info("Migration: added visibility column to websites table.")
|
||||
|
||||
# Confirm creation of new tables added post-initial-deployment
|
||||
# These use CREATE TABLE IF NOT EXISTS so they are safe on first run.
|
||||
# We log confirmation so operators can verify the upgrade applied.
|
||||
for new_table in ("ai_criteria", "ai_analysis_log"):
|
||||
# Confirm presence of tables added post-initial-deployment
|
||||
for new_table in ("ai_criteria", "ai_analysis_log", "bid_tracker", "bid_updates"):
|
||||
cursor.execute(
|
||||
"""
|
||||
SELECT COUNT(*) FROM information_schema.TABLES
|
||||
@@ -418,7 +445,7 @@ def initialize_database():
|
||||
if table_exists:
|
||||
logger.info(f"Table '{new_table}' confirmed present.")
|
||||
else:
|
||||
logger.warning(f"Table '{new_table}' was not created — check DDL.")
|
||||
logger.warning(f"Table '{new_table}' was not created -- check DDL.")
|
||||
|
||||
# Seed default admin if users table is empty
|
||||
cursor.execute("SELECT COUNT(*) FROM users")
|
||||
@@ -439,3 +466,5 @@ def initialize_database():
|
||||
finally:
|
||||
if conn:
|
||||
conn.close()
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user