rename admin schema to xssbook

This commit is contained in:
Murphy 2024-12-20 00:30:08 -05:00
parent 66281a4db6
commit 757ccac010
Signed by: freya
GPG key ID: 9FBC6FFD6D2DBF17
38 changed files with 126 additions and 96 deletions

View file

@ -0,0 +1,11 @@
BEGIN TRANSACTION;
SET search_path = public;
-- Migration Start
ALTER SCHEMA admin RENAME TO xssbook;
-- Migration End;
-- Set Current Revision
UPDATE sys.database_info SET curr_revision = 3 WHERE name = current_database();
COMMIT TRANSACTION;

View file

@ -7,13 +7,13 @@ CREATE VIEW api.comment AS
c.created, c.created,
c.modified c.modified
FROM FROM
admin.comment c xssbook.comment c
LEFT JOIN LEFT JOIN
admin.post p xssbook.post p
ON ON
p.id = c.post_id p.id = c.post_id
LEFT JOIN LEFT JOIN
admin.user u xssbook.user u
ON ON
u.id = c.user_id u.id = c.user_id
WHERE WHERE
@ -25,5 +25,5 @@ CREATE VIEW api.comment AS
GRANT SELECT ON TABLE api.comment GRANT SELECT ON TABLE api.comment
TO rest_anon, rest_user; TO rest_anon, rest_user;
GRANT SELECT ON TABLE admin.comment GRANT SELECT ON TABLE xssbook.comment
TO rest_anon, rest_user; TO rest_anon, rest_user;

View file

@ -11,7 +11,7 @@ BEGIN
PERFORM _api.raise_deny(); PERFORM _api.raise_deny();
END IF; END IF;
UPDATE admin.comment SET UPDATE xssbook.comment SET
deleted = TRUE, deleted = TRUE,
modified = clock_timestamp() modified = clock_timestamp()
WHERE id = OLD.id; WHERE id = OLD.id;
@ -22,7 +22,7 @@ GRANT EXECUTE ON FUNCTION _api.comment_delete()
TO rest_user; TO rest_user;
GRANT DELETE ON TABLE api.comment GRANT DELETE ON TABLE api.comment
TO rest_user; TO rest_user;
GRANT UPDATE ON TABLE admin.comment GRANT UPDATE ON TABLE xssbook.comment
TO rest_user; TO rest_user;
CREATE TRIGGER api_comment_delete_trgr CREATE TRIGGER api_comment_delete_trgr

View file

