-- Convert schema './FileFormats-Schema-0.03-MySQL.sql' to 'FileFormats::Schema v0.04':

BEGIN;

SET foreign_key_checks=0;


CREATE TABLE enum_values (
  enum_id integer NOT NULL,
  value text NOT NULL,
  translation text NOT NULL,
  INDEX enum_values_idx_enum_id (enum_id),
  PRIMARY KEY (enum_id, value),
  CONSTRAINT enum_values_fk_enum_id FOREIGN KEY (enum_id) REFERENCES types (id)
) ENGINE=InnoDB;


SET foreign_key_checks=1;


ALTER TABLE recurring_terminated CHANGE COLUMN terminator terminator text NOT NULL;
ALTER TABLE structure_fields DROP INDEX ,
                             DROP FOREIGN KEY fk_enum_id,
                             DROP INDEX enum_id,
                             DROP COLUMN enum_id,
                             DROP COLUMN translation,
                             ADD COLUMN struct_id integer NOT NULL,
                             ADD COLUMN field_id integer NOT NULL,
                             ADD COLUMN name varchar(255) NOT NULL,
                             ADD COLUMN position integer NOT NULL,
                             ADD COLUMN type_id integer NOT NULL,
                             ADD COLUMN comments text NOT NULL,
                             CHANGE COLUMN value value text NOT NULL,
                             ADD INDEX structure_fields_idx_struct_id (struct_id),
                             ADD INDEX structure_fields_idx_type_id (type_id),
                             ADD PRIMARY KEY (struct_id, field_id),
                             ADD CONSTRAINT structure_fields_fk_struct_id FOREIGN KEY (struct_id) REFERENCES types (id),
                             ADD CONSTRAINT structure_fields_fk_type_id FOREIGN KEY (type_id) REFERENCES types (id);
ALTER TABLE systems CHANGE COLUMN comments comments text NOT NULL;
ALTER TABLE types CHANGE COLUMN comments comments text;

COMMIT;

