Hello. I'm wondering how to design a database for Calorie Counter Application. There will be 3 basic classes:
I'm not sure if the structure is designed by me is good. Is there a better way to do it? Will the database be stable when there will be a lot of records?
CREATE TABLE IF NOT EXISTS `users`(
id INT NOT NULL PRIMARY KEY AUTO_INCREMENT,
username VARCHAR(45) NOT NULL UNIQUE,
password VARCHAR(45) NOT NULL,
age INT NOT NULL,
email VARCHAR(60) NOT NULL,
weight SMALLINT NOT NULL,
height SMALLINT NOT NULL,
gender ENUM ('male', 'female')
);
CREATE TABLE IF NOT EXISTS `meals`(
id INT NOT NULL PRIMARY KEY AUTO_INCREMENT,
created_at TIMESTAMP NOT NULL DEFAULT NOW(),
user_id int NOT NULL,
FOREIGN KEY (user_id) REFERENCES users(id)
);
CREATE TABLE IF NOT EXISTS `food_products`(
id INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
product_name VARCHAR(45) NOT NULL,
proteins DOUBLE NOT NULL,
fats DOUBLE NOT NULL,
carbohydrates DOUBLE NOT NULL,
meal_id INT NOT NULL,
FOREIGN KEY (meal_id) REFERENCES meals(id)
);
User class:
public class User {
private int id;
private String username;
private String password;
private int age;
private String email;
private short weight;
private short height;
private Gender gender;
private List<Meal> meals;
}
Meal class:
public class Meal {
private int id;
private ArrayList<FoodProduct> products;
private LocalDate date;
}
FoodProduct class:
public class FoodProduct {
private int id;
private String productName;
private Double proteins;
private Double fats;
private Double carbohydrates;
}