@ -16,7 +16,7 @@ BEGIN
); );
PERFORM TRUE PERFORM TRUE
FROM admin.post FROM xssbook.post
WHERE id = NEW.post_id; WHERE id = NEW.post_id;
IF NOT FOUND THEN IF NOT FOUND THEN
@ -26,7 +26,7 @@ BEGIN
); );
END IF; END IF;
INSERT INTO admin.comment ( INSERT INTO xssbook.comment (
user_id, user_id,
post_id, post_id,
content content
@ -46,7 +46,7 @@ GRANT EXECUTE ON FUNCTION _api.comment_insert()
TO rest_user; TO rest_user;
GRANT INSERT ON TABLE api.comment GRANT INSERT ON TABLE api.comment
TO rest_user; TO rest_user;
GRANT INSERT ON TABLE admin.comment GRANT INSERT ON TABLE xssbook.comment
TO rest_user; TO rest_user;
GRANT UPDATE ON TABLE sys.comment_id_seq GRANT UPDATE ON TABLE sys.comment_id_seq
TO rest_user; TO rest_user;

View file

@ -27,7 +27,7 @@ BEGIN
END IF; END IF;
IF _changed THEN IF _changed THEN
UPDATE admin.comment SET UPDATE xssbook.comment SET
content = NEW.content, content = NEW.content,
modified = clock_timestamp() modified = clock_timestamp()
WHERE id = OLD.id; WHERE id = OLD.id;
@ -41,7 +41,7 @@ GRANT EXECUTE ON FUNCTION _api.comment_update()
TO rest_user; TO rest_user;
GRANT UPDATE ON TABLE api.comment GRANT UPDATE ON TABLE api.comment
TO rest_user; TO rest_user;
GRANT UPDATE ON TABLE admin.comment GRANT UPDATE ON TABLE xssbook.comment
TO rest_user; TO rest_user;
CREATE TRIGGER api_comment_update_trgr CREATE TRIGGER api_comment_update_trgr

View file

@ -7,9 +7,9 @@ CREATE VIEW api.follow AS
f.created, f.created,
f.modified f.modified
FROM FROM
admin.follow f; xssbook.follow f;
GRANT SELECT ON TABLE api.follow GRANT SELECT ON TABLE api.follow
TO rest_anon, rest_user; TO rest_anon, rest_user;
GRANT SELECT ON TABLE admin.follow GRANT SELECT ON TABLE xssbook.follow
TO rest_anon, rest_user; TO rest_anon, rest_user;

View file

@ -11,7 +11,7 @@ BEGIN
PERFORM _api.raise_deny(); PERFORM _api.raise_deny();
END IF; END IF;
UPDATE admin.follow SET UPDATE xssbook.follow SET
value = FALSE, value = FALSE,
modified = clock_timestamp() modified = clock_timestamp()
WHERE id = OLD.id; WHERE id = OLD.id;
@ -22,7 +22,7 @@ GRANT EXECUTE ON FUNCTION _api.follow_delete()
TO rest_user; TO rest_user;
GRANT DELETE ON TABLE api.follow GRANT DELETE ON TABLE api.follow
TO rest_user; TO rest_user;
GRANT UPDATE ON TABLE admin.follow GRANT UPDATE ON TABLE xssbook.follow
TO rest_user; TO rest_user;
CREATE TRIGGER api_follow_delete_trgr CREATE TRIGGER api_follow_delete_trgr

View file

@ -14,7 +14,7 @@ BEGIN
NEW.value := COALESCE(NEW.value, TRUE); NEW.value := COALESCE(NEW.value, TRUE);
INSERT INTO admin.follow ( INSERT INTO xssbook.follow (
follower_id, follower_id,
followee_id, followee_id,
value value
@ -34,7 +34,7 @@ GRANT EXECUTE ON FUNCTION _api.follow_insert()
TO rest_user; TO rest_user;
GRANT INSERT ON TABLE api.follow GRANT INSERT ON TABLE api.follow
TO rest_user; TO rest_user;
GRANT INSERT ON TABLE admin.follow GRANT INSERT ON TABLE xssbook.follow
TO rest_user; TO rest_user;
GRANT UPDATE ON TABLE sys.follow_id_seq GRANT UPDATE ON TABLE sys.follow_id_seq
TO rest_user; TO rest_user;

View file

@ -20,7 +20,7 @@ BEGIN
END IF; END IF;
IF _changed THEN IF _changed THEN
UPDATE admin.follow SET UPDATE xssbook.follow SET
value = NEW.value, value = NEW.value,
modified = clock_timestamp() modified = clock_timestamp()
WHERE id = OLD.id; WHERE id = OLD.id;
@ -34,7 +34,7 @@ GRANT EXECUTE ON FUNCTION _api.follow_update()
TO rest_user; TO rest_user;
GRANT UPDATE ON TABLE api.follow GRANT UPDATE ON TABLE api.follow
TO rest_user; TO rest_user;
GRANT UPDATE ON TABLE admin.follow GRANT UPDATE ON TABLE xssbook.follow
TO rest_user; TO rest_user;
CREATE TRIGGER api_follow_update_trgr CREATE TRIGGER api_follow_update_trgr

View file

@ -8,9 +8,9 @@ CREATE VIEW api.like AS
l.created, l.created,
l.modified l.modified
FROM FROM
admin.like l; xssbook.like l;
GRANT SELECT ON TABLE api.like GRANT SELECT ON TABLE api.like
TO rest_anon, rest_user; TO rest_anon, rest_user;
GRANT SELECT ON TABLE admin.like GRANT SELECT ON TABLE xssbook.like
TO rest_anon, rest_user; TO rest_anon, rest_user;

View file

@ -11,7 +11,7 @@ BEGIN
PERFORM _api.raise_deny(); PERFORM _api.raise_deny();
END IF; END IF;
UPDATE admin.like SET UPDATE xssbook.like SET
value = FALSE, value = FALSE,
modified = clock_timestamp() modified = clock_timestamp()
WHERE id = OLD.id; WHERE id = OLD.id;
@ -22,7 +22,7 @@ GRANT EXECUTE ON FUNCTION _api.like_delete()
TO rest_user; TO rest_user;
GRANT DELETE ON TABLE api.like GRANT DELETE ON TABLE api.like
TO rest_user; TO rest_user;
GRANT UPDATE ON TABLE admin.like GRANT UPDATE ON TABLE xssbook.like
TO rest_user; TO rest_user;
CREATE TRIGGER api_like_delete_trgr CREATE TRIGGER api_like_delete_trgr

View file

@ -17,7 +17,7 @@ BEGIN
NEW.value := COALESCE(NEW.value, TRUE); NEW.value := COALESCE(NEW.value, TRUE);
INSERT INTO admin.like ( INSERT INTO xssbook.like (
user_id, user_id,
post_id, post_id,
comment_id, comment_id,
@ -39,7 +39,7 @@ GRANT EXECUTE ON FUNCTION _api.like_insert()
TO rest_user; TO rest_user;
GRANT INSERT ON TABLE api.like GRANT INSERT ON TABLE api.like
TO rest_user; TO rest_user;
GRANT INSERT ON TABLE admin.like GRANT INSERT ON TABLE xssbook.like
TO rest_user; TO rest_user;
GRANT UPDATE ON TABLE sys.like_id_seq GRANT UPDATE ON TABLE sys.like_id_seq
TO rest_user; TO rest_user;

View file

@ -20,7 +20,7 @@ BEGIN
END IF; END IF;
IF _changed THEN IF _changed THEN
UPDATE admin.like SET UPDATE xssbook.like SET
value = NEW.value, value = NEW.value,
modified = clock_timestamp() modified = clock_timestamp()
WHERE id = OLD.id; WHERE id = OLD.id;
@ -34,7 +34,7 @@ GRANT EXECUTE ON FUNCTION _api.like_update()
TO rest_user; TO rest_user;
GRANT UPDATE ON TABLE api.like GRANT UPDATE ON TABLE api.like
TO rest_user; TO rest_user;
GRANT UPDATE ON TABLE admin.like GRANT UPDATE ON TABLE xssbook.like
TO rest_user; TO rest_user;
CREATE TRIGGER api_like_update_trgr CREATE TRIGGER api_like_update_trgr

View file

@ -20,7 +20,7 @@ $BODY$;
CREATE CONSTRAINT TRIGGER api_validate_role_trgr CREATE CONSTRAINT TRIGGER api_validate_role_trgr
AFTER INSERT OR UPDATE AFTER INSERT OR UPDATE
ON admin.user ON xssbook.user
FOR EACH ROW FOR EACH ROW
EXECUTE PROCEDURE _api.validate_role(); EXECUTE PROCEDURE _api.validate_role();

View file

@ -31,7 +31,7 @@ BEGIN
_user_id = _payload->>'user_id'; _user_id = _payload->>'user_id';
UPDATE admin.user UPDATE xssbook.user
SET seen = clock_timestamp() SET seen = clock_timestamp()
WHERE id = _user_id; WHERE id = _user_id;
@ -43,5 +43,5 @@ GRANT EXECUTE ON FUNCTION _api.verify_jwt(TEXT)
TO rest_anon, rest_user; TO rest_anon, rest_user;
GRANT SELECT ON TABLE sys.database_info GRANT SELECT ON TABLE sys.database_info
TO rest_anon, rest_user; TO rest_anon, rest_user;
GRANT UPDATE ON TABLE admin.user GRANT UPDATE ON TABLE xssbook.user
TO rest_anon, rest_user; TO rest_anon, rest_user;

View file

@ -11,7 +11,7 @@ DECLARE
_token sys.JWT; _token sys.JWT;
BEGIN BEGIN
SELECT role INTO _role SELECT role INTO _role
FROM admin.user u FROM xssbook.user u
WHERE u.username = login.username WHERE u.username = login.username
AND u.password = login.password; AND u.password = login.password;
@ -23,7 +23,7 @@ BEGIN
END IF; END IF;
SELECT id INTO _user_id SELECT id INTO _user_id
FROM admin.user u FROM xssbook.user u
WHERE u.username = login.username; WHERE u.username = login.username;
_token = _api.sign_jwt( _token = _api.sign_jwt(
@ -37,5 +37,5 @@ $BODY$;
GRANT EXECUTE ON FUNCTION api.login(TEXT, TEXT) GRANT EXECUTE ON FUNCTION api.login(TEXT, TEXT)
TO rest_anon, rest_user; TO rest_anon, rest_user;
GRANT SELECT ON TABLE admin.user GRANT SELECT ON TABLE xssbook.user
TO rest_anon, rest_user; TO rest_anon, rest_user;

View file

@ -13,12 +13,12 @@ BEGIN
'{"Content-Disposition": "inline; filename=\"%s\""},' '{"Content-Disposition": "inline; filename=\"%s\""},'
'{"Cache-Control": "max-age=259200"}]' '{"Cache-Control": "max-age=259200"}]'
, m.mime, m.name) , m.mime, m.name)
FROM admin.media m FROM xssbook.media m
WHERE m.id = _media_id WHERE m.id = _media_id
INTO _headers; INTO _headers;
SELECT m.content SELECT m.content
FROM admin.media m FROM xssbook.media m
WHERE m.id = _media_id WHERE m.id = _media_id
INTO _data; INTO _data;
@ -33,5 +33,5 @@ $BODY$;
GRANT EXECUTE ON FUNCTION _api.serve_system_media(INTEGER) GRANT EXECUTE ON FUNCTION _api.serve_system_media(INTEGER)
TO rest_anon, rest_user; TO rest_anon, rest_user;
GRANT SELECT ON TABLE admin.media GRANT SELECT ON TABLE xssbook.media
TO rest_anon, rest_user; TO rest_anon, rest_user;

View file

@ -13,12 +13,12 @@ BEGIN
'{"Content-Disposition": "inline"},' '{"Content-Disposition": "inline"},'
'{"Cache-Control": "max-age=259200"}]' '{"Cache-Control": "max-age=259200"}]'
, m.mime) , m.mime)
FROM admin.user_media m FROM xssbook.user_media m
WHERE m.id = _media_id WHERE m.id = _media_id
INTO _headers; INTO _headers;
SELECT m.content SELECT m.content
FROM admin.user_media m FROM xssbook.user_media m
WHERE m.id = _media_id WHERE m.id = _media_id
INTO _data; INTO _data;
@ -33,5 +33,5 @@ $BODY$;
GRANT EXECUTE ON FUNCTION _api.serve_user_media(INTEGER) GRANT EXECUTE ON FUNCTION _api.serve_user_media(INTEGER)
TO rest_anon, rest_user; TO rest_anon, rest_user;
GRANT SELECT ON TABLE admin.user_media GRANT SELECT ON TABLE xssbook.user_media
TO rest_anon, rest_user; TO rest_anon, rest_user;

View file

@ -1,6 +1,6 @@
CREATE FUNCTION _api.serve_user_or_default_media( CREATE FUNCTION _api.serve_user_or_default_media(
_user_id INTEGER, _user_id INTEGER,
_type admin.user_media_type, _type xssbook.user_media_type,
_default TEXT _default TEXT
) )
RETURNS sys."*/*" RETURNS sys."*/*"
@ -11,7 +11,7 @@ DECLARE
BEGIN BEGIN
SELECT id SELECT id
FROM admin.user_media m FROM xssbook.user_media m
WHERE m.type = _type WHERE m.type = _type
AND m.user_id = _user_id AND m.user_id = _user_id
INTO _media_id; INTO _media_id;
@ -21,7 +21,7 @@ BEGIN
END IF; END IF;
SELECT id SELECT id
FROM admin.media m FROM xssbook.media m
WHERE m.name = _default WHERE m.name = _default
INTO _media_id; INTO _media_id;
@ -33,9 +33,9 @@ BEGIN
END END
$BODY$; $BODY$;
GRANT EXECUTE ON FUNCTION _api.serve_user_or_default_media(INTEGER, admin.user_media_type, TEXT) GRANT EXECUTE ON FUNCTION _api.serve_user_or_default_media(INTEGER, xssbook.user_media_type, TEXT)
TO rest_anon, rest_user; TO rest_anon, rest_user;
GRANT SELECT ON TABLE admin.user_media GRANT SELECT ON TABLE xssbook.user_media
TO rest_anon, rest_user; TO rest_anon, rest_user;
GRANT SELECT ON TABLE admin.media GRANT SELECT ON TABLE xssbook.media
TO rest_anon, rest_user; TO rest_anon, rest_user;

View file

@ -1,5 +1,5 @@
CREATE FUNCTION api.delete_user_media( CREATE FUNCTION api.delete_user_media(
media_type admin.user_media_type media_type xssbook.user_media_type
) )
RETURNS void RETURNS void
LANGUAGE plpgsql VOLATILE LANGUAGE plpgsql VOLATILE
@ -11,16 +11,16 @@ BEGIN
_user_id = _api.get_user_id(); _user_id = _api.get_user_id();
DELETE FROM DELETE FROM
admin.user_media xssbook.user_media
WHERE WHERE
"type" = media_type AND "type" = media_type AND
"user_id" = _user_id; "user_id" = _user_id;
END END
$BODY$; $BODY$;
GRANT EXECUTE ON FUNCTION api.delete_user_media(admin.user_media_type) GRANT EXECUTE ON FUNCTION api.delete_user_media(xssbook.user_media_type)
TO rest_user; TO rest_user;
GRANT DELETE ON TABLE admin.user_media GRANT DELETE ON TABLE xssbook.user_media
TO rest_user; TO rest_user;
GRANT UPDATE ON TABLE sys.user_media_id_seq GRANT UPDATE ON TABLE sys.user_media_id_seq
TO rest_user; TO rest_user;

View file

@ -10,7 +10,7 @@ BEGIN
_default := 'default_avatar_' || MOD(user_id, 25) || '.png'; _default := 'default_avatar_' || MOD(user_id, 25) || '.png';
RETURN _api.serve_user_or_default_media( RETURN _api.serve_user_or_default_media(
user_id, user_id,
'avatar'::admin.user_media_type, 'avatar'::xssbook.user_media_type,
_default _default
); );
END END

View file

@ -10,7 +10,7 @@ BEGIN
_default := 'default_banner_' || MOD(user_id, 25) || '.png'; _default := 'default_banner_' || MOD(user_id, 25) || '.png';
RETURN _api.serve_user_or_default_media( RETURN _api.serve_user_or_default_media(
user_id, user_id,
'banner'::admin.user_media_type, 'banner'::xssbook.user_media_type,
_default _default
); );
END END
@ -18,7 +18,7 @@ $BODY$;
GRANT EXECUTE ON FUNCTION api.profile_banner(INTEGER) GRANT EXECUTE ON FUNCTION api.profile_banner(INTEGER)
TO rest_anon, rest_user; TO rest_anon, rest_user;
GRANT SELECT ON TABLE admin.user_media GRANT SELECT ON TABLE xssbook.user_media
TO rest_anon, rest_user; TO rest_anon, rest_user;
GRANT SELECT ON TABLE admin.media GRANT SELECT ON TABLE xssbook.media
TO rest_anon, rest_user; TO rest_anon, rest_user;

View file

@ -1,5 +1,5 @@
CREATE FUNCTION api.update_user_media( CREATE FUNCTION api.update_user_media(
media_type admin.user_media_type, media_type xssbook.user_media_type,
mime TEXT, mime TEXT,
content TEXT content TEXT
) )
@ -13,7 +13,7 @@ BEGIN
_user_id = _api.get_user_id(); _user_id = _api.get_user_id();
_data = decode(content, 'base64'); _data = decode(content, 'base64');
INSERT INTO admin.user_media ( INSERT INTO xssbook.user_media (
user_id, user_id,
content, content,
mime, mime,
@ -33,9 +33,9 @@ BEGIN
END END
$BODY$; $BODY$;
GRANT EXECUTE ON FUNCTION api.update_user_media(admin.user_media_type, TEXT, TEXT) GRANT EXECUTE ON FUNCTION api.update_user_media(xssbook.user_media_type, TEXT, TEXT)
TO rest_user; TO rest_user;
GRANT INSERT, UPDATE ON TABLE admin.user_media GRANT INSERT, UPDATE ON TABLE xssbook.user_media
TO rest_user; TO rest_user;
GRANT UPDATE ON TABLE sys.user_media_id_seq GRANT UPDATE ON TABLE sys.user_media_id_seq
TO rest_user; TO rest_user;

View file

@ -10,13 +10,13 @@ CREATE VIEW api.post AS
COALESCE(l.lc, 0) COALESCE(l.lc, 0)
AS like_count AS like_count
FROM FROM
admin.post p xssbook.post p
LEFT JOIN ( LEFT JOIN (
SELECT SELECT
COUNT(c.id) as cc, COUNT(c.id) as cc,
c.post_id c.post_id
FROM FROM
admin.comment c xssbook.comment c
GROUP BY GROUP BY
c.post_id c.post_id
) c ) c
@ -27,14 +27,14 @@ CREATE VIEW api.post AS
COUNT(l.id) as lc, COUNT(l.id) as lc,
l.post_id l.post_id
FROM FROM
admin.like l xssbook.like l
GROUP BY GROUP BY
l.post_id l.post_id
) l ) l
ON ON
p.id = l.post_id p.id = l.post_id
LEFT JOIN LEFT JOIN
admin.user u xssbook.user u
ON ON
u.id = p.user_id u.id = p.user_id
WHERE WHERE
@ -46,5 +46,5 @@ CREATE VIEW api.post AS
GRANT SELECT ON TABLE api.post GRANT SELECT ON TABLE api.post
TO rest_anon, rest_user; TO rest_anon, rest_user;
GRANT SELECT ON TABLE admin.post GRANT SELECT ON TABLE xssbook.post
TO rest_anon, rest_user; TO rest_anon, rest_user;

View file

@ -11,7 +11,7 @@ BEGIN
PERFORM _api.raise_deny(); PERFORM _api.raise_deny();
END IF; END IF;
UPDATE admin.post SET UPDATE xssbook.post SET
deleted = TRUE, deleted = TRUE,
modified = clock_timestamp() modified = clock_timestamp()
WHERE id = OLD.id; WHERE id = OLD.id;
@ -22,7 +22,7 @@ GRANT EXECUTE ON FUNCTION _api.post_delete()
TO rest_user; TO rest_user;
GRANT DELETE ON TABLE api.post GRANT DELETE ON TABLE api.post
TO rest_user; TO rest_user;
GRANT UPDATE ON TABLE admin.post GRANT UPDATE ON TABLE xssbook.post
TO rest_user; TO rest_user;
CREATE TRIGGER api_post_delete_trgr CREATE TRIGGER api_post_delete_trgr

View file

@ -16,7 +16,7 @@ BEGIN
_max => 4096 _max => 4096
); );
INSERT INTO admin.post ( INSERT INTO xssbook.post (
user_id, user_id,
content content
) VALUES ( ) VALUES (
@ -34,7 +34,7 @@ GRANT EXECUTE ON FUNCTION _api.post_insert()
TO rest_user; TO rest_user;
GRANT INSERT ON TABLE api.post GRANT INSERT ON TABLE api.post
TO rest_user; TO rest_user;
GRANT INSERT ON TABLE admin.post GRANT INSERT ON TABLE xssbook.post
TO rest_user; TO rest_user;
GRANT UPDATE ON TABLE sys.post_id_seq GRANT UPDATE ON TABLE sys.post_id_seq
TO rest_user; TO rest_user;

View file

@ -27,7 +27,7 @@ BEGIN
END IF; END IF;
IF _changed THEN IF _changed THEN
UPDATE admin.post SET UPDATE xssbook.post SET
content = NEW.content, content = NEW.content,
modified = clock_timestamp() modified = clock_timestamp()
WHERE id = OLD.id; WHERE id = OLD.id;
@ -41,7 +41,7 @@ GRANT EXECUTE ON FUNCTION _api.post_update()
TO rest_user; TO rest_user;
GRANT UPDATE ON TABLE api.post GRANT UPDATE ON TABLE api.post
TO rest_user; TO rest_user;
GRANT UPDATE ON TABLE admin.post GRANT UPDATE ON TABLE xssbook.post
TO rest_user; TO rest_user;
CREATE TRIGGER api_post_update_trgr CREATE TRIGGER api_post_update_trgr

View file

@ -7,7 +7,7 @@ CREATE SCHEMA api;
DROP SCHEMA IF EXISTS _api CASCADE; DROP SCHEMA IF EXISTS _api CASCADE;
CREATE SCHEMA _api; CREATE SCHEMA _api;
GRANT USAGE ON SCHEMA admin TO rest_anon, rest_user; GRANT USAGE ON SCHEMA xssbook TO rest_anon, rest_user;
GRANT USAGE ON SCHEMA sys TO rest_anon, rest_user; GRANT USAGE ON SCHEMA sys TO rest_anon, rest_user;
GRANT USAGE ON SCHEMA api TO rest_anon, rest_user; GRANT USAGE ON SCHEMA api TO rest_anon, rest_user;

View file

@ -20,7 +20,7 @@ BEGIN
SELECT password SELECT password
INTO _real_password INTO _real_password
FROM admin.user FROM xssbook.user
WHERE id = _user_id; WHERE id = _user_id;
IF _real_password <> current_password THEN IF _real_password <> current_password THEN
@ -30,7 +30,7 @@ BEGIN
END IF; END IF;
UPDATE UPDATE
admin.user xssbook.user
SET SET
"password" = new_password "password" = new_password
WHERE WHERE
@ -40,5 +40,5 @@ $BODY$;
GRANT EXECUTE ON FUNCTION api.update_password(TEXT, TEXT) GRANT EXECUTE ON FUNCTION api.update_password(TEXT, TEXT)
TO rest_user; TO rest_user;
GRANT SELECT, UPDATE ON TABLE admin.user GRANT SELECT, UPDATE ON TABLE xssbook.user
TO rest_user; TO rest_user;

View file

@ -29,13 +29,13 @@ CREATE VIEW api.user AS
mb.mime mb.mime
AS banner_mime AS banner_mime
FROM FROM
admin.user u xssbook.user u
LEFT JOIN ( LEFT JOIN (
SELECT SELECT
COUNT(f.id) as fc, COUNT(f.id) as fc,
f.followee_id f.followee_id
FROM FROM
admin.follow f xssbook.follow f
GROUP BY GROUP BY
f.followee_id f.followee_id
) f ) f
@ -46,7 +46,7 @@ CREATE VIEW api.user AS
COUNT(fl.id) as fc, COUNT(fl.id) as fc,
fl.follower_id fl.follower_id
FROM FROM
admin.follow fl xssbook.follow fl
GROUP BY GROUP BY
fl.follower_id fl.follower_id
) fl ) fl
@ -57,7 +57,7 @@ CREATE VIEW api.user AS
COUNT(c.id) as cc, COUNT(c.id) as cc,
c.user_id c.user_id
FROM FROM
admin.comment c xssbook.comment c
GROUP BY GROUP BY
c.user_id c.user_id
) c ) c
@ -68,7 +68,7 @@ CREATE VIEW api.user AS
COUNT(p.id) as pc, COUNT(p.id) as pc,
p.user_id p.user_id
FROM FROM
admin.post p xssbook.post p
GROUP BY GROUP BY
p.user_id p.user_id
) p ) p
@ -79,7 +79,7 @@ CREATE VIEW api.user AS
COUNT(l.id) as lc, COUNT(l.id) as lc,
l.user_id l.user_id
FROM FROM
admin.like l xssbook.like l
GROUP BY GROUP BY
l.user_id l.user_id
) l ) l
@ -90,7 +90,7 @@ CREATE VIEW api.user AS
ma.mime, ma.mime,
ma.user_id ma.user_id
FROM FROM
admin.user_media ma xssbook.user_media ma
WHERE WHERE
ma.type = 'avatar' ma.type = 'avatar'
) ma ) ma
@ -101,7 +101,7 @@ CREATE VIEW api.user AS
mb.mime, mb.mime,
mb.user_id mb.user_id
FROM FROM
admin.user_media mb xssbook.user_media mb
WHERE WHERE
mb.type = 'banner' mb.type = 'banner'
) mb ) mb
@ -112,5 +112,5 @@ CREATE VIEW api.user AS
GRANT SELECT ON TABLE api.user GRANT SELECT ON TABLE api.user
TO rest_anon, rest_user; TO rest_anon, rest_user;
GRANT SELECT ON TABLE admin.user GRANT SELECT ON TABLE xssbook.user
TO rest_anon, rest_user; TO rest_anon, rest_user;

