Refactoring schema-checking logic for database