Fix migration problem and updated team invites management

- Fixed problem with migrations
- Added tests
- Updated team invites management