View file

@ -11,7 +11,7 @@ BEGIN
PERFORM _api.raise_deny(); PERFORM _api.raise_deny();
END IF; END IF;
UPDATE admin.user SET UPDATE xssbook.user SET
deleted = TRUE, deleted = TRUE,
modified = clock_timestamp() modified = clock_timestamp()
WHERE id = _user_id; WHERE id = _user_id;
@ -22,7 +22,7 @@ GRANT EXECUTE ON FUNCTION _api.user_delete()
TO rest_user; TO rest_user;
GRANT DELETE ON TABLE api.user GRANT DELETE ON TABLE api.user
TO rest_user; TO rest_user;
GRANT UPDATE ON TABLE admin.user GRANT UPDATE ON TABLE xssbook.user
TO rest_user; TO rest_user;
CREATE TRIGGER api_user_delete_trgr CREATE TRIGGER api_user_delete_trgr

View file

@ -22,7 +22,7 @@ BEGIN
_max => 24 _max => 24
); );
PERFORM TRUE FROM admin.user PERFORM TRUE FROM xssbook.user
WHERE username = NEW.username; WHERE username = NEW.username;
IF FOUND THEN IF FOUND THEN
@ -84,7 +84,7 @@ BEGIN
); );
NEW.profile_bio = COALESCE(NEW.profile_bio, ''::text); NEW.profile_bio = COALESCE(NEW.profile_bio, ''::text);
INSERT INTO admin.user ( INSERT INTO xssbook.user (
username, username,
password, password,
first_name, first_name,
@ -118,7 +118,7 @@ GRANT EXECUTE ON FUNCTION _api.user_insert()
TO rest_anon, rest_user; TO rest_anon, rest_user;
GRANT INSERT ON TABLE api.user GRANT INSERT ON TABLE api.user
TO rest_anon, rest_user; TO rest_anon, rest_user;
GRANT INSERT ON TABLE admin.user GRANT INSERT ON TABLE xssbook.user
TO rest_anon, rest_user; TO rest_anon, rest_user;
GRANT UPDATE ON TABLE sys.user_id_seq GRANT UPDATE ON TABLE sys.user_id_seq
TO rest_anon, rest_user; TO rest_anon, rest_user;

View file

@ -24,7 +24,7 @@ BEGIN
); );
IF NEW.username IS DISTINCT FROM OLD.username THEN IF NEW.username IS DISTINCT FROM OLD.username THEN
PERFORM TRUE FROM admin.user PERFORM TRUE FROM xssbook.user
WHERE username = NEW.username; WHERE username = NEW.username;
IF FOUND THEN IF FOUND THEN
PERFORM _api.raise_unique('username'); PERFORM _api.raise_unique('username');
@ -117,7 +117,7 @@ BEGIN
END IF; END IF;
IF _changed THEN IF _changed THEN
UPDATE admin.user SET UPDATE xssbook.user SET
username = NEW.username, username = NEW.username,
first_name = NEW.first_name, first_name = NEW.first_name,
last_name = NEW.last_name, last_name = NEW.last_name,
@ -138,7 +138,7 @@ GRANT EXECUTE ON FUNCTION _api.user_update()
TO rest_user; TO rest_user;
GRANT UPDATE ON TABLE api.user GRANT UPDATE ON TABLE api.user
TO rest_user; TO rest_user;
GRANT UPDATE ON TABLE admin.user GRANT UPDATE ON TABLE xssbook.user
TO rest_user; TO rest_user;
CREATE TRIGGER api_user_update_trgr CREATE TRIGGER api_user_update_trgr

