Created
June 6, 2025 08:06
-
-
Save ilvalerione/a2215a81b63ff3a41fe87a014141c1fb to your computer and use it in GitHub Desktop.
Demo database for NeuronAI Data Analyst Agent
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Database configuration | |
$host = 'localhost'; | |
$dbname = 'blog'; | |
$username = 'root'; | |
$password = ''; | |
try { | |
// Create PDO instance | |
$pdo = new \PDO("mysql:host=$host;dbname=$dbname;charset=utf8mb4", $username, $password, [ | |
\PDO::ATTR_ERRMODE => \PDO::ERRMODE_EXCEPTION, | |
\PDO::ATTR_DEFAULT_FETCH_MODE => \PDO::FETCH_ASSOC, | |
]); | |
echo "Connected to database successfully!\n"; | |
// Create tables | |
createTables($pdo); | |
// Generate and insert users | |
$users = generateUsers(); | |
insertUsers($pdo, $users); | |
// Generate and insert articles for each user | |
insertArticles($pdo, $users); | |
echo "\nDatabase seeded successfully!\n"; | |
echo "Created 10 users with 10 articles each (100 total articles)\n"; | |
} catch (\PDOException $e) { | |
die("Connection failed: " . $e->getMessage()); | |
} | |
function createTables($pdo) { | |
// Drop tables if they exist (for clean slate) | |
$pdo->exec("DROP TABLE IF EXISTS articles"); | |
$pdo->exec("DROP TABLE IF EXISTS users"); | |
// Create users table | |
$createUsersTable = " | |
CREATE TABLE users ( | |
id INT AUTO_INCREMENT PRIMARY KEY, | |
name VARCHAR(100) NOT NULL, | |
email VARCHAR(150) UNIQUE NOT NULL, | |
bio TEXT, | |
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP | |
) | |
"; | |
// Create articles table | |
$createArticlesTable = " | |
CREATE TABLE articles ( | |
id INT AUTO_INCREMENT PRIMARY KEY, | |
user_id INT NOT NULL, | |
title VARCHAR(255) NOT NULL, | |
content TEXT NOT NULL, | |
stars INT DEFAULT 0, | |
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, | |
FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE | |
) | |
"; | |
$pdo->exec($createUsersTable); | |
$pdo->exec($createArticlesTable); | |
echo "Tables created successfully!\n"; | |
} | |
function generateUsers() { | |
$firstNames = ['Alex', 'Sofia', 'Marco', 'Emma', 'Luca', 'Isabella', 'Matteo', 'Giulia', 'Francesco', 'Chiara']; | |
$lastNames = ['Rossi', 'Ferrari', 'Bianchi', 'Romano', 'Galli', 'Conti', 'Ricci', 'Marino', 'Greco', 'Bruno']; | |
$domains = ['gmail.com', 'yahoo.com', 'outlook.com', 'hotmail.com', 'icloud.com']; | |
$bios = [ | |
'Passionate developer with 10+ years of experience in web technologies.', | |
'Tech enthusiast who loves exploring new frameworks and technologies.', | |
'Full-stack developer specializing in modern web applications.', | |
'Software architect with expertise in scalable system design.', | |
'Frontend specialist focused on user experience and interface design.', | |
'Backend engineer passionate about performance optimization.', | |
'DevOps engineer with strong automation and infrastructure skills.', | |
'Mobile developer creating cross-platform applications.', | |
'Data scientist turning insights into actionable solutions.', | |
'Product manager bridging technology and business requirements.' | |
]; | |
$users = []; | |
for ($i = 0; $i < 10; $i++) { | |
$firstName = $firstNames[$i]; | |
$lastName = $lastNames[$i]; | |
$email = strtolower($firstName . '.' . $lastName . '@' . $domains[array_rand($domains)]); | |
$users[] = [ | |
'name' => $firstName . ' ' . $lastName, | |
'email' => $email, | |
'bio' => $bios[$i] | |
]; | |
} | |
return $users; | |
} | |
function insertUsers($pdo, $users) { | |
$stmt = $pdo->prepare("INSERT INTO users (name, email, bio) VALUES (?, ?, ?)"); | |
foreach ($users as $user) { | |
$stmt->execute([$user['name'], $user['email'], $user['bio']]); | |
} | |
echo "Inserted 10 users successfully!\n"; | |
} | |
function insertArticles($pdo, $users) { | |
$articleTitles = [ | |
'Getting Started with Modern PHP Development', | |
'Best Practices for Database Design', | |
'Understanding Design Patterns in Software Development', | |
'Building Scalable Web Applications', | |
'The Future of Web Development', | |
'Optimizing Application Performance', | |
'Security Considerations for Web Apps', | |
'Microservices Architecture Explained', | |
'Introduction to Test-Driven Development', | |
'Managing Technical Debt Effectively', | |
'API Design Best Practices', | |
'Docker and Containerization Guide', | |
'Version Control with Git', | |
'Continuous Integration and Deployment', | |
'Database Optimization Techniques', | |
'Frontend Framework Comparison', | |
'Mobile-First Development Approach', | |
'Cloud Computing Fundamentals', | |
'Machine Learning for Developers', | |
'Cybersecurity in Modern Applications' | |
]; | |
$contentTemplates = [ | |
'This article explores the fundamental concepts and provides practical examples for implementation. We will dive deep into the topic and examine real-world use cases.', | |
'In this comprehensive guide, we will walk through step-by-step instructions and best practices that have been proven in production environments.', | |
'Understanding this concept is crucial for modern development. This article breaks down complex ideas into digestible explanations with code examples.', | |
'This tutorial covers everything you need to know to get started, from basic concepts to advanced techniques used by industry professionals.', | |
'Learn how to implement these strategies effectively in your projects. We will cover common pitfalls and how to avoid them.', | |
'This in-depth analysis examines the pros and cons of different approaches and provides recommendations based on real-world experience.', | |
'Discover the latest trends and techniques that are shaping the future of development. Includes practical tips and implementation strategies.', | |
'A practical approach to solving common challenges faced by developers. This article includes code samples and detailed explanations.', | |
'Master these essential skills with our comprehensive guide. From beginner concepts to advanced techniques used in enterprise applications.', | |
'Everything you need to know about this important topic, explained with clear examples and practical applications for your projects.' | |
]; | |
$stmt = $pdo->prepare("INSERT INTO articles (user_id, title, content, stars) VALUES (?, ?, ?, ?)"); | |
// Get user IDs | |
$userIds = $pdo->query("SELECT id FROM users ORDER BY id")->fetchAll(PDO::FETCH_COLUMN); | |
$articleIndex = 0; | |
foreach ($userIds as $userId) { | |
for ($i = 0; $i < 10; $i++) { | |
$title = $articleTitles[$articleIndex % count($articleTitles)]; | |
$content = $contentTemplates[$i % count($contentTemplates)]; | |
$stars = rand(0, 500); // Random stars between 0 and 500 | |
$stmt->execute([$userId, $title, $content, $stars]); | |
$articleIndex++; | |
} | |
} | |
echo "Inserted 100 articles successfully!\n"; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment