-- +goose Up
-- Prepare staging tables for legacy medicine import:
-- - cmedikamente
-- - cmedikamente_group
-- - cmotorische_reaktion

CREATE TABLE IF NOT EXISTS medicine_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 medicine_group_old_id_map (
  old_id int(11) NOT NULL,
  new_id binary(16) NOT NULL,
  PRIMARY KEY (old_id),
  UNIQUE KEY uq_medicine_group_old_id_map_new_id (new_id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci;

CREATE TABLE IF NOT EXISTS motor_reaction_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 motor_reaction_old_id_map (
  old_id int(11) NOT NULL,
  new_id binary(16) NOT NULL,
  PRIMARY KEY (old_id),
  UNIQUE KEY uq_motor_reaction_old_id_map_new_id (new_id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci;

CREATE TABLE IF NOT EXISTS medicine_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,
  motor_reaction_old_id int(11) DEFAULT NULL,
  PRIMARY KEY (id),
  KEY idx_medicine_old_import_group (cmedikamente_group_id),
  KEY idx_medicine_old_import_reaction (motor_reaction_old_id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci;

CREATE TABLE IF NOT EXISTS medicine_old_id_map (
  old_id int(11) NOT NULL,
  new_id binary(16) NOT NULL,
  PRIMARY KEY (old_id),
  UNIQUE KEY uq_medicine_old_id_map_new_id (new_id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci;

-- +goose Down
DROP TABLE IF EXISTS medicine_old_id_map;
DROP TABLE IF EXISTS medicine_old_import;
DROP TABLE IF EXISTS motor_reaction_old_id_map;
DROP TABLE IF EXISTS motor_reaction_old_import;
DROP TABLE IF EXISTS medicine_group_old_id_map;
DROP TABLE IF EXISTS medicine_group_old_import;
