Initial commit

This commit is contained in:
2025-06-22 00:01:22 +03:00
parent fd70166cf6
commit 033b80bfad
153 changed files with 26874 additions and 1 deletions

View File

@@ -0,0 +1,11 @@
USE emergency_tracker;
-- Add field column if it doesn't exist
ALTER TABLE users
ADD COLUMN IF NOT EXISTS field ENUM('הפעלה', 'תוכנה', 'סייבר', 'טכני', 'מטה') DEFAULT NULL AFTER team;
-- Update existing users with default field if they don't have one
UPDATE users SET field = 'מטה' WHERE field IS NULL AND is_admin = TRUE;
-- Show the updated structure
DESCRIBE users;

View File

@@ -0,0 +1,16 @@
USE emergency_tracker;
-- Add role column to users table
ALTER TABLE users
ADD COLUMN role ENUM('user', 'team_admin', 'department_admin', 'field_admin', 'global_admin') NOT NULL DEFAULT 'user' AFTER is_admin;
-- Update existing admin users to be global_admin
UPDATE users SET role = 'global_admin' WHERE is_admin = TRUE;
-- Add role-based actions to admin_actions table
ALTER TABLE admin_actions
MODIFY COLUMN action_type ENUM('reset_all', 'reset_password', 'reset_team', 'reset_department', 'reset_field', 'role_change', 'report_on_behalf') NOT NULL;
-- Add target_role column for role changes
ALTER TABLE admin_actions
ADD COLUMN target_role VARCHAR(50) DEFAULT NULL AFTER target_user_id;

View File

@@ -0,0 +1,36 @@
-- Database maintenance and optimization script
USE emergency_tracker;
-- Show current connection status
SHOW STATUS LIKE 'Threads_connected';
SHOW STATUS LIKE 'Threads_running';
SHOW STATUS LIKE 'Max_used_connections';
-- Show current process list (active connections)
SHOW PROCESSLIST;
-- Optimize tables for better performance
OPTIMIZE TABLE users;
OPTIMIZE TABLE admin_actions;
-- Update table statistics
ANALYZE TABLE users;
ANALYZE TABLE admin_actions;
-- Show table sizes
SELECT
table_name AS 'Table',
ROUND(((data_length + index_length) / 1024 / 1024), 2) AS 'Size (MB)'
FROM information_schema.TABLES
WHERE table_schema = 'emergency_tracker'
ORDER BY (data_length + index_length) DESC;
-- Show connection limits
SHOW VARIABLES LIKE 'max_connections';
SHOW VARIABLES LIKE 'wait_timeout';
SHOW VARIABLES LIKE 'interactive_timeout';
-- Recommended settings for connection management
-- SET GLOBAL max_connections = 200;
-- SET GLOBAL wait_timeout = 300;
-- SET GLOBAL interactive_timeout = 300;

View File

@@ -0,0 +1,45 @@
-- Use the emergency_tracker database
USE emergency_tracker;
-- Drop existing tables if they exist (for clean setup)
DROP TABLE IF EXISTS admin_actions;
DROP TABLE IF EXISTS users;
-- Create users table with all required fields
CREATE TABLE users (
national_id CHAR(9) PRIMARY KEY,
password VARCHAR(255) NOT NULL,
name VARCHAR(100) NOT NULL,
in_shelter ENUM('yes', 'no', 'no_alarm') DEFAULT NULL,
last_updated DATETIME DEFAULT NULL,
is_admin BOOLEAN NOT NULL DEFAULT FALSE,
must_change_password BOOLEAN NOT NULL DEFAULT TRUE,
password_changed_at DATETIME DEFAULT NULL,
department ENUM('מרחב', 'מחשוב', 'אגם', 'לשכה') DEFAULT NULL,
team ENUM('מפלג', 'אתרים', 'מערכות תקשוב', 'שובר', 'קריה', 'כס', 'סיסטם', 'תקשורת', 'נוק', 'אגם', 'לשכה') DEFAULT NULL
);
-- Create admin_actions table
CREATE TABLE admin_actions (
id INT AUTO_INCREMENT PRIMARY KEY,
admin_id CHAR(9) NOT NULL,
action_type ENUM('reset_all', 'reset_password') NOT NULL,
target_user_id CHAR(9) DEFAULT NULL,
timestamp DATETIME DEFAULT CURRENT_TIMESTAMP,
FOREIGN KEY (admin_id) REFERENCES users(national_id),
FOREIGN KEY (target_user_id) REFERENCES users(national_id)
);
-- Insert a test admin user (password: "admin123")
-- Hash generated with bcrypt for "admin123"
INSERT INTO users (national_id, password, name, is_admin, must_change_password, department, team)
VALUES ('123456782', '$2a$12$LQv3c1yqBWVHxkd0LHAkCOYz6TtxMQJqhN8/LewdBdXzz.JrKIFHy', 'מנהל מערכת', TRUE, FALSE, 'מחשוב', 'סיסטם')
ON DUPLICATE KEY UPDATE
department = 'מחשוב',
team = 'סיסטם';
-- Show tables were created
SHOW TABLES;
-- Show the admin user was created
SELECT national_id, name, is_admin, department, team FROM users WHERE is_admin = TRUE;

