-- init.sql
CREATE DATABASE IF NOT EXISTS elio_test;
CREATE DATABASE IF NOT EXISTS elio;


-- Haupttabellen erzeugen
CREATE TABLE IF NOT EXISTS elio.blablabla (
    id INT AUTO_INCREMENT PRIMARY KEY,
    warehouse char(2) NOT NULL,
    productid VARCHAR(20) NOT NULL,
    amount INT DEFAULT 0,
    created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
    CONSTRAINT location_product_must_be_one UNIQUE (warehouse, productid)
) ENGINE=InnoDB;

CREATE TABLE IF NOT EXISTS elio.deliverytimes (
    id INT AUTO_INCREMENT PRIMARY KEY,
    fromcountry varchar(4) NOT NULL,
    tocountry varchar(4) NOT NULL,
    state varchar(4) NULL,
    delivery INT DEFAULT 0,
    created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
    CONSTRAINT delivery_from_to_country_must_be_one UNIQUE (fromcountry, tocountry)
) ENGINE=InnoDB;

-- Testtabellen erzeugen
CREATE TABLE IF NOT EXISTS elio_test.warehouseproducts (
    id INT AUTO_INCREMENT PRIMARY KEY,
    warehouse char(2) NOT NULL,
    productid VARCHAR(20) NOT NULL,
    amount INT DEFAULT 0,
    created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
    CONSTRAINT location_product_must_be_one UNIQUE (warehouse, productid)
) ENGINE=InnoDB;

CREATE TABLE IF NOT EXISTS elio_test.deliverytimes (
    id INT AUTO_INCREMENT PRIMARY KEY,
    fromcountry varchar(4) NOT NULL,
    tocountry varchar(4) NOT NULL,
    state varchar(4) NULL,
    delivery INT DEFAULT 0,
    created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
    CONSTRAINT delivery_from_to_country_must_be_one UNIQUE (fromcountry, tocountry)
) ENGINE=InnoDB;

-- Userkram
CREATE USER IF NOT EXISTS 'elio'@'%' IDENTIFIED BY 'eliogeheim';
CREATE USER IF NOT EXISTS 'elio_test'@'%' IDENTIFIED BY 'eliogeheim';
GRANT ALL PRIVILEGES ON elio.* TO 'elio'@'%';
GRANT ALL PRIVILEGES ON elio_test.* TO 'elio_test'@'%';
FLUSH PRIVILEGES;
