MME-13 WIP hibernate config annotations and migration.
This commit is contained in:
parent
d2beb2af0f
commit
6eead31193
@ -52,11 +52,10 @@ public class Recipe {
|
|||||||
@JoinColumn(name = "owner_id", nullable = false)
|
@JoinColumn(name = "owner_id", nullable = false)
|
||||||
private User owner;
|
private User owner;
|
||||||
|
|
||||||
@OneToMany
|
@OneToMany(mappedBy = "recipe", orphanRemoval = true, cascade = CascadeType.ALL)
|
||||||
@JoinColumn(name = "recipe_id")
|
|
||||||
private Set<RecipeStar> stars = new HashSet<>();
|
private Set<RecipeStar> stars = new HashSet<>();
|
||||||
|
|
||||||
@OneToMany(mappedBy = "recipe")
|
@OneToMany(mappedBy = "recipe", orphanRemoval = true, cascade = CascadeType.ALL)
|
||||||
private Set<RecipeComment> comments = new HashSet<>();
|
private Set<RecipeComment> comments = new HashSet<>();
|
||||||
|
|
||||||
@Column(nullable = false)
|
@Column(nullable = false)
|
||||||
|
|||||||
@ -1,9 +1,8 @@
|
|||||||
package app.mealsmadeeasy.api.recipe.star;
|
package app.mealsmadeeasy.api.recipe.star;
|
||||||
|
|
||||||
import jakarta.persistence.Column;
|
import app.mealsmadeeasy.api.recipe.Recipe;
|
||||||
import jakarta.persistence.EmbeddedId;
|
import app.mealsmadeeasy.api.user.User;
|
||||||
import jakarta.persistence.Entity;
|
import jakarta.persistence.*;
|
||||||
import jakarta.persistence.Table;
|
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
|
||||||
import java.time.OffsetDateTime;
|
import java.time.OffsetDateTime;
|
||||||
@ -16,6 +15,16 @@ public final class RecipeStar {
|
|||||||
@EmbeddedId
|
@EmbeddedId
|
||||||
private RecipeStarId id;
|
private RecipeStarId id;
|
||||||
|
|
||||||
|
@ManyToOne
|
||||||
|
@MapsId("ownerId")
|
||||||
|
@JoinColumn(name = "owner_id", nullable = false, updatable = false)
|
||||||
|
private User owner;
|
||||||
|
|
||||||
|
@ManyToOne
|
||||||
|
@MapsId("recipeId")
|
||||||
|
@JoinColumn(name = "recipe_id", nullable = false, updatable = false)
|
||||||
|
private Recipe recipe;
|
||||||
|
|
||||||
@Column(nullable = false, updatable = false)
|
@Column(nullable = false, updatable = false)
|
||||||
private OffsetDateTime timestamp = OffsetDateTime.now();
|
private OffsetDateTime timestamp = OffsetDateTime.now();
|
||||||
|
|
||||||
|
|||||||
@ -0,0 +1,47 @@
|
|||||||
|
ALTER TABLE user_granted_authority DROP CONSTRAINT user_granted_authority_user_id_fkey;
|
||||||
|
ALTER TABLE user_granted_authority ADD FOREIGN KEY (user_id) REFERENCES "user" ON DELETE CASCADE;
|
||||||
|
|
||||||
|
ALTER TABLE refresh_token DROP CONSTRAINT refresh_token_owner_id_fkey;
|
||||||
|
ALTER TABLE refresh_token ADD FOREIGN KEY (owner_id) REFERENCES "user" ON DELETE CASCADE;
|
||||||
|
|
||||||
|
ALTER TABLE image DROP CONSTRAINT image_owner_id_fkey;
|
||||||
|
ALTER TABLE image ADD FOREIGN KEY (owner_id) REFERENCES "user" ON DELETE CASCADE;
|
||||||
|
|
||||||
|
ALTER TABLE image_viewer DROP CONSTRAINT image_viewer_image_id_fkey;
|
||||||
|
ALTER TABLE image_viewer ADD FOREIGN KEY (image_id) REFERENCES image ON DELETE CASCADE;
|
||||||
|
|
||||||
|
ALTER TABLE image_viewer DROP CONSTRAINT image_viewer_viewer_id_fkey;
|
||||||
|
ALTER TABLE image_viewer ADD FOREIGN KEY (viewer_id) REFERENCES "user" ON DELETE CASCADE;
|
||||||
|
|
||||||
|
ALTER TABLE recipe DROP CONSTRAINT recipe_owner_id_fkey;
|
||||||
|
ALTER TABLE recipe ADD FOREIGN KEY (owner_id) REFERENCES "user" ON DELETE CASCADE;
|
||||||
|
|
||||||
|
ALTER TABLE recipe DROP CONSTRAINT recipe_main_image_id_fkey;
|
||||||
|
ALTER TABLE recipe ADD FOREIGN KEY (main_image_id) REFERENCES image ON DELETE SET NULL;
|
||||||
|
|
||||||
|
ALTER TABLE recipe_viewer DROP CONSTRAINT recipe_viewer_recipe_id_fkey;
|
||||||
|
ALTER TABLE recipe_viewer ADD FOREIGN KEY (recipe_id) REFERENCES recipe ON DELETE CASCADE;
|
||||||
|
|
||||||
|
ALTER TABLE recipe_viewer DROP CONSTRAINT recipe_viewer_viewer_id_fkey;
|
||||||
|
ALTER TABLE recipe_viewer ADD FOREIGN KEY (viewer_id) REFERENCES "user" ON DELETE CASCADE;
|
||||||
|
|
||||||
|
ALTER TABLE recipe_comment DROP CONSTRAINT recipe_comment_owner_id_fkey;
|
||||||
|
ALTER TABLE recipe_comment ADD FOREIGN KEY (owner_id) REFERENCES "user" ON DELETE CASCADE;
|
||||||
|
|
||||||
|
ALTER TABLE recipe_comment DROP CONSTRAINT recipe_comment_recipe_id_fkey;
|
||||||
|
ALTER TABLE recipe_comment ADD FOREIGN KEY (recipe_id) REFERENCES recipe ON DELETE CASCADE;
|
||||||
|
|
||||||
|
ALTER TABLE recipe_star DROP CONSTRAINT recipe_star_recipe_id_fkey;
|
||||||
|
ALTER TABLE recipe_star ADD FOREIGN KEY (recipe_id) REFERENCES recipe ON DELETE CASCADE;
|
||||||
|
|
||||||
|
ALTER TABLE recipe_star DROP CONSTRAINT recipe_star_owner_id_fkey;
|
||||||
|
ALTER TABLE recipe_star ADD FOREIGN KEY (owner_id) REFERENCES "user" ON DELETE CASCADE;
|
||||||
|
|
||||||
|
ALTER TABLE recipe_draft DROP CONSTRAINT recipe_draft_owner_id_fkey;
|
||||||
|
ALTER TABLE recipe_draft ADD FOREIGN KEY (owner_id) REFERENCES "user" ON DELETE CASCADE;
|
||||||
|
|
||||||
|
ALTER TABLE recipe_draft DROP CONSTRAINT recipe_draft_main_image_id_fkey;
|
||||||
|
ALTER TABLE recipe_draft ADD FOREIGN KEY (main_image_id) REFERENCES image ON DELETE SET NULL;
|
||||||
|
|
||||||
|
ALTER TABLE file DROP CONSTRAINT file_owner_id_fkey;
|
||||||
|
ALTER TABLE file ADD FOREIGN KEY (owner_id) REFERENCES "user" ON DELETE CASCADE;
|
||||||
Loading…
Reference in New Issue
Block a user