Database upgrade and Foreign Keys

Needs more testing but implemented foreign keys. Hopefully this will
make routing easier. Updated the testing accordingly. Refactored many
names, so I will have to update that in the front-end.