Final version
This commit is contained in:
83
server/sql/schema.sql
Normal file
83
server/sql/schema.sql
Normal file
@ -0,0 +1,83 @@
|
||||
-- MySQL schema for warehouse manager
|
||||
|
||||
CREATE TABLE IF NOT EXISTS users (
|
||||
id INT AUTO_INCREMENT PRIMARY KEY,
|
||||
username VARCHAR(64) NOT NULL UNIQUE,
|
||||
password_hash VARCHAR(255) NULL,
|
||||
name VARCHAR(128) NOT NULL,
|
||||
email VARCHAR(128) NOT NULL,
|
||||
department VARCHAR(128) DEFAULT NULL,
|
||||
position VARCHAR(128) DEFAULT NULL,
|
||||
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS roles (
|
||||
id INT AUTO_INCREMENT PRIMARY KEY,
|
||||
name VARCHAR(32) NOT NULL UNIQUE
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS permissions (
|
||||
id INT AUTO_INCREMENT PRIMARY KEY,
|
||||
name VARCHAR(32) NOT NULL UNIQUE
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS user_roles (
|
||||
user_id INT NOT NULL,
|
||||
role_id INT NOT NULL,
|
||||
PRIMARY KEY(user_id, role_id),
|
||||
FOREIGN KEY(user_id) REFERENCES users(id) ON DELETE CASCADE,
|
||||
FOREIGN KEY(role_id) REFERENCES roles(id) ON DELETE CASCADE
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS role_permissions (
|
||||
role_id INT NOT NULL,
|
||||
permission_id INT NOT NULL,
|
||||
PRIMARY KEY(role_id, permission_id),
|
||||
FOREIGN KEY(role_id) REFERENCES roles(id) ON DELETE CASCADE,
|
||||
FOREIGN KEY(permission_id) REFERENCES permissions(id) ON DELETE CASCADE
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS categories (
|
||||
id INT AUTO_INCREMENT PRIMARY KEY,
|
||||
name VARCHAR(128) NOT NULL,
|
||||
description TEXT,
|
||||
icon VARCHAR(64) DEFAULT 'fas fa-tag',
|
||||
color VARCHAR(16) DEFAULT '#2c5aa0',
|
||||
active TINYINT(1) DEFAULT 1,
|
||||
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS items (
|
||||
id INT AUTO_INCREMENT PRIMARY KEY,
|
||||
name VARCHAR(255) NOT NULL,
|
||||
category_id INT NULL,
|
||||
price DECIMAL(12,2) NOT NULL DEFAULT 0,
|
||||
quantity INT NOT NULL DEFAULT 0,
|
||||
description TEXT,
|
||||
barcode VARCHAR(128),
|
||||
min_quantity INT NOT NULL DEFAULT 0,
|
||||
location VARCHAR(255),
|
||||
supplier VARCHAR(255),
|
||||
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
|
||||
FOREIGN KEY(category_id) REFERENCES categories(id) ON DELETE SET NULL
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS operations (
|
||||
id INT AUTO_INCREMENT PRIMARY KEY,
|
||||
type ENUM('incoming','outgoing') NOT NULL,
|
||||
item_id INT NOT NULL,
|
||||
quantity INT NOT NULL,
|
||||
employee_id INT NOT NULL,
|
||||
status ENUM('completed','pending','cancelled') DEFAULT 'completed',
|
||||
notes TEXT,
|
||||
supplier VARCHAR(255),
|
||||
recipient VARCHAR(255),
|
||||
date TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||
FOREIGN KEY(item_id) REFERENCES items(id) ON DELETE CASCADE,
|
||||
FOREIGN KEY(employee_id) REFERENCES users(id) ON DELETE RESTRICT
|
||||
);
|
||||
|
||||
|
||||
43
server/sql/seed.sql
Normal file
43
server/sql/seed.sql
Normal file
@ -0,0 +1,43 @@
|
||||
-- Seed roles and permissions
|
||||
INSERT IGNORE INTO roles (id, name) VALUES
|
||||
(1,'admin'),(2,'manager'),(3,'operator'),(4,'viewer');
|
||||
|
||||
INSERT IGNORE INTO permissions (id, name) VALUES
|
||||
(1,'read'),(2,'write'),(3,'delete'),(4,'admin');
|
||||
|
||||
INSERT IGNORE INTO role_permissions (role_id, permission_id) VALUES
|
||||
(1,1),(1,2),(1,3),(1,4), -- admin: all
|
||||
(2,1),(2,2), -- manager: read, write
|
||||
(3,1), -- operator: read
|
||||
(4,1); -- viewer: read
|
||||
|
||||
-- Users (CHANGE THESE PASSWORDS IN PRODUCTION!)
|
||||
-- Default passwords: admin123, manager123, operator123, viewer123
|
||||
-- Use bcrypt or similar for production hashing
|
||||
INSERT INTO users (id, username, password_hash, name, email, department, position) VALUES
|
||||
(1,'admin','admin123','Администратор','admin@company.com','IT','Системный администратор'),
|
||||
(2,'manager','manager123','Менеджер склада','manager@company.com','Склад','Менеджер склада'),
|
||||
(3,'operator','operator123','Оператор','operator@company.com','Склад','Оператор склада'),
|
||||
(4,'viewer','viewer123','Наблюдатель','viewer@company.com','Бухгалтерия','Бухгалтер')
|
||||
ON DUPLICATE KEY UPDATE name=VALUES(name);
|
||||
|
||||
INSERT IGNORE INTO user_roles (user_id, role_id) VALUES
|
||||
(1,1), (2,2), (3,3), (4,4);
|
||||
|
||||
-- Categories
|
||||
INSERT INTO categories (id, name, description, icon, color, active) VALUES
|
||||
(1,'Электроника','Техника и гаджеты','fas fa-laptop','#2c5aa0',1),
|
||||
(2,'Инструменты','Строительные и слесарные инструменты','fas fa-tools','#1a7f37',1),
|
||||
(3,'Офис','Канцелярия и офисные товары','fas fa-briefcase','#8a2be2',1)
|
||||
ON DUPLICATE KEY UPDATE name=VALUES(name);
|
||||
|
||||
-- Items
|
||||
INSERT INTO items (name, category_id, price, quantity, description, barcode, min_quantity, location, supplier) VALUES
|
||||
('Ноутбук Lenovo', 1, 65000, 10, '15.6" Ryzen 5', 'LN-12345', 2, 'Стеллаж A1', 'Lenovo'),
|
||||
('Шуруповерт Bosch', 2, 8500, 25, 'Аккумуляторный 18В', 'BS-98765', 5, 'Стеллаж B2', 'Bosch'),
|
||||
('Бумага A4', 3, 350, 200, 'Пачка 500 листов', 'A4-11111', 50, 'Стеллаж C3', 'Svetocopy');
|
||||
|
||||
-- Sample operations (today)
|
||||
INSERT INTO operations (type, item_id, quantity, employee_id, status, notes, supplier)
|
||||
VALUES ('incoming', 1, 5, 1, 'completed', 'Поступление партии', 'Lenovo');
|
||||
|
||||
Reference in New Issue
Block a user