data seed feature for demo and prod

This commit is contained in:
2025-11-15 20:57:39 +01:00
parent 41439eed09
commit e3ed4a3295
17 changed files with 4574 additions and 1793 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,247 @@
# Database Commands - Quick Reference
## 🚀 Common Workflows
### First-Time Development Setup
```bash
make migrate-up # Apply migrations
make init-prod # Create admin user
make seed-demo # Add demo data
make dev # Start developing
```
### First-Time Production Setup
```bash
# 1. Configure .env
ENVIRONMENT=production
ADMIN_EMAIL=admin@yourcompany.com
ADMIN_PASSWORD=SecurePassword123!
# 2. Initialize
make migrate-up
make init-prod
# 3. Create vendors via admin panel
```
### Daily Development
```bash
make dev # Start server
make seed-demo-reset # Fresh demo data
make test # Run tests
```
---
## 📋 Command Reference
### Database Migrations
```bash
make migrate-create message="add_feature" # Create migration
make migrate-up # Apply migrations
make migrate-down # Rollback last
make migrate-status # Check status
```
### Initialization
```bash
make init-prod # Create admin + settings (SAFE for production)
```
### Demo Data (Development Only)
```bash
make seed-demo # 3 vendors + data
make seed-demo-minimal # 1 vendor only
make seed-demo-reset # DELETE ALL + reseed (DANGEROUS!)
```
### Complete Workflows
```bash
make db-setup # migrate + init + seed
make db-reset # rollback + migrate + reset
```
---
## ⚙️ Configuration (.env)
### Required Settings
```bash
ENVIRONMENT=development # development/staging/production
DATABASE_URL=sqlite:///./wizamart.db
# Admin credentials (CHANGE IN PRODUCTION!)
ADMIN_EMAIL=admin@wizamart.com
ADMIN_USERNAME=admin
ADMIN_PASSWORD=admin123
```
### Demo Data Controls
```bash
SEED_DEMO_VENDORS=3 # How many vendors
SEED_CUSTOMERS_PER_VENDOR=15 # Customers per vendor
SEED_PRODUCTS_PER_VENDOR=20 # Products per vendor
```
### Using Settings in Code
```python
from app.core.config import settings
# Environment checks
if settings.is_production:
# Production code
# Access configuration
email = settings.admin_email
db_url = settings.database_url
```
---
## 🔐 Default Credentials
### Admin (After init-prod)
```
URL: http://localhost:8000/admin/login
Username: admin
Password: admin123 (CHANGE IN PRODUCTION!)
```
### Demo Vendors (After seed-demo)
```
Vendor 1: vendor1@example.com / password123
Vendor 2: vendor2@example.com / password123
Vendor 3: vendor3@example.com / password123
```
⚠️ **All demo passwords are INSECURE - for development only!**
---
## 📊 What Each Command Creates
### `make init-prod`
✅ Platform admin user
✅ Admin settings
✅ Role templates
✅ RBAC schema verification
**Safe for production**: YES
**Contains fake data**: NO
### `make seed-demo`
✅ 3 demo vendors
✅ Demo vendor users
✅ ~45 customers (15 per vendor)
✅ ~60 products (20 per vendor)
✅ Vendor themes
✅ Custom domains
**Safe for production**: NO
**Contains fake data**: YES - ALL OF IT
### `make seed-demo-minimal`
✅ 1 demo vendor
✅ 1 demo vendor user
✅ ~15 customers
✅ ~20 products
✅ Vendor theme
✅ Custom domain
**Safe for production**: NO
**Contains fake data**: YES
---
## 🚨 Safety Features
### Production Warnings
```bash
# Automatically warns if:
⚠️ Using default admin password
⚠️ Using default JWT secret
⚠️ Debug mode enabled in production
⚠️ ALLOWED_HOSTS is wildcard
```
### Environment Protection
```bash
# seed_demo.py refuses to run if:
ENVIRONMENT=production
Error: Cannot run demo seeding in production!
```
### Reset Confirmation
```bash
make seed-demo-reset
# Requires typing: DELETE ALL DATA
```
---
## 🔍 Verification Commands
### Check Database State
```python
# Quick check
python -c "
from app.core.database import SessionLocal
from models.database.vendor import Vendor
db = SessionLocal()
print(f'Vendors: {db.query(Vendor).count()}')
db.close()
"
```
### View Settings
```python
# Check configuration
python -c "
from app.core.config import settings, print_environment_info
print_environment_info()
"
```
### Validate Production
```python
# Check production security
python -c "
from app.core.config import validate_production_settings
warnings = validate_production_settings()
if warnings:
for w in warnings: print(w)
else:
print('✅ Production configuration is secure')
"
```
---
## 🆘 Common Issues
### "Admin already exists"
**Normal!** init_production.py is idempotent (safe to run multiple times)
### "Table doesn't exist"
❌ Run migrations first: `make migrate-up`
### "Cannot run in production"
**Correct behavior!** seed_demo.py blocks production usage
### "Default password warning"
⚠️ Update `.env` with secure password in production
---
## 📚 More Help
```bash
make help # All commands
make help-db # Database-specific help
```
**Documentation**:
- `DATABASE_INIT_GUIDE.md` - Detailed guide
- `MIGRATION_GUIDE.md` - Migration from old system
- `README.md` - Project overview

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,91 @@
# Product Independence - Quick Reference
## TL;DR
**Problem:** Products must have a MarketplaceProduct entry, even for vendor-created products.
**Solution:** Make `marketplace_product_id` nullable and add core product fields to Product table.
**Impact:** 6-8 weeks implementation, requires database migration.
---
## Current Blocker for Seed Script
The seed script fails because it tries to create standalone products, but the current schema requires:
```python
marketplace_product_id = Column(..., nullable=False) # ❌ MANDATORY
```
### Temporary Workaround (Current Seed Script)
Create MarketplaceProduct for every Product until migration is complete:
```python
# For each product:
# 1. Create MarketplaceProduct
# 2. Create Product linked to it
```
This works but violates the desired architecture.
---
## Quick Decision Matrix
| Question | Answer | Priority |
|----------|--------|----------|
| Implement now? | Not urgent - current workaround functional | Medium |
| Block for launch? | No - can ship with current architecture | N/A |
| Technical debt? | Yes - should address in 1-2 quarters | Medium-High |
---
## Minimal Implementation (if needed quickly)
**Phase 1 Only - Make nullable:**
```python
# 1 hour migration
def upgrade():
op.alter_column('products', 'marketplace_product_id', nullable=True)
op.add_column('products', sa.Column('title', sa.String(), nullable=True))
op.add_column('products', sa.Column('gtin', sa.String(), nullable=True))
# Add only critical fields
# Updated model
class Product:
marketplace_product_id = Column(Integer, ForeignKey(...), nullable=True) # ✅
title = Column(String, nullable=True) # Temp nullable
gtin = Column(String, nullable=True)
```
Then gradually add remaining fields in future migrations.
---
## Key Stakeholders to Consult
- [ ] Product Manager - Business impact, priority
- [ ] Lead Developer - Technical approach, timeline
- [ ] DevOps - Migration strategy, rollback plan
- [ ] Vendors (if beta testing) - Feature importance
---
## Next Steps
1. **Review full migration plan:** `/outputs/PRODUCT_MIGRATION_PLAN.md`
2. **Discuss with team** - Get buy-in on approach
3. **Schedule implementation** - Based on priority
4. **Create tracking ticket** - Link to migration plan
---
## For Now: Use Workaround
The updated `seed_demo.py` creates both MarketplaceProduct and Product.
This is temporary until migration is implemented.
**No immediate action required** - continue development with current architecture.