Database schema and queries