feat: добавить модуль базы данных с PGlite и Drizzle-ORM, а также CRUD для категорий списка желаний
This commit is contained in:
129
backend/seed.ts
129
backend/seed.ts
@@ -1,129 +0,0 @@
|
||||
import { DatabaseService } from './src/database/database.service';
|
||||
import { wishlistCategories, wishlistItems } from './src/database/schema';
|
||||
|
||||
async function seed() {
|
||||
const db = new DatabaseService();
|
||||
|
||||
console.log('🌱 Seeding wishlist categories...');
|
||||
|
||||
// Создать категории
|
||||
const categories = await db.database
|
||||
.insert(wishlistCategories)
|
||||
.values([
|
||||
{
|
||||
name: 'БЮДЖЕТНО',
|
||||
slug: 'tier-1',
|
||||
minPrice: 0,
|
||||
maxPrice: 150000, // 1500 руб
|
||||
color: '#00ff41',
|
||||
icon: '🟢',
|
||||
order: 1,
|
||||
},
|
||||
{
|
||||
name: 'СРЕДНИЙ',
|
||||
slug: 'tier-2',
|
||||
minPrice: 150001,
|
||||
maxPrice: 500000, // 5000 руб
|
||||
color: '#00cc33',
|
||||
icon: '🟡',
|
||||
order: 2,
|
||||
},
|
||||
{
|
||||
name: 'ТОП',
|
||||
slug: 'tier-3',
|
||||
minPrice: 500001,
|
||||
maxPrice: null, // без ограничения
|
||||
color: '#009922',
|
||||
icon: '🔴',
|
||||
order: 3,
|
||||
},
|
||||
])
|
||||
.returning();
|
||||
|
||||
console.log(`✅ Created ${categories.length} categories`);
|
||||
|
||||
console.log('🌱 Seeding wishlist items...');
|
||||
|
||||
// Создать примерные товары
|
||||
const items = await db.database
|
||||
.insert(wishlistItems)
|
||||
.values([
|
||||
{
|
||||
title: 'Зерновой Кофе (Эфиопия)',
|
||||
description: 'Люблю светлую обжарку. Желательно Эфиопия или Кения. Нужен именно в зернах.',
|
||||
price: 85000, // 850 руб
|
||||
currency: 'RUB',
|
||||
link: 'https://ozon.ru',
|
||||
images: [
|
||||
'url:https://images.unsplash.com/photo-1497935586351-b67a49e012bf?w=500',
|
||||
],
|
||||
categoryId: categories[0].id, // БЮДЖЕТНО
|
||||
},
|
||||
{
|
||||
title: 'Молескин в точку',
|
||||
description: 'Черный, классический. Обязательно в точку, а не в линейку.',
|
||||
price: 120000, // 1200 руб
|
||||
currency: 'RUB',
|
||||
link: 'https://wildberries.ru',
|
||||
images: [
|
||||
'url:https://images.unsplash.com/photo-1531346878377-a513bc957374?w=500',
|
||||
],
|
||||
categoryId: categories[0].id, // БЮДЖЕТНО
|
||||
},
|
||||
{
|
||||
title: 'Винил: Daft Punk',
|
||||
description: 'Альбом "Random Access Memories". Мечтаю послушать его на проигрывателе.',
|
||||
price: 350000, // 3500 руб
|
||||
currency: 'RUB',
|
||||
link: 'https://market.yandex.ru',
|
||||
images: [
|
||||
'url:https://images.unsplash.com/photo-1603048588665-791ca8aea617?w=500',
|
||||
],
|
||||
categoryId: categories[1].id, // СРЕДНИЙ
|
||||
},
|
||||
{
|
||||
title: 'D&D Стартовый набор',
|
||||
description: '5-я редакция. Хочу попробовать поиграть с друзьями.',
|
||||
price: 290000, // 2900 руб
|
||||
currency: 'RUB',
|
||||
link: 'https://hobbygames.ru',
|
||||
images: [
|
||||
'url:https://images.unsplash.com/photo-1632501641765-e568d90e09b2?w=500',
|
||||
],
|
||||
categoryId: categories[1].id, // СРЕДНИЙ
|
||||
},
|
||||
{
|
||||
title: 'LEGO Speed Champions',
|
||||
description: 'Любая машинка из этой серии, желательно Porsche или Ferrari.',
|
||||
price: 250000, // 2500 руб
|
||||
currency: 'RUB',
|
||||
link: 'https://detmir.ru',
|
||||
images: [
|
||||
'url:https://images.unsplash.com/photo-1585366119957-e9730b6d0f60?w=500',
|
||||
],
|
||||
categoryId: categories[1].id, // СРЕДНИЙ
|
||||
},
|
||||
{
|
||||
title: 'Keychron K2',
|
||||
description: 'Механическая клавиатура. Свичи Red или Brown. Нужна подсветка.',
|
||||
price: 900000, // 9000 руб
|
||||
currency: 'RUB',
|
||||
link: 'https://geekboards.ru',
|
||||
images: [
|
||||
'url:https://images.unsplash.com/photo-1595225476474-87563907a212?w=500',
|
||||
],
|
||||
categoryId: categories[2].id, // ТОП
|
||||
},
|
||||
])
|
||||
.returning();
|
||||
|
||||
console.log(`✅ Created ${items.length} wishlist items`);
|
||||
console.log('✨ Seeding completed!');
|
||||
|
||||
process.exit(0);
|
||||
}
|
||||
|
||||
seed().catch((error) => {
|
||||
console.error('❌ Seeding failed:', error);
|
||||
process.exit(1);
|
||||
});
|
||||
Reference in New Issue
Block a user