This repository contains the complete PostgreSQL database implementation and OLAP analysis for a social network platform, developed as part of the SI40 (Database Management) unit at the UTBM engineering school.
This project addresses the design, implementation, and analysis of a relational database system for a social media application. The core challenge was designing a robust and secure database structure capable of handling core social network functionalities (posts, likes, comments, following) and enabling strategic decision-making through Online Analytical Processing (OLAP).
The project involved:
- Relational Modeling (MCD/MLD).
- PostgreSQL Implementation including advanced features (Procedures, Triggers, Cursors).
- User Management and Role-Based Access Control (RBAC).
- OLAP Analysis using Power BI and a Star Schema.
si40versionfinale (1).sql: Complete database implementation including schema, procedures, triggers, and sample dataPiana_Jury_Chairi_SI40_rapport.pdf: Comprehensive project report (in French) with:- MCD/MLD diagrams
- Detailed SQL query explanations
- OLAP analysis and Power BI dashboard
- Complete technical documentation
For detailed information about the project, please refer to the project report which includes:
- Complete database modeling (MCD/MLD)
- Step-by-step implementation guide
- SQL query examples with screenshots
- OLAP analysis methodology
- Power BI dashboard design
- Entity Relationship Diagram (ERD)
The database, implemented in PostgreSQL, includes several advanced features for data integrity, security, and automation:
UTILISATEURTable: Stores user profiles, including roles (administrateur,user_normal,spectateur).- User Management Procedure (
add_user): Safely inserts a new user, including:- Validation of the
ROLEfield against permitted values (administrateur,user_normal,spectateur). - Automatic generation of
ID_UTILISATEURusing a sequence (utilisateur_id_seq). - Email format validation before insertion.
- Validation of the
- Cursor Procedure (
process_utilisateurs): Demonstrates row-by-row data processing and retrieval within PL/pgSQL.
A trigger-based notification system is implemented using the NOTIFICATION table, automatically responding to user actions:
| Action | Trigger | Function | Description |
|---|---|---|---|
| Like | trigger_post_liked |
notify_post_liked() |
Notifies the post author when their post is liked. |
| Comment | trigger_comment_posted |
notify_comment_posted() |
Notifies the post author when a new comment is posted. |
| Follow | trigger_user_followed |
notify_user_followed() |
Notifies a user when they gain a new follower. |
HISTORIQUE_ACTIONSTable: Records allINSERT,UPDATE, andDELETEoperations on core tables (UTILISATEUR,POSTE,COMMENTAIRE).historique_trigger()Function: Uses theTG_OPspecial variable to determine the type of operation and records the old/new data payload inJSONBformat.
The project includes an Online Analytical Processing (OLAP) layer built using Power BI to support strategic decision-making:
- Schema: A Star Schema with
POSTEas the central Fact Table. - Dimensions: Key dimensions include
Utilisateur,Commentaire,Notification,Aime(Like), andSuit(Follow). - Key Metrics Tracked:
- Post Popularity (Likes vs. Comments)
- Engagement trends over time (Likes by Date)
- User activity (Posts vs. Comments)
- Notification Volume by Day
- Average user age and demographics
- PostgreSQL 12+ installed
- psql command-line tool or pgAdmin 4
- Git
- Clone the repository:
git clone https://github.com/victorpiana/SocialNetwork-DB-Analysis.git
cd SocialNetwork-DB-Analysis- Create the database:
psql -U postgres -c "CREATE DATABASE social_network;"- Execute the SQL file:
psql -U postgres -d social_network -f "si40versionfinale (1).sql"That's it! The database is now ready with all tables, procedures, triggers, and sample data.
- Role-Based Access Control (RBAC): Three user roles with distinct permissions:
administrateur: Full access to all tables and operationsuser_normal: Standard user operations (create posts, like, comment, follow)spectateur: Read-only access
- Email Validation: Ensures data quality at the database level through triggers
- Audit Trail: Complete history of all data modifications in
HISTORIQUE_ACTIONS - Input Validation: Procedures validate data before insertion to maintain integrity
The database includes several callable functions and procedures:
-- Add a new user with validation
CALL add_user('John Doe', 'john@example.com', 'user_normal', 'securePassword123');
-- Process and display all users (using cursor)
SELECT * FROM process_utilisateurs();
-- View recent notifications
SELECT * FROM NOTIFICATION ORDER BY DATE_NOTIFICATION DESC;
-- Check audit log
SELECT * FROM HISTORIQUE_ACTIONS ORDER BY DATE_ACTION DESC;
-- Get user statistics
SELECT COUNT(*) as total_users FROM UTILISATEUR;
SELECT AVG(EXTRACT(YEAR FROM AGE(DATE_NAISSANCE))) as avg_age FROM UTILISATEUR;Victor Piana - Database modeling, SQL implementation
Cyprien Jury - SQL queries, procedures, triggers
Hamza Chairi - OLAP analysis, Power BI dashboard
Engineering Students – UTBM, SI40 (June 2024)
Supervised by: Mme Christine Lahoud
| Category | Technology | Usage |
|---|---|---|
| Database | PostgreSQL | Core database management system |
| Modeling | WinDesign | MCD/MLD diagram creation |
| Administration | pgAdmin 4 | Database administration and testing |
| Analytics | Power BI | OLAP analysis and visualization |
| Language | PL/pgSQL | Stored procedures and triggers |
This project is part of an academic curriculum at UTBM and is provided for educational purposes.