Fix imports and make database schema more strict.

This commit is contained in:
Kavin 2022-07-18 21:22:46 +05:30
parent 14f8c55782
commit 0e8b17698d
No known key found for this signature in database
GPG Key ID: 49451E4482CC5BCD
6 changed files with 14 additions and 12 deletions

View File

@ -967,7 +967,7 @@ public class ResponseHelper {
if (user != null) {
Multithreading.runAsync(() -> {
try (StatelessSession s = DatabaseSessionFactory.createStatelessSession()) {
try (Session s = DatabaseSessionFactory.createSession()) {
if (override) {
user.setSubscribed(Set.of(channelIds));
} else {
@ -977,7 +977,7 @@ public class ResponseHelper {
if (channelIds.length > 0) {
var tr = s.beginTransaction();
s.update(user);
s.merge(user);
tr.commit();
}
} catch (Exception e) {

View File

@ -7,7 +7,7 @@ import jakarta.persistence.*;
public class Channel {
@Id
@Column(name = "uploader_id", length = 30)
@Column(name = "uploader_id", unique = true, nullable = false, length = 30)
private String uploader_id;
@Column(name = "uploader", length = 80)

View File

@ -40,7 +40,7 @@ public class Playlist {
private String thumbnail;
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "owner")
@JoinColumn(name = "owner", nullable = false)
private User owner;
@ManyToMany

View File

@ -19,7 +19,7 @@ public class PlaylistVideo {
}
@Id
@Column(name = "id", unique = true, length = 16)
@Column(name = "id", unique = true, length = 16, nullable = false)
private String id;
@Column(name = "title", length = 120)
@ -32,7 +32,7 @@ public class PlaylistVideo {
private String thumbnail;
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "uploader_id")
@JoinColumn(name = "uploader_id", nullable = false)
private Channel channel;
public String getId() {

View File

@ -1,6 +1,7 @@
package me.kavin.piped.utils.obj.db;
import jakarta.persistence.*;
import org.hibernate.annotations.Cascade;
import java.io.Serializable;
import java.util.Set;
@ -29,10 +30,11 @@ public class User implements Serializable {
private String sessionId;
@ElementCollection
@CollectionTable(name = "users_subscribed", joinColumns = @JoinColumn(name = "subscriber"), indexes = {
@Index(columnList = "subscriber", name = "users_subscribed_subscriber_idx"),
@Index(columnList = "channel", name = "users_subscribed_channel_idx")})
@Column(name = "channel", length = 30)
@CollectionTable(name = "users_subscribed", joinColumns = @JoinColumn(name = "subscriber", nullable = false),
indexes = {@Index(columnList = "subscriber", name = "users_subscribed_subscriber_idx"),
@Index(columnList = "channel", name = "users_subscribed_channel_idx")})
@Column(name = "channel", length = 30, nullable = false)
@Cascade(org.hibernate.annotations.CascadeType.ALL)
private Set<String> subscribed_ids;
@OneToMany(mappedBy = "owner", cascade = CascadeType.ALL)

View File

@ -9,7 +9,7 @@ import jakarta.persistence.*;
public class Video {
@Id
@Column(name = "id", unique = true, length = 16)
@Column(name = "id", unique = true, length = 16, nullable = false)
private String id;
@Column(name = "title", length = 120)
@ -28,7 +28,7 @@ public class Video {
private String thumbnail;
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "uploader_id")
@JoinColumn(name = "uploader_id", nullable = false)
private Channel channel;
public Video() {