brownsys / K9db

MySQL-compatible database for GDPR compliance by construction.
MIT License
28 stars 0 forks source link

Data subject within non-data subject table (sample application: Mouthful) #171

Open benkilimnik opened 1 year ago

benkilimnik commented 1 year ago

Encountered in the sample application schema for Mouthful located in experiments/schema-annot/annotated/mouthful-annotated.sql

K9db cannot accurately capture the Author column in the Comment table which refers to a data subject that owns all data. (The entire application contains just two tables: Comment and Thread).

CREATE TABLE Thread(
    Id int PRIMARY KEY,
    CreatedAt datetime not null,
    Path text not null
);

CREATE TABLE Comment(
    Id int PRIMARY KEY,
    ThreadId int not null,
    Body text not null,
    Author text not null,
    Confirmed int not null,
    CreatedAt datetime not null,
    ReplyTo int not null,
    DeletedAt datetime not null,
    FOREIGN KEY(ThreadId) references Thread(Id),
);

Work around: modify schema by adding a separate user table

CREATE DATA_SUBJECT TABLE user (
    id text PRIMARY KEY
);

and then adding a foreign key to user(id) in Comment

FOREIGN KEY(Author) OWNED_BY user(id)