-
Notifications
You must be signed in to change notification settings - Fork 0
/
db.sql
46 lines (40 loc) · 1.72 KB
/
db.sql
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
CREATE TABLE batteries (
id INT AUTO_INCREMENT PRIMARY KEY,
eanGtin VARCHAR(255) NOT NULL,
weight FLOAT NOT NULL,
brand VARCHAR(255) NOT NULL,
model VARCHAR(255) NOT NULL,
size VARCHAR(255) NOT NULL,
chemistry VARCHAR(255) NOT NULL,
voltage VARCHAR(255) NOT NULL,
minCapacity FLOAT NOT NULL,
typCapacity FLOAT NOT NULL,
version VARCHAR(255) NOT NULL,
dischargeCurrent FLOAT NOT NULL,
circuitProtection VARCHAR(255) NOT NULL,
height FLOAT NOT NULL,
diameter FLOAT NOT NULL,
created_at TIMESTAMP NOT NULL DEFAULT NOW(),
updated_at TIMESTAMP NOT NULL DEFAULT NOW() ON UPDATE NOW()
);
CREATE TABLE `battery_prices` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`batteryId` int(11) NOT NULL,
`price` float NOT NULL,
`priceReduced` float DEFAULT NULL,
`createdAt` timestamp NOT NULL DEFAULT current_timestamp(),
`updatedAt` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(),
PRIMARY KEY (`id`),
KEY `batteryId` (`batteryId`),
CONSTRAINT `battery_prices_ibfk_1` FOREIGN KEY (`batteryId`) REFERENCES `batteries` (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=910 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;
CREATE TABLE sourcers(
id INT auto_increment PRIMARY KEY,
`name` VARCHAR(255) NOT NULL,
createdAt TIMESTAMP NOT NULL DEFAULT NOW(),
updatedAt TIMESTAMP NOT NULL DEFAULT NOW() ON UPDATE NOW()
);
ALTER TABLE battery_prices ADD COLUMN `sourcerId` INT NOT NULL DEFAULT 1 REFERENCES sourcers(`id`) AFTER `batteryId`;
ALTER TABLE batteries CHANGE COLUMN `created_at` `createdAt` TIMESTAMP NOT NULL DEFAULT NOW();
ALTER TABLE batteries CHANGE COLUMN `updated_at` `updatedAt` TIMESTAMP NOT NULL DEFAULT NOW() ON UPDATE NOW();
ALTER TABLE `batteries` CHANGE COLUMN `voltage` `voltage` float NULL;