crwmolada

db_certusone

Jun 1st, 2025 (edited)
46
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MySQL 6.98 KB | None | 0 0
  1. -- --------------- CREATE DATABASE db_certusone -- ---------------
  2.  
  3. DROP DATABASE IF EXISTS db_certusone;
  4. CREATE DATABASE db_certusone;
  5. USE db_certusone;
  6. -- --------------- CREATE TABLES -- ---------------
  7.  
  8. -- [1] TABLE roles
  9. CREATE TABLE roles (
  10.     role_id INT AUTO_INCREMENT PRIMARY KEY,
  11.     role_name VARCHAR(50) NOT NULL,
  12.     role_description TEXT
  13. );
  14.  
  15.  
  16. -- [2] TABLE permissions
  17. CREATE TABLE permissions (
  18.     permission_id INT AUTO_INCREMENT PRIMARY KEY,
  19.     permission_name VARCHAR(50) NOT NULL,
  20.     permission_description TEXT
  21. );
  22.  
  23.  
  24. -- [3] Tabla roles_permissions
  25. CREATE TABLE roles_permissions (
  26.     role_permission_id INT AUTO_INCREMENT PRIMARY KEY,
  27.     id_role INT, -- FK
  28.     id_permission INT, -- FK
  29.    
  30.     --  Claves foráneas:
  31.     FOREIGN KEY (id_role) REFERENCES roles(role_id),
  32.     FOREIGN KEY (id_permission) REFERENCES permissions(permission_id)
  33. );
  34.  
  35.  
  36. -- [4] TABLE users
  37. CREATE TABLE users (
  38.     user_id INT AUTO_INCREMENT PRIMARY KEY,
  39.     id_role INT,-- FK
  40.     user_name VARCHAR(100) NOT NULL,
  41.     user_last_name VARCHAR(100) NOT NULL,
  42.     user_email VARCHAR(100) NOT NULL,
  43.     user_password VARCHAR(200) NOT NULL,
  44.     user_created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
  45.     user_updated_at DATETIME DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  46.     user_status BOOLEAN DEFAULT TRUE,
  47.  
  48.     -- Claves foráneas:
  49.     FOREIGN KEY (id_role) REFERENCES roles(role_id)
  50. );
  51.  
  52.  
  53. -- [5] TABLE user_profile
  54. CREATE TABLE user_profile (
  55.     profile_id INT AUTO_INCREMENT PRIMARY KEY,
  56.     id_user INT UNIQUE,
  57.     profile_biography VARCHAR(200),
  58.     profile_interests VARCHAR(200),
  59.     profile_social_links JSON,
  60.     profile_created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
  61.     profile_updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
  62.    
  63.    
  64.     -- Claves foráneas
  65.     FOREIGN KEY (id_user) REFERENCES users(user_id)
  66. );
  67.  
  68.  
  69. -- [6] TABLE mentor
  70. CREATE TABLE mentor (
  71.     mentor_id INT AUTO_INCREMENT PRIMARY KEY,
  72.     id_user INT,
  73.     average_rating DECIMAL(3,2),
  74.     is_available BOOLEAN DEFAULT TRUE,
  75.     mentor_status ENUM('pending_review', 'approved', 'rejected') DEFAULT 'pending_review',
  76.     approved_by_admin_id INT, -- quien revisó
  77.     admin_notes TEXT,
  78.     mentor_created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
  79.     mentor_updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  80.    
  81.     -- Claves foráneas
  82.     FOREIGN KEY (id_user) REFERENCES users(user_id)
  83. );
  84.  
  85.  
  86.  
  87. -- [7] TABLE mentor_resources
  88. CREATE TABLE mentor_resources (
  89.     resource_id INT AUTO_INCREMENT PRIMARY KEY,
  90.     id_mentor INT,
  91.     resource_title VARCHAR(100) NOT NULL,
  92.     resource_description TEXT,
  93.     resource_type ENUM('pdf', 'image') NOT NULL,
  94.     resource_file_url TEXT NOT NULL,
  95.     resource_file_size_kb INT CHECK (resource_file_size_kb <= 50),
  96.     resource_visibility ENUM('private', 'public', 'protected') DEFAULT 'private',
  97.     resource_status ENUM('pending_review', 'approved', 'rejected') DEFAULT 'pending_review',
  98.     resource_uploaded_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
  99.     resource_updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  100.    
  101.     FOREIGN KEY (id_mentor) REFERENCES mentor(mentor_id)
  102. );
  103.  
  104.  
  105. -- [8] TABLE careers
  106. CREATE TABLE careers (
  107.     career_id INT AUTO_INCREMENT PRIMARY KEY,
  108.     career_name VARCHAR(100) NOT NULL,
  109.     career_description TEXT
  110. );
  111.  
  112.  
  113. -- [9] TABLE mentor_requests
  114. CREATE TABLE mentor_requests (
  115.     request_id INT AUTO_INCREMENT PRIMARY KEY,
  116.     id_user INT NOT NULL, -- FK
  117.     id_career INT NOT NULL, -- FK
  118.     request_first_name VARCHAR(100) NOT NULL,
  119.     request_last_name VARCHAR(100) NOT NULL,
  120.     request_dni CHAR(8) UNIQUE,
  121.     request_phone_number VARCHAR(15),
  122.     request_gender CHAR(1),
  123.     request_campus VARCHAR(100),
  124.     request_institutional_email VARCHAR(100),
  125.     request_institutional_term INT,
  126.  
  127.     request_status ENUM('pending', 'approved', 'rejected') DEFAULT 'pending',
  128.     request_created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
  129.     request_reviewed_at DATETIME NULL,
  130.     request_reviewed_by INT NULL, -- getCurrentIdAdmin()
  131.  
  132.     -- Claves foráneas
  133.     FOREIGN KEY (id_user) REFERENCES users(user_id),
  134.     FOREIGN KEY (id_career) REFERENCES careers(career_id),
  135.     FOREIGN KEY (request_reviewed_by) REFERENCES users(user_id)
  136. );
  137.  
  138.  
  139.  
  140. -- [10] TABLE sessions
  141. CREATE TABLE sessions (
  142.     session_id INT AUTO_INCREMENT PRIMARY KEY,
  143.     session_date DATE NOT NULL,
  144.     session_start_time TIME NOT NULL,
  145.     session_end_time TIME NOT NULL,
  146.     session_topic VARCHAR(255),
  147.     session_status ENUM('pending', 'done', 'canceled') DEFAULT 'pending',
  148.     session_conection_url TEXT,
  149.     created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
  150.     id_user INT NOT NULL,
  151.    
  152.    
  153.     -- Claves foráneas
  154.     FOREIGN KEY (id_user) REFERENCES users(user_id)
  155. );
  156.  
  157.  
  158. -- [11] TABLE ratings
  159. CREATE TABLE ratings (
  160.     rating_id INT AUTO_INCREMENT PRIMARY KEY,
  161.     id_session INT NOT NULL,
  162.     id_user INT NOT NULL,
  163.     rating_score TINYINT UNSIGNED CHECK (rating_score BETWEEN 1 AND 5),
  164.     rating_created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
  165.     rating_updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  166.    
  167.    
  168.     -- Claves foráneas
  169.     FOREIGN KEY (id_session) REFERENCES sessions(session_id),
  170.     FOREIGN KEY (id_user) REFERENCES users(user_id)
  171. );
  172.  
  173.  
  174. -- [12] TABLE categories
  175. CREATE TABLE categories (
  176.     category_id INT AUTO_INCREMENT PRIMARY KEY,
  177.     category_name VARCHAR(100) NOT NULL,
  178.     category_parent_id INT DEFAULT NULL,
  179.     category_body TEXT,
  180.     category_created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
  181.     category_updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  182.     category_status ENUM('active', 'hidden', 'deleted') DEFAULT 'active',
  183.    
  184.    
  185.     -- Claves foráneas
  186.     FOREIGN KEY (category_parent_id) REFERENCES categories(category_id)
  187. );
  188.  
  189.  
  190. -- [13] TABLE posts
  191. CREATE TABLE posts (
  192.     post_id INT AUTO_INCREMENT PRIMARY KEY,
  193.     id_user INT NOT NULL,
  194.     id_category INT NOT NULL,
  195.     post_title VARCHAR(255) NOT NULL,
  196.     post_body TEXT NOT NULL,
  197.     post_created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
  198.     post_updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  199.     post_status ENUM('active', 'closed', 'deleted') DEFAULT 'active',
  200.    
  201.    
  202.     -- Claves foráneas
  203.     FOREIGN KEY (id_user) REFERENCES users(user_id),
  204.     FOREIGN KEY (id_category) REFERENCES categories(category_id)
  205. );
  206.  
  207.  
  208.  
  209. -- [14] TABLE comments
  210. CREATE TABLE comments (
  211.     comment_id INT AUTO_INCREMENT PRIMARY KEY,
  212.     id_post INT NOT NULL,
  213.     id_user INT NOT NULL,
  214.     comment_body TEXT NOT NULL,
  215.     comment_created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
  216.     comment_updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  217.     comment_status ENUM('visible', 'hidden', 'deleted') DEFAULT 'visible',
  218.    
  219.    
  220.     -- Claves foráneas
  221.     FOREIGN KEY (id_post) REFERENCES posts(post_id),
  222.     FOREIGN KEY (id_user) REFERENCES users(user_id)
  223. );
  224.  
Advertisement
Add Comment
Please, Sign In to add comment