Add schema validation to device API
Fix primary keys