database.sql 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. -- Web Publication System Database Schema
  2. -- MariaDB/MySQL compatible
  3. CREATE DATABASE IF NOT EXISTS webpub;
  4. USE webpub;
  5. -- Publications table
  6. CREATE TABLE publications (
  7. id INT AUTO_INCREMENT PRIMARY KEY,
  8. title VARCHAR(255) NOT NULL,
  9. content TEXT NOT NULL,
  10. summary VARCHAR(500),
  11. author VARCHAR(100) NOT NULL,
  12. status ENUM('draft', 'published', 'archived') DEFAULT 'draft',
  13. created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
  14. updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  15. published_at TIMESTAMP NULL
  16. );
  17. -- Users table for admin authentication with LDAP support
  18. CREATE TABLE users (
  19. id INT AUTO_INCREMENT PRIMARY KEY,
  20. username VARCHAR(50) UNIQUE NOT NULL,
  21. password VARCHAR(255),
  22. email VARCHAR(255),
  23. role ENUM('admin', 'editor') DEFAULT 'editor',
  24. auth_type ENUM('local', 'ldap') DEFAULT 'local',
  25. ldap_dn VARCHAR(255),
  26. created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
  27. last_login TIMESTAMP NULL
  28. );
  29. -- Categories table
  30. CREATE TABLE categories (
  31. id INT AUTO_INCREMENT PRIMARY KEY,
  32. name VARCHAR(100) UNIQUE NOT NULL,
  33. description TEXT,
  34. created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
  35. );
  36. -- Publication categories junction table
  37. CREATE TABLE publication_categories (
  38. publication_id INT,
  39. category_id INT,
  40. PRIMARY KEY (publication_id, category_id),
  41. FOREIGN KEY (publication_id) REFERENCES publications(id) ON DELETE CASCADE,
  42. FOREIGN KEY (category_id) REFERENCES categories(id) ON DELETE CASCADE
  43. );
  44. -- Insert default admin user (password: admin123)
  45. INSERT INTO users (username, password, email, role, auth_type) VALUES
  46. ('admin', '$2y$10$92IXUNpkjO0rOQ5byMi.Ye4oKoEa3Ro9llC/.og/at2.uheWG/igi', 'admin@example.com', 'admin', 'local');
  47. -- Insert sample categories
  48. INSERT INTO categories (name, description) VALUES
  49. ('Technology', 'Articles about technology and programming'),
  50. ('News', 'Current events and news articles'),
  51. ('Tutorial', 'How-to guides and tutorials'),
  52. ('Opinion', 'Editorials and opinion pieces');
  53. -- Insert sample publications
  54. INSERT INTO publications (title, content, summary, author, status) VALUES
  55. ('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'),
  56. ('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'),
  57. ('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');