dedup table rows

master
Aevann 2024-10-23 22:49:00 +03:00
parent b8938f6c13
commit 906d51cfb9
2 changed files with 6 additions and 4 deletions

View File

@ -27,10 +27,9 @@ class Media(Base):
class MediaUsage(Base):
__tablename__ = "media_usages"
id = Column(Integer, primary_key=True)
filename = Column(String, ForeignKey("media.filename"))
post_id = Column(Integer, ForeignKey("posts.id"))
comment_id = Column(Integer, ForeignKey("comments.id"))
filename = Column(String, ForeignKey("media.filename"), primary_key=True)
post_id = Column(Integer, ForeignKey("posts.id"), primary_key=True)
comment_id = Column(Integer, ForeignKey("comments.id"), primary_key=True)
created_utc = Column(Integer)
deleted_utc = Column(Integer)
removed_utc = Column(Integer)

View File

@ -16,6 +16,9 @@ CREATE SEQUENCE public.media_usages_id_seq
NO MAXVALUE
CACHE 1;
ALTER TABLE ONLY public.media_usages
ADD CONSTRAINT group_media_usages_pkey PRIMARY KEY (filename, post_id, comment_id);
ALTER SEQUENCE public.media_usages_id_seq OWNED BY public.media_usages.id;
ALTER TABLE ONLY public.media_usages ALTER COLUMN id SET DEFAULT nextval('public.media_usages_id_seq'::regclass);