CREATE TABLE photos ( id serial not null primary key, "local_path" varchar not null unique, "hashed_path" varchar not null unique ); create table product_photos ( id serial not null primary key, product_id int references products (id) not null, photo_id int references photos (id) not null );