Repository navigation
Expand file tree
/
Copy pathschema.sql
More file actions
executable file
·112 lines (100 loc) · 4.06 KB
/
Copy pathschema.sql
File metadata and controls
executable file
·112 lines (100 loc) · 4.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
-- StoreTrack Database Schema
-- Run this script once to initialise the database
CREATE DATABASE IF NOT EXISTS storetrack;
USE storetrack;
-- Users
CREATE TABLE IF NOT EXISTS users (
id INT PRIMARY KEY AUTO_INCREMENT,
name VARCHAR(100) NOT NULL,
email VARCHAR(100) UNIQUE NOT NULL,
password VARCHAR(255) NOT NULL,
role ENUM('ADMIN','CASHIER','STOCK_MANAGER') NOT NULL,
is_active TINYINT(1) DEFAULT 1,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
-- Categories
CREATE TABLE IF NOT EXISTS categories (
id INT PRIMARY KEY AUTO_INCREMENT,
name VARCHAR(100) NOT NULL,
description VARCHAR(255),
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
-- Products
CREATE TABLE IF NOT EXISTS products (
id INT PRIMARY KEY AUTO_INCREMENT,
name VARCHAR(150) NOT NULL,
category_id INT NOT NULL,
buying_price DECIMAL(10,2) NOT NULL,
selling_price DECIMAL(10,2) NOT NULL,
quantity INT DEFAULT 0,
min_quantity INT DEFAULT 5,
unit VARCHAR(20) DEFAULT 'pcs',
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
FOREIGN KEY (category_id) REFERENCES categories(id),
INDEX idx_products_category (category_id)
);
-- Suppliers
CREATE TABLE IF NOT EXISTS suppliers (
id INT PRIMARY KEY AUTO_INCREMENT,
name VARCHAR(150) NOT NULL,
phone VARCHAR(15),
email VARCHAR(100),
address TEXT,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
-- Stock Entries
CREATE TABLE IF NOT EXISTS stock_entries (
id INT PRIMARY KEY AUTO_INCREMENT,
product_id INT NOT NULL,
supplier_id INT,
quantity_added INT NOT NULL,
added_by INT NOT NULL,
added_date TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
FOREIGN KEY (product_id) REFERENCES products(id),
FOREIGN KEY (supplier_id) REFERENCES suppliers(id),
FOREIGN KEY (added_by) REFERENCES users(id),
INDEX idx_stock_product (product_id)
);
-- Sales
CREATE TABLE IF NOT EXISTS sales (
id INT PRIMARY KEY AUTO_INCREMENT,
cashier_id INT NOT NULL,
total_amount DECIMAL(10,2) NOT NULL,
tax_amount DECIMAL(10,2) DEFAULT 0.00,
sale_date TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
FOREIGN KEY (cashier_id) REFERENCES users(id),
INDEX idx_sales_date (sale_date)
);
-- Sale Items
CREATE TABLE IF NOT EXISTS sale_items (
id INT PRIMARY KEY AUTO_INCREMENT,
sale_id INT NOT NULL,
product_id INT NOT NULL,
quantity INT NOT NULL,
unit_price DECIMAL(10,2) NOT NULL,
subtotal DECIMAL(10,2) NOT NULL,
FOREIGN KEY (sale_id) REFERENCES sales(id),
FOREIGN KEY (product_id) REFERENCES products(id),
INDEX idx_sale_items_sale (sale_id),
INDEX idx_sale_items_product (product_id)
);
-- Seed: default admin — password is "admin123"
INSERT IGNORE INTO users (name, email, password, role)
VALUES ('Admin', 'admin@storetrack.com',
'240be518fabd2724ddb6f04eeb1da5967448d7e831c08c8fa822809f74c720a9', 'ADMIN');
-- Seed categories
INSERT IGNORE INTO categories (id, name, description) VALUES
(1, 'Beverages', 'Drinks and liquid refreshments'),
(2, 'Snacks', 'Chips, biscuits, and packaged snacks'),
(3, 'Dairy', 'Milk, cheese, butter, and dairy products'),
(4, 'Stationery', 'Pens, notebooks, and office supplies');
-- Seed suppliers
INSERT IGNORE INTO suppliers (id, name, phone, email, address) VALUES
(1, 'Metro Wholesale', '9876543210', 'metro@example.com', 'MG Road, Mumbai'),
(2, 'FreshDairy Co.', '9123456789', 'freshdairy@example.com', 'Pune, Maharashtra');
-- Seed products
INSERT IGNORE INTO products (id, name, category_id, buying_price, selling_price, quantity, min_quantity, unit) VALUES
(1, 'Coca-Cola 500ml', 1, 20.00, 28.00, 50, 10, 'bottles'),
(2, 'Lays Classic 40g', 2, 15.00, 20.00, 8, 15, 'packets'),
(3, 'Amul Butter 500g', 3, 220.00, 260.00, 20, 5, 'pcs'),
(4, 'Classmate Notebook', 4, 35.00, 50.00, 30, 10, 'pcs');