Logic behind oc_shares / manually alter this table

i’m experiencing some trouble with database consistency. Where can i find the sql shema describing the database. I would like to try to write some management scripts for my nextcloud instance (e.g: cleaning oc_shares where some record have non-existing uid_owner and uid_initiator, etc).
I dug into the developer docs but didn’t found anything…
Thanks for your help.

Nextcloud version (eg, 18.0.2): 20.0.5
Operating system and version (eg, Ubuntu 20.04): Linux 5.4.80-gentoo-r1 x86_64
Apache or nginx version (eg, Apache 2.4.25): nginx-1.18.0-r2
PHP version (eg, 7.1): 7.4.13
Mariadb version: 10.4.17