Nonverbis

Untitled

Dec 2nd, 2020 (edited)
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.51 KB | None | 0 0
  1. @Entity
  2. @Table(name="posts_post",
  3. indexes = { @Index(name = "created", columnList = "created"),
  4. @Index(name = "updated", columnList = "updated"),
  5. @Index(name = "slug", columnList = "slug"),},
  6. uniqueConstraints = {
  7. @UniqueConstraint(name = "slug_unique_constraint", columnNames= "slug"),
  8. })
  9. @Getter
  10. @Setter
  11. @NoArgsConstructor
  12. public class PostEntity {
  13. @Id
  14. @GeneratedValue(strategy = GenerationType.IDENTITY)
  15. private int id;
  16.  
  17. @CreationTimestamp
  18. @Column(nullable = false)
  19. private LocalDateTime created;
  20.  
  21. @UpdateTimestamp
  22. @Column(nullable = false)
  23. private LocalDateTime updated;
  24.  
  25.  
  26. @Column(nullable = false, columnDefinition = "TEXT")
  27. private String text;
  28.  
  29. @Column(nullable = false)
  30. private String slug;
  31.  
  32. @ManyToOne
  33. @JoinColumn(foreignKey=@ForeignKey(name="AUTHOR_POSTS_FK"), nullable = false)
  34. private AuthorEntity author;
  35.  
  36.  
  37. @ManyToOne
  38. @JoinColumn(foreignKey=@ForeignKey(name="CATEGORY_POSTS_FK"), nullable = false)
  39. private CategoryEntity category;
  40.  
  41. public PostEntity(String slug,
  42. String text,
  43. AuthorEntity author,
  44. CategoryEntity category) {
  45. this.slug = slug;
  46. this.text = text;
  47. this.author = author;
  48. this.category = category;
  49. }
  50. }
  51.  
  52.  
  53.  
  54.  
  55.  
  56. blog=# \d posts_post
  57. Table "public.posts_post"
  58. Column | Type | Collation | Nullable | Default
  59. -------------+-----------------------------+-----------+----------+----------------------------------
  60. id | integer | | not null | generated by default as identity
  61. created | timestamp without time zone | | not null |
  62. slug | character varying(255) | | not null |
  63. text | text | | not null |
  64. updated | timestamp without time zone | | not null |
  65. author_id | integer | | not null |
  66. category_id | integer | | not null |
  67. Indexes:
  68. "posts_post_pkey" PRIMARY KEY, btree (id)
  69. "created" btree (created)
  70. "updated" btree (updated)
  71. Foreign-key constraints:
  72. "author_posts_fk" FOREIGN KEY (author_id) REFERENCES authors_author(id)
  73. "category_posts_fk" FOREIGN KEY (category_id) REFERENCES categories_category(id)
  74.  
Advertisement
Add Comment
Please, Sign In to add comment