Changes between Version 3 and Version 4 of P7


Ignore:
Timestamp:
04/25/26 23:02:41 (7 days ago)
Author:
211099
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • P7

    v3 v4  
    22
    33== Custom Domains
    4 {{{
    5 -- Check email format
     4==== Automatically updates the story timestamp on every update
     5{{{
    66CREATE DOMAIN valid_email AS VARCHAR(255)
    77CHECK (VALUE ~* '^[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,}$');
    8 
    9 -- Check rating range from 0 to 5
     8}}}
     9==== Check rating range from 0 to 5
     10{{{
    1011CREATE DOMAIN story_rating AS DECIMAL(3,2)
    1112CHECK (VALUE >= 0.00 AND VALUE <= 5.00);
    12 
    13 -- Status of accepted values
     13}}}
     14==== Status of accepted values
     15{{{
    1416CREATE DOMAIN story_status AS VARCHAR(50)
    1517CHECK (VALUE IN ('draft', 'published', 'archived'));
    16 
    17 -- Permission level from 1 to 5
     18}}}
     19==== Permission level from 1 to 5
     20{{{
    1821CREATE DOMAIN permission_lvl AS INTEGER
    1922CHECK (VALUE >= 1 AND VALUE <= 5);
    20 
    21 -- URL / image path
     23}}}
     24==== URL / image path
     25{{{
    2226CREATE DOMAIN valid_url AS VARCHAR(2048)
    2327CHECK (VALUE ~* '^https?://.+');
     
    2529
    2630== Views
    27 {{{
    28 -- Detailed view for each story with statistic
     31==== Detailed view for each story with statistic
     32{{{
    2933CREATE OR REPLACE VIEW story_details_view AS
    3034SELECT
     
    5862    s.image, s.story_created_at,
    5963    u.username, u.user_name, u.surname, st.status;
    60 -- Top 10 most popular stories by likes count =
     64}}}
     65==== Top 10 most popular stories by likes count
     66{{{
    6167CREATE MATERIALIZED VIEW top_stories_by_likes AS
    6268SELECT
     
    8187ORDER BY total_likes DESC
    8288LIMIT 10;
    83 
    84 -- View for user profile with all his stories
     89}}}
     90==== View for user profile with all his stories
     91{{{
    8592CREATE OR REPLACE VIEW writer_profile_view AS
    8693SELECT
     
    108115
    109116== Stored Procedures and Functions
    110 {{{
    111 -- Table for daily top story
     117==== Table for daily top story
     118{{{
    112119CREATE TABLE daily_top_stories (
    113120    day         DATE PRIMARY KEY,
     
    115122    total_likes BIGINT
    116123);
    117 
    118 -- Procedure: saves the most liked story of the previous day
     124}}}
     125==== Saves the most liked story of the previous day
     126{{{
    119127CREATE OR REPLACE PROCEDURE get_daily_top_story()
    120128LANGUAGE plpgsql
     
    146154END;
    147155$$;
    148 
    149 -- Procedure: sends a notification to all collaborators of a story
     156}}}
     157==== Procedure: sends a notification to all collaborators of a story
     158{{{
    150159CREATE OR REPLACE PROCEDURE notify_collaborators(
    151160    p_story_id  INTEGER,
     
    183192END;
    184193$$;
    185 
    186 -- Function: calculates the engagement score for a given story
     194}}}
     195=== Function
     196==== Calculates the engagement score for a given story
     197{{{
    187198CREATE OR REPLACE FUNCTION calculate_engagement_score(p_story_id INTEGER)
    188199RETURNS DECIMAL