CREATE TABLE IF NOT EXISTS takeover_acs (
  id BINARY(16) NOT NULL PRIMARY KEY,
  takeover_id BINARY(16) NOT NULL,
  base_id BINARY(16) NULL,
  reserve_ac_id BINARY(16) NULL,
  created_at DATETIME(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6),
  created_by BINARY(16) NULL,
  updated_at DATETIME(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6),
  updated_by BINARY(16) NULL,
  deleted_at DATETIME(6) NULL,
  deleted_by BINARY(16) NULL,
  KEY idx_takeover_acs_takeover_id (takeover_id)
);

CREATE TABLE IF NOT EXISTS takeover_flights (
  id BINARY(16) NOT NULL PRIMARY KEY,
  takeover_id BINARY(16) NOT NULL,
  date_time DATETIME(6) NOT NULL,
  status VARCHAR(32) NOT NULL DEFAULT 'draft',
  alarm_time DATETIME(6) NULL,
  created_at DATETIME(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6),
  created_by BINARY(16) NULL,
  updated_at DATETIME(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6),
  updated_by BINARY(16) NULL,
  deleted_at DATETIME(6) NULL,
  deleted_by BINARY(16) NULL,
  KEY idx_takeover_flights_takeover_id (takeover_id)
);

CREATE TABLE IF NOT EXISTS takeover_roster_crews (
  id BINARY(16) NOT NULL PRIMARY KEY,
  takeover_id BINARY(16) NOT NULL,
  crew_id BINARY(16) NOT NULL,
  confirm_at DATETIME(6) NULL,
  created_at DATETIME(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6),
  created_by BINARY(16) NULL,
  updated_at DATETIME(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6),
  updated_by BINARY(16) NULL,
  deleted_at DATETIME(6) NULL,
  deleted_by BINARY(16) NULL,
  KEY idx_takeover_roster_crews_takeover_id (takeover_id)
);

CREATE TABLE IF NOT EXISTS takeover_other_people (
  id BINARY(16) NOT NULL PRIMARY KEY,
  takeover_id BINARY(16) NOT NULL,
  name VARCHAR(191) NULL,
  mobile_phone VARCHAR(64) NULL,
  email VARCHAR(191) NULL,
  created_at DATETIME(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6),
  created_by BINARY(16) NULL,
  updated_at DATETIME(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6),
  updated_by BINARY(16) NULL,
  deleted_at DATETIME(6) NULL,
  deleted_by BINARY(16) NULL,
  KEY idx_takeover_other_people_takeover_id (takeover_id)
);

