What is the entity-relationship model of the pizzeria?
Our entity-relationship model for the pizzeria project database is composed of four fundamental tables: pizza
, pizza_order
, order_item
and customer
. Here we briefly break down each of these tables and their functions:
-
Pizza
table:
- Pizza ID: Unique identifier for each pizza.
- Name and description: Detailed information of the pizza.
- Price: Decimal type 5,2 (five digits in total, two after the dot).
- Boolean attributes: Identification of whether the pizza is vegetarian, vegan or available by using
tinyint
columns.
-
Table pizza_order
:
- Order ID: Unique identifier of each order.
- Relationship to
customer
: Using customer ID
as foreign key.
- Order date: Time stamp of order creation.
- Total value: Sum of the cost of all pizzas in the order.
- Delivery method: Stores in one character whether the order is take-out, pick-up or eat-in.
- Additional notes: Record for customer specific remarks about the order.
-
Customer
table:
- Customer ID: Unique identification of each customer.
- Customer data: Includes name, address, email and phone number.
-
Table order_item
:
- One-to-one relationship with
pizza
: Each order item has a link to a specific pizza.
- One-to-many relationship with
pizza_order
: An order can have multiple items.
- Primary keys: Composed by
item ID
and order ID
.
- Quantity and price: Quantity management and price adjustments according to the number of pizzas ordered.
How to connect the project to the database?
To connect our project to a MySQL database from IntelliJ IDEA
, we must edit the application.properties
file in the resources
directory. Here we must put four essential instructions to establish the connection:
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driverspring.datasource.url=jdbc:mysql://localhost:3306/fixeria?createDatabaseIfNotExist=truespring.datasource.username=rootspring.datasource.password=admin
What parameters are essential in application.properties
?
spring.datasource.driver-class-name
: Specifies the database type.
spring.datasource.url
: Address and name of the database along with the createDatabaseIfNotExist=true
statement for MySQL.
spring.datasource.username
and password
: Database access credentials.
Advanced configuration: How to use Hikari CP
and Spring JPA
?
What is Hikari CP
for?
Hikari CP
is an automatic database connection manager, optimizing the number of connections according to the number of users in the application. It provides better performance and is essential for the efficiency and scalability of the system.
How to configure Spring JPA
?
To dynamically manage the database schema, we can add and configure Spring JPA
:
spring.jpa.hibernate.ddl-auto=updatespring.jpa.show-sql=true
spring.jpa.hibernate.ddl-auto
:
update
: Adapts to the schema when synchronizing changes without losing data.
spring.jpa.show-sql
: Allows to visualize in the console the SQL actions performed by our application.
These configurations allow the database structure to be automatically updated from the entities defined in our project. In addition, enabling show-sql
helps us to verify and analyze how our actions affect the database in real time.
How to adapt the new IntelliJ IDEA
interface?
Finally, to take advantage of IntelliJ IDEA
's updates to its interface, we can enable the "New UI" in Appearance & Behavior.
This will allow us to familiarize ourselves with a more modern and efficient interface. Simply enable the interface, apply the changes and restart IntelliJ IDEA
.
Using these options not only enhances the development experience, but also optimizes project management in a database environment. By continuing to learn and explore new tools and configurations, you enhance your ability to create robust and efficient applications. Go ahead and explore more on this exciting learning journey!
Want to see more contributions, questions and answers from the community?