mirror of https://github.com/LemmyNet/lemmy
Add support for Featured Posts (#2585)
* Add support for Featured Posts * Fix rebase * More fixesupdate_missing_form_fields
parent
0ecf256ce3
commit
9dfd819691
@ -0,0 +1,47 @@
|
||||
|
||||
DROP TRIGGER IF EXISTS post_aggregates_featured_local ON post;
|
||||
DROP TRIGGER IF EXISTS post_aggregates_featured_community ON post;
|
||||
drop function post_aggregates_featured_community;
|
||||
drop function post_aggregates_featured_local;
|
||||
|
||||
|
||||
alter table post ADD stickied boolean NOT NULL DEFAULT false;
|
||||
Update post
|
||||
set stickied = featured_community;
|
||||
alter table post DROP COLUMN featured_community;
|
||||
alter table post DROP COLUMN featured_local;
|
||||
|
||||
alter table post_aggregates ADD stickied boolean NOT NULL DEFAULT false;
|
||||
Update post_aggregates
|
||||
set stickied = featured_community;
|
||||
alter table post_aggregates DROP COLUMN featured_community;
|
||||
alter table post_aggregates DROP COLUMN featured_local;
|
||||
|
||||
alter table mod_feature_post
|
||||
rename column featured TO stickied;
|
||||
|
||||
alter table mod_feature_post
|
||||
DROP COLUMN is_featured_community;
|
||||
|
||||
alter table mod_feature_post
|
||||
alter column stickied DROP NOT NULL;
|
||||
|
||||
alter table mod_feature_post
|
||||
Rename To mod_sticky_post;
|
||||
|
||||
create function post_aggregates_stickied()
|
||||
returns trigger language plpgsql
|
||||
as $$
|
||||
begin
|
||||
update post_aggregates pa
|
||||
set stickied = NEW.stickied
|
||||
where pa.post_id = NEW.id;
|
||||
|
||||
return null;
|
||||
end $$;
|
||||
|
||||
create trigger post_aggregates_stickied
|
||||
after update on post
|
||||
for each row
|
||||
when (OLD.stickied is distinct from NEW.stickied)
|
||||
execute procedure post_aggregates_stickied();
|
@ -0,0 +1,63 @@
|
||||
|
||||
DROP TRIGGER IF EXISTS post_aggregates_stickied ON post;
|
||||
drop function
|
||||
post_aggregates_stickied;
|
||||
|
||||
|
||||
alter table post ADD featured_community boolean NOT NULL DEFAULT false;
|
||||
alter table post ADD featured_local boolean NOT NULL DEFAULT false;
|
||||
update post
|
||||
set featured_community = stickied;
|
||||
alter table post DROP COLUMN stickied;
|
||||
|
||||
alter table post_aggregates ADD featured_community boolean NOT NULL DEFAULT false;
|
||||
alter table post_aggregates ADD featured_local boolean NOT NULL DEFAULT false;
|
||||
update post_aggregates
|
||||
set featured_community = stickied;
|
||||
alter table post_aggregates DROP COLUMN stickied;
|
||||
|
||||
alter table mod_sticky_post
|
||||
rename column stickied TO featured;
|
||||
|
||||
alter table mod_sticky_post
|
||||
alter column featured SET NOT NULL;
|
||||
|
||||
alter table mod_sticky_post
|
||||
ADD is_featured_community boolean NOT NULL DEFAULT true;
|
||||
|
||||
alter table mod_sticky_post
|
||||
Rename To mod_feature_post;
|
||||
|
||||
create function post_aggregates_featured_community()
|
||||
returns trigger language plpgsql
|
||||
as $$
|
||||
begin
|
||||
update post_aggregates pa
|
||||
set featured_community = NEW.featured_community
|
||||
where pa.post_id = NEW.id;
|
||||
return null;
|
||||
end $$;
|
||||
|
||||
create function post_aggregates_featured_local()
|
||||
returns trigger language plpgsql
|
||||
as $$
|
||||
begin
|
||||
update post_aggregates pa
|
||||
set featured_local = NEW.featured_local
|
||||
where pa.post_id = NEW.id;
|
||||
return null;
|
||||
end $$;
|
||||
|
||||
CREATE TRIGGER post_aggregates_featured_community
|
||||
AFTER UPDATE
|
||||
ON public.post
|
||||
FOR EACH ROW
|
||||
WHEN (old.featured_community IS DISTINCT FROM new.featured_community)
|
||||
EXECUTE FUNCTION public.post_aggregates_featured_community();
|
||||
|
||||
CREATE TRIGGER post_aggregates_featured_local
|
||||
AFTER UPDATE
|
||||
ON public.post
|
||||
FOR EACH ROW
|
||||
WHEN (old.featured_local IS DISTINCT FROM new.featured_local)
|
||||
EXECUTE FUNCTION public.post_aggregates_featured_local();
|
Loading…
Reference in New Issue