"""
Vytvoří tabulku covance_kit_inventory v databázi studie.
Spusť jednorázově pro inicializaci.
"""

import mysql.connector
import db_config

DDL = """
CREATE TABLE IF NOT EXISTS covance_kit_inventory (
    id                  INT AUTO_INCREMENT PRIMARY KEY,
    import_id           INT NOT NULL,
    study               VARCHAR(20)  NOT NULL,
    project_no          VARCHAR(10),
    region              VARCHAR(10),
    country             VARCHAR(10),
    site_code           VARCHAR(10),
    investigator_name   VARCHAR(100),
    kit_type            VARCHAR(10),
    description         VARCHAR(100),
    accession           VARCHAR(20),
    shipped_date        DATE,
    expiration_date     DATE,
    days_to_expiration  SMALLINT,
    FOREIGN KEY (import_id) REFERENCES iwrs_import(import_id),
    INDEX idx_import      (import_id),
    INDEX idx_site        (site_code),
    INDEX idx_accession   (accession),
    INDEX idx_expiration  (expiration_date)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
"""

conn = mysql.connector.connect(
    host=db_config.DB_HOST, port=db_config.DB_PORT,
    user=db_config.DB_USER, password=db_config.DB_PASSWORD,
    database=db_config.DB_NAME,
)
cursor = conn.cursor()
cursor.execute(DDL)
conn.commit()
cursor.close()
conn.close()
print("Tabulka covance_kit_inventory OK.")
