package io.crowdcode.flaschenlager.stock.model;

import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
import lombok.experimental.Accessors;

import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Index;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.Version;
import javax.validation.constraints.NotNull;
import java.math.BigDecimal;
import java.time.LocalDateTime;

@Entity
@Getter
@Setter
@Accessors(chain = true)
@EqualsAndHashCode(of = {"id", "version"})
@ToString(exclude = "stock")
@Table(indexes = @Index(name = "product_added", columnList = "productId,addedAt"))
public class StockEntry {

    @Id
    @GeneratedValue
    private Long id;

    @Version
    private Long version;

    @NotNull
    private Long productId;

    @NotNull
    private Long quantity;

    @NotNull
    private BigDecimal price;

    @NotNull
    private LocalDateTime addedAt;

    @ManyToOne
    private Stock stock;
}

@@ -683,16 +683,22 @@
  = %22
+stock_
 product_
 adde
@@ -693,16 +693,25 @@
 product_
+quantity_
 added%22, 
@@ -728,24 +728,42 @@
  = %22
+stock_id,
 product
-I
+i
 d,
+quantity,
 added
-A
+a
 t%22))

fix index definition