Spaces:
Sleeping
Sleeping
File size: 10,432 Bytes
da819ac |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 |
const mongoose = require('mongoose');
const bcrypt = require('bcryptjs');
const User = require('./models/User');
const SourceText = require('./models/SourceText');
// MongoDB connection
const MONGODB_URI = process.env.MONGODB_URI || 'mongodb://localhost:27017/transcreation-sandbox';
async function seedDatabase() {
try {
console.log('🌱 Starting database seeding...');
console.log('Connecting to MongoDB...');
await mongoose.connect(MONGODB_URI);
console.log('✅ Connected to MongoDB');
// Create admin user
console.log('👤 Creating admin user...');
const adminPassword = await bcrypt.hash('admin123', 10);
const adminUser = await User.findOneAndUpdate(
{ email: 'admin@example.com' },
{
email: 'admin@example.com',
password: adminPassword,
username: 'admin',
role: 'admin',
isActive: true
},
{ upsert: true, new: true }
);
console.log('✅ Admin user created:', adminUser.email);
// Create student user
console.log('👤 Creating student user...');
const studentPassword = await bcrypt.hash('student123', 10);
const studentUser = await User.findOneAndUpdate(
{ email: 'student@example.com' },
{
email: 'student@example.com',
password: studentPassword,
username: 'student',
role: 'student',
isActive: true
},
{ upsert: true, new: true }
);
console.log('✅ Student user created:', studentUser.email);
// Clear existing source texts
console.log('🗑️ Clearing existing source texts...');
await SourceText.deleteMany({});
console.log('✅ Cleared existing source texts');
// Create tutorial tasks for Week 1
console.log('📚 Creating tutorial tasks for Week 1...');
const tutorialTasks = [
{
title: 'Tutorial Task 1',
content: 'The early bird catches the worm.',
category: 'tutorial',
weekNumber: 1,
sourceLanguage: 'English',
sourceCulture: 'Western',
difficulty: 'beginner',
translationBrief: 'Translate this proverb into Chinese, maintaining its cultural meaning.'
},
{
title: 'Tutorial Task 2',
content: 'Actions speak louder than words.',
category: 'tutorial',
weekNumber: 1,
sourceLanguage: 'English',
sourceCulture: 'Western',
difficulty: 'beginner',
translationBrief: 'Translate this saying into Chinese, preserving its idiomatic nature.'
},
{
title: 'Tutorial Task 3',
content: 'A picture is worth a thousand words.',
category: 'tutorial',
weekNumber: 1,
sourceLanguage: 'English',
sourceCulture: 'Western',
difficulty: 'beginner',
translationBrief: 'Translate this expression into Chinese, keeping its metaphorical meaning.'
}
];
for (const task of tutorialTasks) {
await SourceText.create(task);
}
console.log('✅ Created', tutorialTasks.length, 'tutorial tasks');
// Create tutorial tasks for Week 2 (with images)
console.log('📚 Creating tutorial tasks for Week 2...');
const tutorialTasksWeek2 = [
{
title: 'Tutorial Task 1 - Week 2',
content: 'A picture is worth a thousand words.',
category: 'tutorial',
weekNumber: 2,
sourceLanguage: 'English',
sourceCulture: 'Western',
difficulty: 'intermediate',
translationBrief: 'Translate this saying into Chinese, considering the visual context of the image.',
imageUrl: 'https://images.unsplash.com/photo-1506905925346-21bda4d32df4?w=800&h=600&fit=crop',
imageAlt: 'A beautiful landscape photograph showing mountains and lake'
},
{
title: 'Tutorial Task 2 - Week 2',
content: 'The early bird catches the worm.',
category: 'tutorial',
weekNumber: 2,
sourceLanguage: 'English',
sourceCulture: 'Western',
difficulty: 'intermediate',
translationBrief: 'Translate this proverb into Chinese, considering the visual elements in the image.',
imageUrl: 'https://images.unsplash.com/photo-1444464666168-49d633b86797?w=800&h=600&fit=crop',
imageAlt: 'A bird perched on a branch during sunrise'
},
{
title: 'Tutorial Task 3 - Week 2',
content: 'Actions speak louder than words.',
category: 'tutorial',
weekNumber: 2,
sourceLanguage: 'English',
sourceCulture: 'Western',
difficulty: 'intermediate',
translationBrief: 'Translate this saying into Chinese, considering the visual context provided.',
imageUrl: 'https://images.unsplash.com/photo-1557804506-669a67965ba0?w=800&h=600&fit=crop',
imageAlt: 'People working together in a collaborative environment'
}
];
for (const task of tutorialTasksWeek2) {
await SourceText.create(task);
}
console.log('✅ Created', tutorialTasksWeek2.length, 'tutorial tasks for Week 2');
// Create weekly practice tasks for Week 1
console.log('📝 Creating weekly practice tasks for Week 1...');
const weeklyPracticeTasks = [
{
title: 'Week 1 Practice 1',
content: '为什么睡前一定要吃夜宵?因为这样才不会做饿梦。',
category: 'weekly-practice',
weekNumber: 1,
sourceLanguage: 'Chinese',
sourceCulture: 'Chinese',
difficulty: 'intermediate',
translationBrief: 'Translate this humorous Chinese text into English, maintaining its wordplay and cultural humor.'
},
{
title: 'Week 1 Practice 2',
content: '女娲用什么补天?强扭的瓜。',
category: 'weekly-practice',
weekNumber: 1,
sourceLanguage: 'Chinese',
sourceCulture: 'Chinese',
difficulty: 'intermediate',
translationBrief: 'Translate this Chinese riddle into English, preserving its clever wordplay.'
},
{
title: 'Week 1 Practice 3',
content: '你知道如何区分真假大象吗?把他们仍进水中,真相会浮出水面的。',
category: 'weekly-practice',
weekNumber: 1,
sourceLanguage: 'Chinese',
sourceCulture: 'Chinese',
difficulty: 'intermediate',
translationBrief: 'Translate this Chinese joke into English, maintaining its pun and humor.'
},
{
title: 'Week 1 Practice 4',
content: 'What if Soy milk is just regular milk introducing itself in Spanish.',
category: 'weekly-practice',
weekNumber: 1,
sourceLanguage: 'English',
sourceCulture: 'Western',
difficulty: 'intermediate',
translationBrief: 'Translate this English joke into Chinese, preserving its linguistic humor.'
},
{
title: 'Week 1 Practice 5',
content: 'I can\'t believe I got fired from the calendar factory. All I did was take a day off.',
category: 'weekly-practice',
weekNumber: 1,
sourceLanguage: 'English',
sourceCulture: 'Western',
difficulty: 'intermediate',
translationBrief: 'Translate this English joke into Chinese, maintaining its wordplay humor.'
},
{
title: 'Week 1 Practice 6',
content: 'When life gives you melons, you might be dyslexic.',
category: 'weekly-practice',
weekNumber: 1,
sourceLanguage: 'English',
sourceCulture: 'Western',
difficulty: 'intermediate',
translationBrief: 'Translate this English wordplay into Chinese, preserving its linguistic cleverness.'
}
];
for (const task of weeklyPracticeTasks) {
await SourceText.create(task);
}
console.log('✅ Created', weeklyPracticeTasks.length, 'weekly practice tasks');
// Create practice examples (legacy support)
console.log('📖 Creating practice examples...');
const practiceExamples = [
{
title: 'Practice Example 1',
content: '为什么睡前一定要吃夜宵?因为这样才不会做饿梦。',
category: 'weekly-practice',
weekNumber: 1,
sourceLanguage: 'Chinese',
sourceCulture: 'Chinese',
difficulty: 'intermediate'
},
{
title: 'Practice Example 2',
content: '女娲用什么补天?强扭的瓜。',
category: 'weekly-practice',
weekNumber: 1,
sourceLanguage: 'Chinese',
sourceCulture: 'Chinese',
difficulty: 'intermediate'
},
{
title: 'Practice Example 3',
content: '你知道如何区分真假大象吗?把他们仍进水中,真相会浮出水面的。',
category: 'weekly-practice',
weekNumber: 1,
sourceLanguage: 'Chinese',
sourceCulture: 'Chinese',
difficulty: 'intermediate'
},
{
title: 'Practice Example 4',
content: 'What if Soy milk is just regular milk introducing itself in Spanish.',
category: 'weekly-practice',
weekNumber: 1,
sourceLanguage: 'English',
sourceCulture: 'Western',
difficulty: 'intermediate'
}
];
for (const example of practiceExamples) {
await SourceText.create(example);
}
console.log('✅ Created', practiceExamples.length, 'practice examples');
console.log('🎉 Database seeding completed successfully!');
console.log('');
console.log('📋 Created:');
console.log(' 👤 Admin user: admin@example.com / admin123');
console.log(' 👤 Student user: student@example.com / student123');
console.log(' 📚 Tutorial tasks: 3 tasks for Week 1');
console.log(' 📝 Weekly practice: 6 tasks for Week 1');
console.log(' 📖 Practice examples: 4 examples');
console.log('');
console.log('🔗 You can now:');
console.log(' 1. Log in with admin@example.com / admin123');
console.log(' 2. Log in with student@example.com / student123');
console.log(' 3. View tutorial tasks and weekly practice');
console.log(' 4. Create submissions and test the voting system');
} catch (error) {
console.error('❌ Database seeding failed:', error);
process.exit(1);
} finally {
await mongoose.disconnect();
console.log('🔌 Disconnected from MongoDB');
}
}
// Run the seeding
seedDatabase(); |