mirror of
https://github.com/LemmyNet/lemmy
synced 2024-11-24 05:23:04 +00:00
be1389420b
* SQL format checking, 1. * SQL format checking, 2. * SQL format checking, 3. * SQL format checking, 4. * SQL format checking, 5. * Running pg_format * Getting rid of comment. * Upping pg_format version. * Using git ls-files for sql format check. * Fixing sql lints. * Addressing PR comments.
67 lines
1.4 KiB
PL/PgSQL
67 lines
1.4 KiB
PL/PgSQL
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 ();
|
|
|