diff --git a/src/main/java/dev/nmarulo/depensaapp/app/productshoppinglist/ProductHasShoppingList.java b/src/main/java/dev/nmarulo/depensaapp/app/productshoppinglist/ProductHasShoppingList.java index 620ba9e..5886438 100644 --- a/src/main/java/dev/nmarulo/depensaapp/app/productshoppinglist/ProductHasShoppingList.java +++ b/src/main/java/dev/nmarulo/depensaapp/app/productshoppinglist/ProductHasShoppingList.java @@ -4,10 +4,14 @@ import dev.nmarulo.depensaapp.app.shoppinglist.ShoppingList; import dev.nmarulo.depensaapp.app.unitytypes.UnitType; import dev.nmarulo.depensaapp.commons.gson.GsonExclude; +import jakarta.persistence.*; import lombok.*; +import org.springframework.data.annotation.CreatedDate; +import org.springframework.data.annotation.LastModifiedDate; +import org.springframework.data.jpa.domain.support.AuditingEntityListener; -import jakarta.persistence.*; import java.math.BigDecimal; +import java.time.LocalDateTime; import java.util.Objects; @AllArgsConstructor @@ -15,6 +19,7 @@ @Getter @Setter @Entity +@EntityListeners(AuditingEntityListener.class) @Table(name = "products_has_shopping_list") @ToString public class ProductHasShoppingList { @@ -37,6 +42,16 @@ public class ProductHasShoppingList { @Column(name = "selected", nullable = false) private boolean selected; + @Basic + @CreatedDate + @Column(name = "created_at", updatable = false) + private LocalDateTime createdAt; + + @Basic + @LastModifiedDate + @Column(name = "updated_at") + private LocalDateTime updatedAt; + @ManyToOne(fetch = FetchType.LAZY) @JoinColumn(name = "product_id", insertable = false, updatable = false) @ToString.Exclude diff --git a/src/main/resources/db/migration/mysql/V3__add_columns_products_has_shopping_list.sql b/src/main/resources/db/migration/mysql/V3__add_columns_products_has_shopping_list.sql new file mode 100644 index 0000000..e1582df --- /dev/null +++ b/src/main/resources/db/migration/mysql/V3__add_columns_products_has_shopping_list.sql @@ -0,0 +1,5 @@ +ALTER TABLE products_has_shopping_list + ADD created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP NOT NULL; + +ALTER TABLE products_has_shopping_list + ADD updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP NOT NULL;