Changes between Version 3 and Version 4 of P7
- Timestamp:
- 04/25/26 23:02:41 (7 days ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
P7
v3 v4 2 2 3 3 == Custom Domains 4 {{{ 5 -- Check email format 4 ==== Automatically updates the story timestamp on every update 5 {{{ 6 6 CREATE DOMAIN valid_email AS VARCHAR(255) 7 7 CHECK (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 {{{ 10 11 CREATE DOMAIN story_rating AS DECIMAL(3,2) 11 12 CHECK (VALUE >= 0.00 AND VALUE <= 5.00); 12 13 -- Status of accepted values 13 }}} 14 ==== Status of accepted values 15 {{{ 14 16 CREATE DOMAIN story_status AS VARCHAR(50) 15 17 CHECK (VALUE IN ('draft', 'published', 'archived')); 16 17 -- Permission level from 1 to 5 18 }}} 19 ==== Permission level from 1 to 5 20 {{{ 18 21 CREATE DOMAIN permission_lvl AS INTEGER 19 22 CHECK (VALUE >= 1 AND VALUE <= 5); 20 21 -- URL / image path 23 }}} 24 ==== URL / image path 25 {{{ 22 26 CREATE DOMAIN valid_url AS VARCHAR(2048) 23 27 CHECK (VALUE ~* '^https?://.+'); … … 25 29 26 30 == Views 27 {{{ 28 -- Detailed view for each story with statistic 31 ==== Detailed view for each story with statistic 32 {{{ 29 33 CREATE OR REPLACE VIEW story_details_view AS 30 34 SELECT … … 58 62 s.image, s.story_created_at, 59 63 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 {{{ 61 67 CREATE MATERIALIZED VIEW top_stories_by_likes AS 62 68 SELECT … … 81 87 ORDER BY total_likes DESC 82 88 LIMIT 10; 83 84 -- View for user profile with all his stories 89 }}} 90 ==== View for user profile with all his stories 91 {{{ 85 92 CREATE OR REPLACE VIEW writer_profile_view AS 86 93 SELECT … … 108 115 109 116 == Stored Procedures and Functions 110 {{{ 111 -- Table for daily top story 117 ==== Table for daily top story 118 {{{ 112 119 CREATE TABLE daily_top_stories ( 113 120 day DATE PRIMARY KEY, … … 115 122 total_likes BIGINT 116 123 ); 117 118 -- Procedure: saves the most liked story of the previous day 124 }}} 125 ==== Saves the most liked story of the previous day 126 {{{ 119 127 CREATE OR REPLACE PROCEDURE get_daily_top_story() 120 128 LANGUAGE plpgsql … … 146 154 END; 147 155 $$; 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 {{{ 150 159 CREATE OR REPLACE PROCEDURE notify_collaborators( 151 160 p_story_id INTEGER, … … 183 192 END; 184 193 $$; 185 186 -- Function: calculates the engagement score for a given story 194 }}} 195 === Function 196 ==== Calculates the engagement score for a given story 197 {{{ 187 198 CREATE OR REPLACE FUNCTION calculate_engagement_score(p_story_id INTEGER) 188 199 RETURNS DECIMAL
