drop table metadata;

create table metadata(
   name varchar(50),
   comment varchar(200),
   private_key varchar(500),
   public_key varchar(500)
);

insert into metadata default vALUES;

drop table entity cascade;

create table entity(
   id INT GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
   creation_ts TIMESTAMPTZ NOT NULL DEFAULT now(),
   creator INT REFERENCES entity(id),
   name varchar(100) NOT NULL,
   group_p BOOLEAN NOT NULL,
   geo_offset BIGINT,
   --private_key VARCHAR(300) NOT NULL,
   public_key VARCHAR(300) NOT NULL,
   expiration DATE


);

drop table group_member;

create table group_member(
   group_id INT NOT NULL REFERENCES entity(id) ON DELETE CASCADE,
   person_id INT NOT NULL REFERENCES entity(id)  ON DELETE CASCADE,
   role VARCHAR(10),
   PRIMARY KEY (group_id,person_id)
);

drop table property;

create table property(
   id INT NOT NULL REFERENCES entity(id) ON DELETE CASCADE,
   property_name VARCHAR(100),
   PRIMARY KEY (id, property_name)
);
