database: fix table public_keys and aliases

Added foreign keys and fixed sqlalchemy class declaration
pylib: db session is now not shared between thread

additionaly added a method to close the session