create user telegram_bot@localhost IDENTIFIED BY "telegram_bot";

grant all on telegram_bot.* to telegram_bot@localhost;

flush privileges;

create database telegram_bot;

use telegram_bot;


CREATE TABLE manufature (
    mnf CHAR(50) PRIMARY KEY,
    name VARCHAR(255) DEFAULT '' NOT NULL,
    site VARCHAR(255),
    email VARCHAR(255),
    INDEX (name)
);

CREATE TABLE function (
    function_id CHAR(50) PRIMARY KEY,
    name VARCHAR(255) DEFAULT '' NOT NULL,
    description TEXT,
    INDEX (name)
);

CREATE TABLE case_type (
    case_id CHAR(50) PRIMARY KEY,
    description TEXT DEFAULT '',
    url_image VARCHAR(255)
);

CREATE TABLE smd_code (
    id CHAR(50) PRIMARY KEY,
    mnf CHAR(50),
    function_id CHAR(50),
    case_type CHAR(50),
    code VARCHAR(50),
    description TEXT,
    FOREIGN KEY (mnf) REFERENCES manufature(mnf),
    FOREIGN KEY (function_id) REFERENCES function(function_id),
    FOREIGN KEY (case_type) REFERENCES case_type(case_id)
);
