ocp5/create-db-loff.sql
Fred Z 7d1f4418db Adds 'db_summary()' method
To lighten and improve the __init__
Now it can be re-called after the create-DB script
Exports messages template in 'config.py'
PyMysql seem not to accept 'CREATE TABLE IF NOT EXIST'
2018-08-03 00:41:17 +02:00

29 lines
876 B
SQL

-- ---------------------------------------------
-- Creates a local DB to avoid requesting API --
-- ---------------------------------------------
CREATE DATABASE loff CHARACTER SET 'utf8';
USE loff;
CREATE TABLE category(
`id`INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
`name` VARCHAR(200) UNIQUE
)ENGINE=InnoDB;
CREATE TABLE product(
`id` INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
`code` BIGINT UNSIGNED NOT NULL UNIQUE,
`url` VARCHAR(200),
`name` VARCHAR(200) UNIQUE,
`nutrition_grades` VARCHAR(1),
`category_id`INT UNSIGNED,
`substitute_id` INT UNSIGNED,
CONSTRAINT `fk_product_category`
FOREIGN KEY (category_id) REFERENCES category(id)
ON DELETE CASCADE,
CONSTRAINT `fk_product_substitute`
FOREIGN KEY (substitute_id) REFERENCES product(id)
ON DELETE SET NULL
)ENGINE=InnoDB;