-- +goose Up
-- Staging table set for legacy medicine dump format:
-- - cmedikamente_group
-- - cmotorische_reaktion
-- - cmedikamente

CREATE TABLE IF NOT EXISTS cmedikamente_group_old_import (
  id INT(11) NOT NULL,
  name VARCHAR(255) DEFAULT NULL,
  PRIMARY KEY (id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci;

CREATE TABLE IF NOT EXISTS cmotorische_old_import (
  id INT(11) NOT NULL,
  name VARCHAR(255) DEFAULT NULL,
  ball INT(11) DEFAULT NULL,
  PRIMARY KEY (id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci;

CREATE TABLE IF NOT EXISTS cmedikamente_old_import (
  id INT(11) NOT NULL,
  name VARCHAR(255) DEFAULT NULL,
  dose VARCHAR(255) DEFAULT NULL,
  weight INT(11) DEFAULT NULL,
  col INT(11) DEFAULT NULL,
  cmedikamente_group_id INT(11) DEFAULT NULL,
  PRIMARY KEY (id),
  KEY idx_cmedikamente_old_group_id (cmedikamente_group_id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci;

CREATE TABLE IF NOT EXISTS cmedikamente_group_old_id_map (
  old_id INT(11) NOT NULL,
  new_id BINARY(16) NOT NULL,
  PRIMARY KEY (old_id),
  UNIQUE KEY uq_cmedikamente_group_old_new_id (new_id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci;

CREATE TABLE IF NOT EXISTS cmotorische_old_id_map (
  old_id INT(11) NOT NULL,
  new_id BINARY(16) NOT NULL,
  PRIMARY KEY (old_id),
  UNIQUE KEY uq_cmotorische_old_new_id (new_id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci;

CREATE TABLE IF NOT EXISTS cmedikamente_old_id_map (
  old_id INT(11) NOT NULL,
  new_id BINARY(16) NOT NULL,
  PRIMARY KEY (old_id),
  UNIQUE KEY uq_cmedikamente_old_new_id (new_id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci;

-- +goose Down
DROP TABLE IF EXISTS cmedikamente_old_id_map;
DROP TABLE IF EXISTS cmotorische_old_id_map;
DROP TABLE IF EXISTS cmedikamente_group_old_id_map;
DROP TABLE IF EXISTS cmedikamente_old_import;
DROP TABLE IF EXISTS cmotorische_old_import;
DROP TABLE IF EXISTS cmedikamente_group_old_import;
