drop index if exists accountdata_account; drop table if exists accountdata; drop index if exists contactrelationship_account; drop index if exists contactrelationship_contact; drop index if exists account_name; drop table if exists contactrelationship; drop table if exists account; drop table if exists contact; create table account ( id bigint primary key, name varchar(255) not null ); create index account_name on account (name); create table contact ( id bigint primary key, name varchar(255) not null, email varchar(255) unique not null -- unique forces an index ); create table contactrelationship ( id bigint primary key, account_id bigint not null, contact_id bigint not null, main boolean not null, foreign key (account_id) references account (id), foreign key (contact_id) references contact (id) ); create index contactrelationship_account on contactrelationship (account_id); create index contactrelationship_contact on contactrelationship (contact_id); create table accountdata ( id bigserial primary key, account_id bigint not null, stuff varchar(255), foreign key (account_id) references account (id) ); create index accountdata_account on accountdata (account_id);