Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
4 changes: 2 additions & 2 deletions src/deploy/enum_achievement_type.sql
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
BEGIN;

CREATE TYPE maevsi.achievement_type AS ENUM (
CREATE TYPE vibetype.achievement_type AS ENUM (
'early_bird',
'meet_the_team'
);

COMMENT ON TYPE maevsi.achievement_type IS 'Achievements that can be unlocked by users.';
COMMENT ON TYPE vibetype.achievement_type IS 'Achievements that can be unlocked by users.';

COMMIT;
4 changes: 2 additions & 2 deletions src/deploy/enum_event_size.sql
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
BEGIN;

CREATE TYPE maevsi.event_size AS ENUM (
CREATE TYPE vibetype.event_size AS ENUM (
'small',
'medium',
'large',
'huge'
);

COMMENT ON TYPE maevsi.event_size IS 'Possible event sizes: small, medium, large, huge.';
COMMENT ON TYPE vibetype.event_size IS 'Possible event sizes: small, medium, large, huge.';

COMMIT;
4 changes: 2 additions & 2 deletions src/deploy/enum_event_visibility.sql
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
BEGIN;

CREATE TYPE maevsi.event_visibility AS ENUM (
CREATE TYPE vibetype.event_visibility AS ENUM (
'public',
'private',
'unlisted'
);

COMMENT ON TYPE maevsi.event_visibility IS 'Possible visibilities of events and event groups: public, private and unlisted.';
COMMENT ON TYPE vibetype.event_visibility IS 'Possible visibilities of events and event groups: public, private and unlisted.';

COMMIT;
4 changes: 2 additions & 2 deletions src/deploy/enum_invitation_feedback.sql
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
BEGIN;

CREATE TYPE maevsi.invitation_feedback AS ENUM (
CREATE TYPE vibetype.invitation_feedback AS ENUM (
'accepted',
'canceled'
);

COMMENT ON TYPE maevsi.invitation_feedback IS 'Possible answers to an invitation: accepted, canceled.';
COMMENT ON TYPE vibetype.invitation_feedback IS 'Possible answers to an invitation: accepted, canceled.';

COMMIT;
4 changes: 2 additions & 2 deletions src/deploy/enum_invitation_feedback_paper.sql
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
BEGIN;

CREATE TYPE maevsi.invitation_feedback_paper AS ENUM (
CREATE TYPE vibetype.invitation_feedback_paper AS ENUM (
'none',
'paper',
'digital'
);

COMMENT ON TYPE maevsi.invitation_feedback_paper IS 'Possible choices on how to receive a paper invitation: none, paper, digital.';
COMMENT ON TYPE vibetype.invitation_feedback_paper IS 'Possible choices on how to receive a paper invitation: none, paper, digital.';

COMMIT;
4 changes: 2 additions & 2 deletions src/deploy/enum_language.sql
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
BEGIN;

CREATE TYPE maevsi.language AS ENUM (
CREATE TYPE vibetype.language AS ENUM (
'de',
'en'
);

COMMENT ON TYPE maevsi.language IS 'Supported ISO 639 language codes.';
COMMENT ON TYPE vibetype.language IS 'Supported ISO 639 language codes.';

COMMIT;
4 changes: 2 additions & 2 deletions src/deploy/enum_social_network.sql
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
BEGIN;

CREATE TYPE maevsi.social_network AS ENUM (
CREATE TYPE vibetype.social_network AS ENUM (
'facebook',
'instagram',
'tiktok',
'x'
);

COMMENT ON TYPE maevsi.social_network IS 'Social networks.';
COMMENT ON TYPE vibetype.social_network IS 'Social networks.';

COMMIT;
2 changes: 1 addition & 1 deletion src/deploy/extension_postgis.sql
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@ GRANT EXECUTE ON FUNCTION
st_coorddim(geometry),
st_geomfromgeojson(text),
st_srid(geography)
TO maevsi_anonymous, maevsi_account;
TO vibetype_anonymous, vibetype_account;

COMMIT;
14 changes: 7 additions & 7 deletions src/deploy/function_account_block_ids.sql
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
BEGIN;

CREATE FUNCTION maevsi_private.account_block_ids()
CREATE FUNCTION vibetype_private.account_block_ids()
RETURNS TABLE (id UUID) AS $$
BEGIN
RETURN QUERY
-- users blocked by the current user
SELECT blocked_account_id
FROM maevsi.account_block
WHERE created_by = maevsi.invoker_account_id()
FROM vibetype.account_block
WHERE created_by = vibetype.invoker_account_id()
UNION ALL
-- users who blocked the current user
SELECT created_by
FROM maevsi.account_block
WHERE blocked_account_id = maevsi.invoker_account_id();
FROM vibetype.account_block
WHERE blocked_account_id = vibetype.invoker_account_id();
END
$$ LANGUAGE PLPGSQL STRICT STABLE SECURITY DEFINER;

COMMENT ON FUNCTION maevsi_private.account_block_ids() IS 'Returns all account ids being blocked by the invoker and all accounts that blocked the invoker.';
COMMENT ON FUNCTION vibetype_private.account_block_ids() IS 'Returns all account ids being blocked by the invoker and all accounts that blocked the invoker.';

GRANT EXECUTE ON FUNCTION maevsi_private.account_block_ids() TO maevsi_account, maevsi_anonymous;
GRANT EXECUTE ON FUNCTION vibetype_private.account_block_ids() TO vibetype_account, vibetype_anonymous;

COMMIT;
12 changes: 6 additions & 6 deletions src/deploy/function_account_delete.sql
Original file line number Diff line number Diff line change
@@ -1,27 +1,27 @@
BEGIN;

CREATE FUNCTION maevsi.account_delete(
CREATE FUNCTION vibetype.account_delete(
"password" TEXT
) RETURNS VOID AS $$
DECLARE
_current_account_id UUID;
BEGIN
_current_account_id := current_setting('jwt.claims.account_id')::UUID;

IF (EXISTS (SELECT 1 FROM maevsi_private.account WHERE account.id = _current_account_id AND account.password_hash = crypt($1, account.password_hash))) THEN
IF (EXISTS (SELECT 1 FROM maevsi.event WHERE event.created_by = _current_account_id)) THEN
IF (EXISTS (SELECT 1 FROM vibetype_private.account WHERE account.id = _current_account_id AND account.password_hash = crypt($1, account.password_hash))) THEN
IF (EXISTS (SELECT 1 FROM vibetype.event WHERE event.created_by = _current_account_id)) THEN
RAISE 'You still own events!' USING ERRCODE = 'foreign_key_violation';
ELSE
DELETE FROM maevsi_private.account WHERE account.id = _current_account_id;
DELETE FROM vibetype_private.account WHERE account.id = _current_account_id;
END IF;
ELSE
RAISE 'Account with given password not found!' USING ERRCODE = 'invalid_password';
END IF;
END;
$$ LANGUAGE PLPGSQL STRICT SECURITY DEFINER;

COMMENT ON FUNCTION maevsi.account_delete(TEXT) IS 'Allows to delete an account.';
COMMENT ON FUNCTION vibetype.account_delete(TEXT) IS 'Allows to delete an account.';

GRANT EXECUTE ON FUNCTION maevsi.account_delete(TEXT) TO maevsi_account;
GRANT EXECUTE ON FUNCTION vibetype.account_delete(TEXT) TO vibetype_account;

COMMIT;
12 changes: 6 additions & 6 deletions src/deploy/function_account_email_address_verification.sql
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
BEGIN;

CREATE FUNCTION maevsi.account_email_address_verification(
CREATE FUNCTION vibetype.account_email_address_verification(
code UUID
) RETURNS VOID AS $$
DECLARE
_account maevsi_private.account;
_account vibetype_private.account;
BEGIN
SELECT *
FROM maevsi_private.account
FROM vibetype_private.account
INTO _account
WHERE account.email_address_verification = $1;

Expand All @@ -19,14 +19,14 @@ BEGIN
RAISE 'Verification code expired!' USING ERRCODE = 'object_not_in_prerequisite_state';
END IF;

UPDATE maevsi_private.account
UPDATE vibetype_private.account
SET email_address_verification = NULL
WHERE email_address_verification = $1;
END;
$$ LANGUAGE PLPGSQL STRICT SECURITY DEFINER;

COMMENT ON FUNCTION maevsi.account_email_address_verification(UUID) IS 'Sets the account''s email address verification code to `NULL` for which the email address verification code equals the one passed and is up to date.';
COMMENT ON FUNCTION vibetype.account_email_address_verification(UUID) IS 'Sets the account''s email address verification code to `NULL` for which the email address verification code equals the one passed and is up to date.';

GRANT EXECUTE ON FUNCTION maevsi.account_email_address_verification(UUID) TO maevsi_account, maevsi_anonymous;
GRANT EXECUTE ON FUNCTION vibetype.account_email_address_verification(UUID) TO vibetype_account, vibetype_anonymous;

COMMIT;
10 changes: 5 additions & 5 deletions src/deploy/function_account_password_change.sql
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
BEGIN;

CREATE FUNCTION maevsi.account_password_change(
CREATE FUNCTION vibetype.account_password_change(
password_current TEXT,
password_new TEXT
) RETURNS VOID AS $$
Expand All @@ -13,16 +13,16 @@ BEGIN

_current_account_id := current_setting('jwt.claims.account_id')::UUID;

IF (EXISTS (SELECT 1 FROM maevsi_private.account WHERE account.id = _current_account_id AND account.password_hash = crypt($1, account.password_hash))) THEN
UPDATE maevsi_private.account SET password_hash = crypt($2, gen_salt('bf')) WHERE account.id = _current_account_id;
IF (EXISTS (SELECT 1 FROM vibetype_private.account WHERE account.id = _current_account_id AND account.password_hash = crypt($1, account.password_hash))) THEN
UPDATE vibetype_private.account SET password_hash = crypt($2, gen_salt('bf')) WHERE account.id = _current_account_id;
ELSE
RAISE 'Account with given password not found!' USING ERRCODE = 'invalid_password';
END IF;
END;
$$ LANGUAGE PLPGSQL STRICT SECURITY DEFINER;

COMMENT ON FUNCTION maevsi.account_password_change(TEXT, TEXT) IS 'Allows to change an account''s password.';
COMMENT ON FUNCTION vibetype.account_password_change(TEXT, TEXT) IS 'Allows to change an account''s password.';

GRANT EXECUTE ON FUNCTION maevsi.account_password_change(TEXT, TEXT) TO maevsi_account;
GRANT EXECUTE ON FUNCTION vibetype.account_password_change(TEXT, TEXT) TO vibetype_account;

COMMIT;
12 changes: 6 additions & 6 deletions src/deploy/function_account_password_reset.sql
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
BEGIN;

CREATE FUNCTION maevsi.account_password_reset(
CREATE FUNCTION vibetype.account_password_reset(
code UUID,
"password" TEXT
) RETURNS VOID AS $$
DECLARE
_account maevsi_private.account;
_account vibetype_private.account;
BEGIN
IF (char_length($2) < 8) THEN
RAISE 'Password too short!' USING ERRCODE = 'invalid_parameter_value';
END IF;

SELECT *
FROM maevsi_private.account
FROM vibetype_private.account
INTO _account
WHERE account.password_reset_verification = $1;

Expand All @@ -24,16 +24,16 @@ BEGIN
RAISE 'Reset code expired!' USING ERRCODE = 'object_not_in_prerequisite_state';
END IF;

UPDATE maevsi_private.account
UPDATE vibetype_private.account
SET
password_hash = crypt($2, gen_salt('bf')),
password_reset_verification = NULL
WHERE account.password_reset_verification = $1;
END;
$$ LANGUAGE PLPGSQL STRICT SECURITY DEFINER;

COMMENT ON FUNCTION maevsi.account_password_reset(UUID, TEXT) IS 'Sets a new password for an account if there was a request to do so before that''s still up to date.';
COMMENT ON FUNCTION vibetype.account_password_reset(UUID, TEXT) IS 'Sets a new password for an account if there was a request to do so before that''s still up to date.';

GRANT EXECUTE ON FUNCTION maevsi.account_password_reset(UUID, TEXT) TO maevsi_anonymous, maevsi_account;
GRANT EXECUTE ON FUNCTION vibetype.account_password_reset(UUID, TEXT) TO vibetype_anonymous, vibetype_account;

COMMIT;
12 changes: 6 additions & 6 deletions src/deploy/function_account_password_reset_request.sql
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
BEGIN;

CREATE FUNCTION maevsi.account_password_reset_request(
CREATE FUNCTION vibetype.account_password_reset_request(
email_address TEXT,
"language" TEXT
) RETURNS VOID AS $$
DECLARE
_notify_data RECORD;
BEGIN
WITH updated AS (
UPDATE maevsi_private.account
UPDATE vibetype_private.account
SET password_reset_verification = gen_random_uuid()
WHERE account.email_address = $1
RETURNING *
Expand All @@ -17,14 +17,14 @@ BEGIN
updated.email_address,
updated.password_reset_verification,
updated.password_reset_verification_valid_until
FROM updated, maevsi.account
FROM updated, vibetype.account
WHERE updated.id = account.id
INTO _notify_data;

IF (_notify_data IS NULL) THEN
-- noop
ELSE
INSERT INTO maevsi_private.notification (channel, payload) VALUES (
INSERT INTO vibetype.notification (channel, payload) VALUES (
'account_password_reset_request',
jsonb_pretty(jsonb_build_object(
'account', _notify_data,
Expand All @@ -35,8 +35,8 @@ BEGIN
END;
$$ LANGUAGE PLPGSQL STRICT SECURITY DEFINER;

COMMENT ON FUNCTION maevsi.account_password_reset_request(TEXT, TEXT) IS 'Sets a new password reset verification code for an account.';
COMMENT ON FUNCTION vibetype.account_password_reset_request(TEXT, TEXT) IS 'Sets a new password reset verification code for an account.';

GRANT EXECUTE ON FUNCTION maevsi.account_password_reset_request(TEXT, TEXT) TO maevsi_anonymous, maevsi_account;
GRANT EXECUTE ON FUNCTION vibetype.account_password_reset_request(TEXT, TEXT) TO vibetype_anonymous, vibetype_account;

COMMIT;
22 changes: 11 additions & 11 deletions src/deploy/function_account_registration.sql
Original file line number Diff line number Diff line change
@@ -1,33 +1,33 @@
BEGIN;

CREATE FUNCTION maevsi.account_registration(
CREATE FUNCTION vibetype.account_registration(
username TEXT,
email_address TEXT,
"password" TEXT,
"language" TEXT
) RETURNS UUID AS $$
DECLARE
_new_account_private maevsi_private.account;
_new_account_public maevsi.account;
_new_account_private vibetype_private.account;
_new_account_public vibetype.account;
_new_account_notify RECORD;
BEGIN
IF (char_length(account_registration.password) < 8) THEN
RAISE 'Password too short!' USING ERRCODE = 'invalid_parameter_value';
END IF;

IF (EXISTS (SELECT 1 FROM maevsi.account WHERE account.username = account_registration.username)) THEN
IF (EXISTS (SELECT 1 FROM vibetype.account WHERE account.username = account_registration.username)) THEN
RAISE 'An account with this username already exists!' USING ERRCODE = 'unique_violation';
END IF;

IF (EXISTS (SELECT 1 FROM maevsi_private.account WHERE account.email_address = account_registration.email_address)) THEN
IF (EXISTS (SELECT 1 FROM vibetype_private.account WHERE account.email_address = account_registration.email_address)) THEN
RAISE 'An account with this email address already exists!' USING ERRCODE = 'unique_violation';
END IF;

INSERT INTO maevsi_private.account(email_address, password_hash, last_activity) VALUES
INSERT INTO vibetype_private.account(email_address, password_hash, last_activity) VALUES
(account_registration.email_address, crypt(account_registration.password, gen_salt('bf')), CURRENT_TIMESTAMP)
RETURNING * INTO _new_account_private;

INSERT INTO maevsi.account(id, username) VALUES
INSERT INTO vibetype.account(id, username) VALUES
(_new_account_private.id, account_registration.username)
RETURNING * INTO _new_account_public;

Expand All @@ -38,9 +38,9 @@ BEGIN
_new_account_private.email_address_verification_valid_until
INTO _new_account_notify;

INSERT INTO maevsi.contact(account_id, created_by) VALUES (_new_account_private.id, _new_account_private.id);
INSERT INTO vibetype.contact(account_id, created_by) VALUES (_new_account_private.id, _new_account_private.id);

INSERT INTO maevsi_private.notification (channel, payload) VALUES (
INSERT INTO vibetype.notification (channel, payload) VALUES (
'account_registration',
jsonb_pretty(jsonb_build_object(
'account', row_to_json(_new_account_notify),
Expand All @@ -52,8 +52,8 @@ BEGIN
END;
$$ LANGUAGE PLPGSQL STRICT SECURITY DEFINER;

COMMENT ON FUNCTION maevsi.account_registration(TEXT, TEXT, TEXT, TEXT) IS 'Creates a contact and registers an account referencing it.';
COMMENT ON FUNCTION vibetype.account_registration(TEXT, TEXT, TEXT, TEXT) IS 'Creates a contact and registers an account referencing it.';

GRANT EXECUTE ON FUNCTION maevsi.account_registration(TEXT, TEXT, TEXT, TEXT) TO maevsi_anonymous, maevsi_account;
GRANT EXECUTE ON FUNCTION vibetype.account_registration(TEXT, TEXT, TEXT, TEXT) TO vibetype_anonymous, vibetype_account;

COMMIT;
Loading