28
scripts/init-database.sql Normal file
View File

@@ -0,0 +1,28 @@
CREATE DATABASE IF NOT EXISTS emergency_tracker CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
USE emergency_tracker;
CREATE TABLE IF NOT EXISTS users (
national_id CHAR(9) PRIMARY KEY,
password VARCHAR(255) NOT NULL,
name VARCHAR(100) NOT NULL,
in_shelter ENUM('yes', 'no', 'no_alarm') DEFAULT NULL,
last_updated DATETIME DEFAULT NULL,
is_admin BOOLEAN NOT NULL DEFAULT FALSE,
must_change_password BOOLEAN NOT NULL DEFAULT TRUE,
password_changed_at DATETIME DEFAULT NULL
);
CREATE TABLE IF NOT EXISTS admin_actions (
id INT AUTO_INCREMENT PRIMARY KEY,
admin_id CHAR(9) NOT NULL,
action_type ENUM('reset_all', 'reset_password') NOT NULL,
target_user_id CHAR(9) DEFAULT NULL,
timestamp DATETIME DEFAULT CURRENT_TIMESTAMP,
FOREIGN KEY (admin_id) REFERENCES users(national_id),
FOREIGN KEY (target_user_id) REFERENCES users(national_id)
);
-- Insert a test admin user (password: "admin123")
INSERT IGNORE INTO users (national_id, password, name, is_admin, must_change_password)
VALUES ('123456782', '$2a$12$LQv3c1yqBWVHxkd0LHAkCOYz6TtxMQJqhN8/LewdBdXzz.JrKIFHy', 'מנהל מערכת', TRUE, FALSE);

View File

@@ -0,0 +1,18 @@
-- Run this as MySQL root user to create the database user and grant permissions
-- Create the database if it doesn't exist
CREATE DATABASE IF NOT EXISTS emergency_tracker CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
-- Create the user (replace 'your_password' with a strong password)
CREATE USER IF NOT EXISTS 'soldier_tracker'@'localhost' IDENTIFIED BY 'your_secure_password_here';
CREATE USER IF NOT EXISTS 'soldier_tracker'@'%' IDENTIFIED BY 'your_secure_password_here';
-- Grant all privileges on the emergency_tracker database
GRANT ALL PRIVILEGES ON emergency_tracker.* TO 'soldier_tracker'@'localhost';
GRANT ALL PRIVILEGES ON emergency_tracker.* TO 'soldier_tracker'@'%';
-- Flush privileges to apply changes
FLUSH PRIVILEGES;
-- Show the user was created
SELECT User, Host FROM mysql.user WHERE User = 'soldier_tracker';

View File

@@ -0,0 +1,5 @@
USE emergency_tracker;
-- Update admin_actions table to support department resets
ALTER TABLE admin_actions
MODIFY COLUMN action_type ENUM('reset_all', 'reset_password', 'reset_team', 'reset_department') NOT NULL;

View File

@@ -0,0 +1,5 @@
USE emergency_tracker;
-- Update admin_actions table to support field resets
ALTER TABLE admin_actions
MODIFY COLUMN action_type ENUM('reset_all', 'reset_password', 'reset_team', 'reset_department', 'reset_field') NOT NULL;

View File

@@ -0,0 +1,5 @@
USE emergency_tracker;
-- Update admin_actions table to support team resets
ALTER TABLE admin_actions
MODIFY COLUMN action_type ENUM('reset_all', 'reset_password', 'reset_team') NOT NULL;

View File

@@ -0,0 +1,4 @@
USE emergency_tracker;
-- Update the admin user to have a default field
UPDATE users SET field = 'מטה' WHERE national_id = '123456782' AND is_admin = TRUE;

View File

@@ -0,0 +1,9 @@
USE emergency_tracker;
-- Add department and team columns to users table
ALTER TABLE users
ADD COLUMN department ENUM('מרחב', 'מחשוב', 'אגם', 'לשכה') DEFAULT NULL,
ADD COLUMN team ENUM('מפלג', 'אתרים', 'מערכות תקשוב', 'שובר', 'קריה', 'כס', 'סיסטם', 'תקשורת', 'נוק', 'אגם', 'לשכה') DEFAULT NULL;
-- Update existing admin user with default values
UPDATE users SET department = 'מחשוב', team = 'סיסטם' WHERE national_id = '123456782';