

create table entity (
  id VARCHAR(128) unique not null,
  project VARCHAR(128),
  instruction_data mediumblob,
  fitness double,
  generation int,
  image mediumblob,
  votes bigint not null default 0,
  votes_up bigint not null default 0,
  primary key(id)
) type=innodb;

create unique index entity_id_idx on entity(id);

create index entity_fitness_idx on entity(project, fitness);

create index entity_votes_idx on entity(project, votes);
create index entity_votes_up_idx on entity(project, votes_up);


create table top (
  id VARCHAR(128) unique not null,
  project VARCHAR(128),
  instruction_data mediumblob,
  fitness double,
  generation int,
  image mediumblob,
  created_at timestamp,
  primary key(id)
) type=innodb;

create unique index top_id_idx on top(id);

create index top_fitness_idx on top(project, fitness);
create index top_added_idx on top(project, created_at);




create table imagenest (
  id VARCHAR(128) unique not null,
  instruction_data mediumblob,
  fitness double,
  generation int,
  created_at timestamp null,
  votes bigint not null default 0,
  votes_up bigint not null default 0,
  is_active boolean default true,
  is_in_top boolean default false,
  added_to_top_at timestamp null,
  shop_url VARCHAR(255),
  primary key(id)
) type=innodb;

create unique index imagenest_id_idx on imagenest(id);

create index imagenest_fitness_idx on imagenest(fitness);
create index imagenest_votes_idx on imagenest(votes);
create index imagenest_votes_up_idx on imagenest(votes_up);
create index imagenest_top_idx on imagenest(added_to_top_at);

create table imagenest_votes (
  id BIGINT UNIQUE NOT NULL AUTO_INCREMENT,
  a VARCHAR(128),
  b VARCHAR(128),
  v VARCHAR(128),
  primary key(id)) type=innodb;

create unique index votes_id_idx on imagenest_votes(id);

create table imagenest_images (
  id varchar(128) not null,
  type varchar(32) not null,
  image mediumblob
  ) type=innodb;

create unique index imagenest_image_idx on imagenest_images(id,type);


create table processing (
  id VARCHAR(128),
  instruction_data mediumblob,
  fitness double,
  generation int,
  primary key(id)) type=innodb;

create unique index processing_id_idx on processing(id);
create index processing_fitness_idx on processing(fitness);



