Merge pull request #314 from TeamPiped/db-schema

Fix imports and make database schema more strict
This commit is contained in:
Kavin 2022-07-18 21:25:44 +05:30 committed by GitHub
commit 4b96f46025
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
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() {