View file

@ -10,7 +10,7 @@ BEGIN
TRUE TRUE
)::JSON->>'user_id'; )::JSON->>'user_id';
UPDATE admin.user UPDATE xssbook.user
SET seen = clock_timestamp() SET seen = clock_timestamp()
WHERE id = _user_id; WHERE id = _user_id;
@ -18,5 +18,5 @@ BEGIN
END END
$BODY$; $BODY$;
GRANT UPDATE ON TABLE admin.user GRANT UPDATE ON TABLE xssbook.user
TO rest_anon, rest_user; TO rest_anon, rest_user;

View file

@ -0,0 +1,19 @@
CREATE FUNCTION FUNCTION _api.root()
RETURNS JSON
LANGUAGE plpgsql;
AS $BODY$
DECLARE
openapi JSON = $$
{
"swagger": "2.0",
"info": {
"title": "XSSBook",
"description": "XSSBook Api Documentation"
}
}
$$;
BEGIN
RETURN openapi;
END
$BODY$;

View file

@ -8,7 +8,7 @@ class Home_model extends Model {
private function get_posts(): array { private function get_posts(): array {
return $this->db return $this->db
->select('*') ->select('*')
->from('admin.post') ->from('xssbook.post')
->limit(20) ->limit(20)
->rows(); ->rows();
} }

View file

@ -23,14 +23,14 @@ class People_model extends Model {
switch ($filter_type) { switch ($filter_type) {
case 'follower': { case 'follower': {
$query = $query $query = $query
->join('admin.follow f', 'f.follower_id = u.id AND f.followee_id', 'INNER') ->join('xssbook.follow f', 'f.follower_id = u.id AND f.followee_id', 'INNER')
->eq($filter_uid) ->eq($filter_uid)
->where('f.value = TRUE'); ->where('f.value = TRUE');
} break; } break;
case 'followee': { case 'followee': {
$query = $query $query = $query
->join('admin.follow f', 'f.followee_id = u.id AND f.follower_id', 'INNER') ->join('xssbook.follow f', 'f.followee_id = u.id AND f.follower_id', 'INNER')
->eq($filter_uid) ->eq($filter_uid)
->where('f.value = TRUE'); ->where('f.value = TRUE');
} break; } break;

View file

@ -36,7 +36,7 @@ class Profile_model extends Model {
if ($this->main->session) { if ($this->main->session) {
$sid = $this->main->user()['id']; $sid = $this->main->user()['id'];
$res = $this->db->select('f.value, f.id') $res = $this->db->select('f.value, f.id')
->from('admin.follow f') ->from('xssbook.follow f')
->where('f.follower_id') ->where('f.follower_id')
->eq($sid) ->eq($sid)
->where('f.followee_id') ->where('f.followee_id')
@ -45,7 +45,7 @@ class Profile_model extends Model {
$following = $res ? $res['value'] : FALSE; $following = $res ? $res['value'] : FALSE;
$follow_id = $res ? $res['id'] : NULL; $follow_id = $res ? $res['id'] : NULL;
$res = $this->db->select('f.value') $res = $this->db->select('f.value')
->from('admin.follow f') ->from('xssbook.follow f')
->where('f.follower_id') ->where('f.follower_id')
->eq($uid) ->eq($uid)
->where('f.followee_id') ->where('f.followee_id')