This project provides an educational PostgreSQL database schema inspired by Spotify, including tables, views, triggers, indexes, and stored procedures for user management, music content, payments, friendships, and more. No special PostgreSQL features or extensions are required beyond standard UUID support.
- Users, artists, albums, tracks, playlists, and user relationships
- Wallet system for payments and package subscriptions
- Friendship requests and social features
- Likes, comments, and user activity tracking
- Views to summarize user preferences and activity
- Triggers to enforce business rules and data consistency
- Indexes for query optimization
Key components (see code for full details):
- Tables: users, artists, albums, tracks, playlists, user_follows, user_likes, packages, features, wallets, payments, user_relationships, etc.
- Functions: Create wallets, manage payments, handle friendships, validate likes, etc.
- Views: Aggregate friend activity and user preferences.
- Triggers: Enforce relationship and content integrity.
- PostgreSQL (with
uuid-osspextension enabled)
-
Clone the repository:
git clone https://github.com/Kebabist/Spotify-Database-Schema.git cd Spotify-Database-Schema -
Open a PostgreSQL session and run the schema creation script:
-- Create all tables and enable UUID extension \i Stupify_Table_Creator.sql
-
(Optional) Create functions, triggers, and views:
\i Stupify_functions.sql \i Stupify_Triggers.sql \i Stupify_views.sql \i Wallet.sql \i Stupify_Indexes.sql
SELECT create_all_tables();SELECT create_wallet('user-uuid-here');SELECT add_funds_to_wallet('user-uuid-here', 50.00);SELECT make_payment('user-uuid-here', 9.99, 'package-uuid-here');SELECT manage_friendship_request('sender-uuid', 'recipient-uuid', 'send');SELECT manage_friendship_request('recipient-uuid', 'sender-uuid', 'accept');SELECT * FROM user_friend_activity WHERE viewing_user_id = 'user-uuid-here' LIMIT 50;- Triggers and constraints enforce integrity, e.g., only friends can message each other and likes must reference valid content.
- Functions and stored procedures use UUIDs for primary keys.
- You may customize or extend the schema for your own educational projects.
Stupify_Table_Creator.sql: Table definitions and setupStupify_functions.sql: Business logic functionsStupify_Triggers.sql: Triggers for integrityStupify_views.sql: Predefined viewsWallet.sql: Wallet and payment functionsStupify_Indexes.sql: Indexes for performance
For the full list of files, visit the repository code page.
This project is for educational purposes only.
