Files
shop-pip/app/seed.py
T

119 lines
4.4 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
from decimal import Decimal
from sqlalchemy import select
from sqlalchemy.orm import Session
from app.models import Category, Product
CATEGORIES = [
{
"slug": "keys",
"name": "Игровые ключи",
"description": "Steam, Epic, Origin и другие платформы",
"sort_order": 1,
},
{
"slug": "software",
"name": "Софт",
"description": "Лицензии и подписки для работы",
"sort_order": 2,
},
{
"slug": "accounts",
"name": "Аккаунты",
"description": "Готовые профили с контентом",
"sort_order": 3,
},
{
"slug": "giftcards",
"name": "Подарочные карты",
"description": "Цифровые коды пополнения",
"sort_order": 4,
},
]
PRODUCTS = [
{
"slug": "steam-wallet-1000",
"title": "Steam Wallet 1000 ₽",
"short_description": "Код пополнения кошелька Steam на 1000 рублей",
"description": "Цифровой код активируется в клиенте Steam. Доставка сразу после оплаты.",
"price": Decimal("1049.00"),
"category_slug": "giftcards",
"image_gradient": "mint",
"is_featured": True,
"delivery_note": "Код на email за 13 минуты",
},
{
"slug": "adobe-cc-1m",
"title": "Adobe Creative Cloud — 1 месяц",
"short_description": "Полный доступ к Photoshop, Premiere, Illustrator",
"description": "Официальная подписка на месяц. Данные для входа приходят автоматически.",
"price": Decimal("1890.00"),
"category_slug": "software",
"image_gradient": "coral",
"is_featured": True,
"delivery_note": "Доступ в личном кабинете",
},
{
"slug": "cyberpunk-steam",
"title": "Cyberpunk 2077 — Steam Key",
"short_description": "Полная версия с обновлениями для Steam",
"description": "Ключ активации для региона RU/CIS. Работает с аккаунтом Steam.",
"price": Decimal("1299.00"),
"category_slug": "keys",
"image_gradient": "ink",
"is_featured": True,
"delivery_note": "Ключ сразу после оплаты",
},
{
"slug": "spotify-premium-3m",
"title": "Spotify Premium — 3 месяца",
"short_description": "Музыка без рекламы и офлайн-режим",
"description": "Подписка активируется на ваш аккаунт или выдаётся новый профиль.",
"price": Decimal("799.00"),
"category_slug": "accounts",
"image_gradient": "sand",
"is_featured": True,
"delivery_note": "Активация до 15 минут",
},
{
"slug": "windows-11-pro",
"title": "Windows 11 Pro Key",
"short_description": "Розничный ключ активации Windows 11 Pro",
"description": "Подходит для чистой установки и апгрейда. Инструкция в письме.",
"price": Decimal("2490.00"),
"category_slug": "software",
"image_gradient": "mint",
"is_featured": False,
"delivery_note": "Ключ на email",
},
{
"slug": "playstation-1500",
"title": "PlayStation Store 1500 ₽",
"short_description": "Карта пополнения аккаунта PSN",
"description": "Цифровой ваучер для российского региона PlayStation Network.",
"price": Decimal("1549.00"),
"category_slug": "giftcards",
"image_gradient": "coral",
"is_featured": False,
"delivery_note": "Код за несколько минут",
},
]
def seed_if_empty(db: Session) -> None:
has_categories = db.scalar(select(Category.id).limit(1)) is not None
if not has_categories:
for item in CATEGORIES:
db.add(Category(**item))
db.commit()
has_products = db.scalar(select(Product.id).limit(1)) is not None
if not has_products:
for item in PRODUCTS:
db.add(Product(**item))
db.commit()