mirror of
https://github.com/TeamPiped/Piped-Backend.git
synced 2024-12-14 06:10:29 +05:30
Fix imports and make database schema more strict.
This commit is contained in:
parent
14f8c55782
commit
0e8b17698d
@ -967,7 +967,7 @@ public class ResponseHelper {
|
|||||||
if (user != null) {
|
if (user != null) {
|
||||||
|
|
||||||
Multithreading.runAsync(() -> {
|
Multithreading.runAsync(() -> {
|
||||||
try (StatelessSession s = DatabaseSessionFactory.createStatelessSession()) {
|
try (Session s = DatabaseSessionFactory.createSession()) {
|
||||||
if (override) {
|
if (override) {
|
||||||
user.setSubscribed(Set.of(channelIds));
|
user.setSubscribed(Set.of(channelIds));
|
||||||
} else {
|
} else {
|
||||||
@ -977,7 +977,7 @@ public class ResponseHelper {
|
|||||||
|
|
||||||
if (channelIds.length > 0) {
|
if (channelIds.length > 0) {
|
||||||
var tr = s.beginTransaction();
|
var tr = s.beginTransaction();
|
||||||
s.update(user);
|
s.merge(user);
|
||||||
tr.commit();
|
tr.commit();
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
@ -7,7 +7,7 @@ import jakarta.persistence.*;
|
|||||||
public class Channel {
|
public class Channel {
|
||||||
|
|
||||||
@Id
|
@Id
|
||||||
@Column(name = "uploader_id", length = 30)
|
@Column(name = "uploader_id", unique = true, nullable = false, length = 30)
|
||||||
private String uploader_id;
|
private String uploader_id;
|
||||||
|
|
||||||
@Column(name = "uploader", length = 80)
|
@Column(name = "uploader", length = 80)
|
||||||
|
@ -40,7 +40,7 @@ public class Playlist {
|
|||||||
private String thumbnail;
|
private String thumbnail;
|
||||||
|
|
||||||
@ManyToOne(fetch = FetchType.LAZY)
|
@ManyToOne(fetch = FetchType.LAZY)
|
||||||
@JoinColumn(name = "owner")
|
@JoinColumn(name = "owner", nullable = false)
|
||||||
private User owner;
|
private User owner;
|
||||||
|
|
||||||
@ManyToMany
|
@ManyToMany
|
||||||
|
@ -19,7 +19,7 @@ public class PlaylistVideo {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Id
|
@Id
|
||||||
@Column(name = "id", unique = true, length = 16)
|
@Column(name = "id", unique = true, length = 16, nullable = false)
|
||||||
private String id;
|
private String id;
|
||||||
|
|
||||||
@Column(name = "title", length = 120)
|
@Column(name = "title", length = 120)
|
||||||
@ -32,7 +32,7 @@ public class PlaylistVideo {
|
|||||||
private String thumbnail;
|
private String thumbnail;
|
||||||
|
|
||||||
@ManyToOne(fetch = FetchType.LAZY)
|
@ManyToOne(fetch = FetchType.LAZY)
|
||||||
@JoinColumn(name = "uploader_id")
|
@JoinColumn(name = "uploader_id", nullable = false)
|
||||||
private Channel channel;
|
private Channel channel;
|
||||||
|
|
||||||
public String getId() {
|
public String getId() {
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package me.kavin.piped.utils.obj.db;
|
package me.kavin.piped.utils.obj.db;
|
||||||
|
|
||||||
import jakarta.persistence.*;
|
import jakarta.persistence.*;
|
||||||
|
import org.hibernate.annotations.Cascade;
|
||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
@ -29,10 +30,11 @@ public class User implements Serializable {
|
|||||||
private String sessionId;
|
private String sessionId;
|
||||||
|
|
||||||
@ElementCollection
|
@ElementCollection
|
||||||
@CollectionTable(name = "users_subscribed", joinColumns = @JoinColumn(name = "subscriber"), indexes = {
|
@CollectionTable(name = "users_subscribed", joinColumns = @JoinColumn(name = "subscriber", nullable = false),
|
||||||
@Index(columnList = "subscriber", name = "users_subscribed_subscriber_idx"),
|
indexes = {@Index(columnList = "subscriber", name = "users_subscribed_subscriber_idx"),
|
||||||
@Index(columnList = "channel", name = "users_subscribed_channel_idx")})
|
@Index(columnList = "channel", name = "users_subscribed_channel_idx")})
|
||||||
@Column(name = "channel", length = 30)
|
@Column(name = "channel", length = 30, nullable = false)
|
||||||
|
@Cascade(org.hibernate.annotations.CascadeType.ALL)
|
||||||
private Set<String> subscribed_ids;
|
private Set<String> subscribed_ids;
|
||||||
|
|
||||||
@OneToMany(mappedBy = "owner", cascade = CascadeType.ALL)
|
@OneToMany(mappedBy = "owner", cascade = CascadeType.ALL)
|
||||||
|
@ -9,7 +9,7 @@ import jakarta.persistence.*;
|
|||||||
public class Video {
|
public class Video {
|
||||||
|
|
||||||
@Id
|
@Id
|
||||||
@Column(name = "id", unique = true, length = 16)
|
@Column(name = "id", unique = true, length = 16, nullable = false)
|
||||||
private String id;
|
private String id;
|
||||||
|
|
||||||
@Column(name = "title", length = 120)
|
@Column(name = "title", length = 120)
|
||||||
@ -28,7 +28,7 @@ public class Video {
|
|||||||
private String thumbnail;
|
private String thumbnail;
|
||||||
|
|
||||||
@ManyToOne(fetch = FetchType.LAZY)
|
@ManyToOne(fetch = FetchType.LAZY)
|
||||||
@JoinColumn(name = "uploader_id")
|
@JoinColumn(name = "uploader_id", nullable = false)
|
||||||
private Channel channel;
|
private Channel channel;
|
||||||
|
|
||||||
public Video() {
|
public Video() {
|
||||||
|
Loading…
Reference in New Issue
Block a user