Add mysql user id to token, and escape mysql query
Introduce foreign key dependencies between tables for consistency