Skip to content

Commit

Permalink
adjusted rental entity and added an appropriate liquibase file
Browse files Browse the repository at this point in the history
  • Loading branch information
ivan0dyatlyukkk committed Oct 2, 2023
1 parent ec5eeee commit 5a6569b
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 14 deletions.
25 changes: 13 additions & 12 deletions src/main/java/com/project/carsharingapp/model/Rental.java
Original file line number Diff line number Diff line change
@@ -1,34 +1,35 @@
package com.project.carsharingapp.model;

import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.Table;
import jakarta.persistence.*;

import java.time.LocalDateTime;
import lombok.Getter;
import lombok.Setter;
import org.hibernate.annotations.SQLDelete;
import org.hibernate.annotations.Where;

@Entity
@Getter
@Setter
@SQLDelete(sql = "UPDATE rentals SET is_deleted = true WHERE id = ?")
@Where(clause = "is_deleted=false")
@Entity
@Table(name = "rentals")
public class Rental {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@Column(name = "rental_date", nullable = false)
private LocalDateTime rentalDate;
@Column(name = "return_date", nullable = false)
private LocalDateTime returnDate;
@Column(name = "actual_return_date")
private LocalDateTime actualReturnDate;
//@OneToOne(fetch = FetchType.LAZY)
//private Car car;
// @ManyToOne(fetch = FetchType.LAZY)
// private User user;
@Column(nullable = false)
@OneToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "car_id", nullable = false)
private Car car;
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "user_id", nullable = false)
private User user;
@Column(name = "is_deleted",nullable = false)
private boolean isDeleted;
}
48 changes: 48 additions & 0 deletions src/main/resources/db/changelog/changes/create-rentals-table.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
databaseChangeLog:
- changeSet:
id: create-rentals-table
author: ivan-diatliuk
changes:
- createTable:
tableName: rentals
columns:
- column:
name: id
type: bigint
autoIncrement: true
constraints:
nullable: false
primaryKey: true
- column:
name: rental_date
type: timestamp
constraints:
nullable: false
- column:
name: return_date
type: timestamp
constraints:
nullable: false
- column:
name: actual_return_date
type: timestamp
- column:
name: car_id
type: bigint
constraints:
nullable: false
foreignKeyName: fk_car_id
references: cars(id)
- column:
name: user_id
type: bigint
constraints:
nullable: false
foreignKeyName: fk_user_id
references: users(id)
- column:
name: is_deleted
type: boolean
defaultValueBoolean: false
constraints:
nullable: false
6 changes: 4 additions & 2 deletions src/main/resources/db/changelog/db.changelog-master.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ databaseChangeLog:
- include:
file: db/changelog/changes/create-roles-table.yaml
- include:
file: /db/changelog/changes/create-users-table.yaml
file: db/changelog/changes/create-users-table.yaml
- include:
file: /db/changelog/changes/create-user-roles-table.yaml
file: db/changelog/changes/create-user-roles-table.yaml
- include:
file: db/changelog/changes/create-rentals-table.yaml

0 comments on commit 5a6569b

Please sign in to comment.