database.sql 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. -- Web Publication System Database Schema
  2. -- MariaDB/MySQL compatible
  3. -- Note: Database creation and selection is handled by setup script
  4. -- Publications table
  5. CREATE TABLE publications (
  6. id INT AUTO_INCREMENT PRIMARY KEY,
  7. title VARCHAR(255) NOT NULL,
  8. content TEXT NOT NULL,
  9. summary VARCHAR(500),
  10. author VARCHAR(100) NOT NULL,
  11. status ENUM('draft', 'published', 'archived') DEFAULT 'draft',
  12. created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
  13. updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  14. published_at TIMESTAMP NULL
  15. );
  16. -- Users table for admin authentication with LDAP support
  17. CREATE TABLE users (
  18. id INT AUTO_INCREMENT PRIMARY KEY,
  19. username VARCHAR(50) UNIQUE NOT NULL,
  20. password VARCHAR(255),
  21. email VARCHAR(255),
  22. role ENUM('admin', 'editor') DEFAULT 'editor',
  23. auth_type ENUM('local', 'ldap') DEFAULT 'local',
  24. ldap_dn VARCHAR(255),
  25. created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
  26. last_login TIMESTAMP NULL
  27. );
  28. -- Categories table
  29. CREATE TABLE categories (
  30. id INT AUTO_INCREMENT PRIMARY KEY,
  31. name VARCHAR(100) UNIQUE NOT NULL,
  32. description TEXT,
  33. created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
  34. );
  35. -- Publication categories junction table
  36. CREATE TABLE publication_categories (
  37. publication_id INT,
  38. category_id INT,
  39. PRIMARY KEY (publication_id, category_id),
  40. FOREIGN KEY (publication_id) REFERENCES publications(id) ON DELETE CASCADE,
  41. FOREIGN KEY (category_id) REFERENCES categories(id) ON DELETE CASCADE
  42. );
  43. -- Insert default admin user (password: admin123)
  44. INSERT INTO users (username, password, email, role, auth_type) VALUES
  45. ('admin', '$2y$10$92IXUNpkjO0rOQ5byMi.Ye4oKoEa3Ro9llC/.og/at2.uheWG/igi', 'admin@example.com', 'admin', 'local');
  46. -- Insert sample categories
  47. INSERT INTO categories (name, description) VALUES
  48. ('Technology', 'Articles about technology and programming'),
  49. ('News', 'Current events and news articles'),
  50. ('Tutorial', 'How-to guides and tutorials'),
  51. ('Opinion', 'Editorials and opinion pieces');
  52. -- Insert sample publications
  53. INSERT INTO publications (title, content, summary, author, status) VALUES
  54. ('Welcome to Web Publication System', 'This is a sample publication to demonstrate the system capabilities. You can edit or delete this publication from the admin panel.', 'A welcome message for new users', 'admin', 'published'),
  55. ('Getting Started with PHP', 'PHP is a popular server-side scripting language designed for web development. This article covers the basics of getting started with PHP development.', 'Introduction to PHP programming', 'admin', 'published'),
  56. ('Database Design Best Practices', 'Good database design is crucial for application performance and maintainability. This article covers essential principles and practices.', 'Tips for designing efficient databases', 'admin', 'draft');