database.sql 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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
  18. CREATE TABLE users (
  19. id INT AUTO_INCREMENT PRIMARY KEY,
  20. username VARCHAR(50) UNIQUE NOT NULL,
  21. password VARCHAR(255) NOT NULL,
  22. email VARCHAR(255),
  23. role ENUM('admin', 'editor') DEFAULT 'editor',
  24. created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
  25. );
  26. -- Categories table
  27. CREATE TABLE categories (
  28. id INT AUTO_INCREMENT PRIMARY KEY,
  29. name VARCHAR(100) UNIQUE NOT NULL,
  30. description TEXT,
  31. created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
  32. );
  33. -- Publication categories junction table
  34. CREATE TABLE publication_categories (
  35. publication_id INT,
  36. category_id INT,
  37. PRIMARY KEY (publication_id, category_id),
  38. FOREIGN KEY (publication_id) REFERENCES publications(id) ON DELETE CASCADE,
  39. FOREIGN KEY (category_id) REFERENCES categories(id) ON DELETE CASCADE
  40. );
  41. -- Insert default admin user (password: admin123)
  42. INSERT INTO users (username, password, email, role) VALUES
  43. ('admin', '$2y$10$92IXUNpkjO0rOQ5byMi.Ye4oKoEa3Ro9llC/.og/at2.uheWG/igi', 'admin@example.com', 'admin');
  44. -- Insert sample categories
  45. INSERT INTO categories (name, description) VALUES
  46. ('Technology', 'Articles about technology and programming'),
  47. ('News', 'Current events and news articles'),
  48. ('Tutorial', 'How-to guides and tutorials'),
  49. ('Opinion', 'Editorials and opinion pieces');
  50. -- Insert sample publications
  51. INSERT INTO publications (title, content, summary, author, status) VALUES
  52. ('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'),
  53. ('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'),
  54. ('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');