refactor: remove Vendor.owner_user_id column

- Remove owner_user_id column and owner relationship from Vendor model
- Update User model ownership checks to use company relationship
- Add migration to drop owner_user_id column from vendors table

Ownership is now determined solely via vendor.company.owner_user_id

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
2025-12-02 19:39:08 +01:00
parent 14054bfd6d
commit 5ba4603ac9
4 changed files with 72 additions and 246 deletions

View File

@@ -1,234 +0,0 @@
# Documentation Migration - COMPLETE ✅
**Date:** November 17, 2025
**Status:** ALL CRITICAL CONTENT MIGRATED
**Action:** `docs/__REVAMPING/` folder can now be safely deleted
---
## Summary
All critical documentation has been successfully migrated from `docs/__REVAMPING/` to the main documentation structure. The documentation is now fully organized, branded as Wizamart, and ready for use.
---
## ✅ What Was Migrated
### 1. Letzshop → Wizamart Branding Fixed
-`mkdocs.yml` - All branding updated
-`docs/development/environment-detection.md` - All references updated
-`docs/index.md` - Already updated
- ✅ Copyright updated to 2024-2025
### 2. Frontend Documentation (13 files)
**Location:** `docs/frontend/`
-`overview.md` - Complete frontend architecture overview
-`shared/` - 6 files (UI components, pagination, sidebar, logging)
-`admin/` - 2 files (architecture, page templates)
-`vendor/` - 2 files (architecture, page templates)
-`shop/` - 2 files (architecture, page templates)
### 3. Backend Documentation (2 files)
**Location:** `docs/backend/`
-`admin-integration-guide.md`
-`admin-feature-integration.md`
### 4. API Documentation & Diagrams (4 files)
**Location:** `docs/api/`
-`authentication-flow-diagrams.md` ← Visual flow diagrams
-`rbac-visual-guide.md` ← RBAC visual diagrams
### 5. Architecture Documentation & Diagrams (7 files)
**Location:** `docs/architecture/`
**Diagrams:**
-`diagrams/multitenant-diagrams.md`
-`diagrams/vendor-domain-diagrams.md`
**Theme System:**
-`theme-system/overview.md`
-`theme-system/presets.md`
**URL Routing:**
-`url-routing/overview.md`
### 6. Development Documentation (8 files)
**Location:** `docs/development/`
-`environment-detection.md` (with all Letzshop→Wizamart fixes)
**Database Seeder:**
-`database-seeder/DATABASE_SEEDER_DOCUMENTATION.md`
-`database-seeder/MAKEFILE_DATABASE_SEEDER.md`
-`database-seeder/DATABASE_INIT_GUIDE.md`
-`database-seeder/DATABASE_QUICK_REFERENCE_GUIDE.md`
**Error Rendering:**
-`error-rendering/ERROR_RENDERING_DEVELOPER_DOCUMENTATION.md`
-`error-rendering/HTML_ERROR_RENDERING_FLOW_DIAGRAM.md`
### 7. Deployment Documentation (1 file)
**Location:** `docs/deployment/`
-`stripe-integration.md` - Stripe payment integration guide
---
## 📊 Final Statistics
**Total Files Migrated:** ~35+ documentation files
**New Directories Created:** 8
- `docs/frontend/` (with 4 subdirectories)
- `docs/architecture/diagrams/`
- `docs/architecture/theme-system/`
- `docs/architecture/url-routing/`
- `docs/development/database-seeder/`
- `docs/development/error-rendering/`
**mkdocs.yml Updates:** ~40+ new navigation entries added
**Build Status:** ✅ SUCCESS (no errors)
---
## 📁 Final Documentation Structure
```
docs/
├── getting-started/
├── architecture/
│ ├── Overview, Multi-tenant, Middleware, Request Flow, Auth & RBAC
│ ├── diagrams/ ✨ NEW
│ │ ├── multitenant-diagrams.md
│ │ └── vendor-domain-diagrams.md
│ ├── theme-system/ ✨ NEW
│ │ ├── overview.md
│ │ └── presets.md
│ └── url-routing/ ✨ NEW
│ └── overview.md
├── backend/
│ ├── Overview, Middleware Ref, RBAC Quick Ref
│ ├── admin-integration-guide.md ✨ NEW
│ └── admin-feature-integration.md ✨ NEW
├── frontend/ ✨ NEW (Complete section)
│ ├── overview.md
│ ├── shared/
│ │ ├── ui-components.md
│ │ ├── ui-components-quick-reference.md
│ │ ├── pagination.md
│ │ ├── pagination-quick-start.md
│ │ ├── sidebar.md
│ │ └── logging.md
│ ├── admin/
│ │ ├── architecture.md
│ │ └── page-templates.md
│ ├── vendor/
│ │ ├── architecture.md
│ │ └── page-templates.md
│ └── shop/
│ ├── architecture.md
│ └── page-templates.md
├── api/
│ ├── Authentication (Guide, Quick Ref, Flow Diagrams ✨ NEW)
│ ├── RBAC (Developer Guide, Visual Guide ✨ NEW)
│ ├── Error Handling
│ └── Rate Limiting
├── guides/
├── testing/
├── development/
│ ├── Icons, Naming Conventions, Database Migrations
│ ├── database-seeder/ ✨ NEW
│ │ ├── DATABASE_SEEDER_DOCUMENTATION.md
│ │ ├── MAKEFILE_DATABASE_SEEDER.md
│ │ ├── DATABASE_INIT_GUIDE.md
│ │ └── DATABASE_QUICK_REFERENCE_GUIDE.md
│ ├── Exception Handling, Frontend Exception Handling
│ ├── error-rendering/ ✨ NEW
│ │ ├── ERROR_RENDERING_DEVELOPER_DOCUMENTATION.md
│ │ └── HTML_ERROR_RENDERING_FLOW_DIAGRAM.md
│ ├── environment-detection.md (✅ Wizamart branding fixed)
│ ├── Contributing
│ └── PyCharm Setup
└── deployment/
├── Overview, Docker, Production, Environment Variables
└── stripe-integration.md ✨ NEW
```
---
## 🗑️ What's Left in __REVAMPING (Can Be Deleted)
The `docs/__REVAMPING/` folder now only contains:
1. **Duplicates** - Already migrated files
2. **Roadmaps** - Historical project roadmaps (already completed work)
3. **Old project docs** - Superseded by current documentation
4. **Migration tracking** - `MIGRATION_STATUS.md` (kept for reference)
**Recommendation:** The entire `docs/__REVAMPING/` folder can now be safely deleted.
---
## ✅ Verification Checklist
- ✅ All Letzshop references fixed (except marketplace imports context)
- ✅ All diagrams migrated
- ✅ All frontend documentation migrated
- ✅ All backend documentation migrated
- ✅ All architecture documentation migrated
- ✅ Database seeder docs migrated
- ✅ Error rendering docs migrated
- ✅ Theme system docs migrated
- ✅ URL routing docs migrated
- ✅ Stripe integration docs migrated
- ✅ mkdocs.yml updated with all new files
- ✅ Documentation builds successfully
- ✅ No critical content left unmigrated
---
## 🎯 Next Steps
1. **Review** - Quick review of migrated docs for any remaining Letzshop references
2. **Delete** - Remove `docs/__REVAMPING/` folder
3. **Commit** - Commit all changes to git
4. **Deploy** - Build and deploy documentation with `mkdocs serve` or `mkdocs build`
---
## 📝 Git Status
New files to add to git:
```
docs/api/authentication-flow-diagrams.md
docs/api/rbac-visual-guide.md
docs/architecture/diagrams/
docs/architecture/theme-system/
docs/architecture/url-routing/
docs/backend/admin-integration-guide.md
docs/backend/admin-feature-integration.md
docs/development/database-seeder/
docs/development/error-rendering/
docs/development/environment-detection.md
docs/deployment/stripe-integration.md
docs/frontend/ (entire directory)
mkdocs.yml (modified)
```
---
## 🎉 SUCCESS!
The documentation migration is **100% complete**. The Wizamart platform now has:
- ✅ Comprehensive, well-organized documentation
- ✅ Proper branding throughout
- ✅ Complete frontend, backend, and architecture guides
- ✅ All diagrams and visual guides included
- ✅ Database seeder and error rendering documentation
- ✅ Theme system and URL routing guides
- ✅ Stripe integration guide for future implementation
**The `docs/__REVAMPING/` folder can now be safely deleted.**

View File

@@ -0,0 +1,60 @@
"""remove_vendor_owner_user_id_column
Revision ID: 9f3a25ea4991
Revises: 5818330181a5
Create Date: 2025-12-02 17:58:45.663338
This migration removes the owner_user_id column from the vendors table.
Architecture Change:
- OLD: Each vendor had its own owner (vendor.owner_user_id)
- NEW: Vendors belong to a company, company has one owner (company.owner_user_id)
The vendor ownership is now determined via the company relationship:
- vendor.company.owner_user_id contains the owner
"""
from typing import Sequence, Union
from alembic import op
import sqlalchemy as sa
# revision identifiers, used by Alembic.
revision: str = '9f3a25ea4991'
down_revision: Union[str, None] = '5818330181a5'
branch_labels: Union[str, Sequence[str], None] = None
depends_on: Union[str, Sequence[str], None] = None
def upgrade() -> None:
"""
Remove owner_user_id column from vendors table.
Ownership is now determined via the company relationship.
Note: SQLite batch mode recreates the table without the column,
so we don't need to explicitly drop constraints.
"""
with op.batch_alter_table('vendors', schema=None) as batch_op:
# Drop the column - batch mode handles constraints automatically
batch_op.drop_column('owner_user_id')
def downgrade() -> None:
"""
Re-add owner_user_id column to vendors table.
WARNING: This will add the column back but NOT restore the data.
You will need to manually populate owner_user_id from company.owner_user_id
if reverting this migration.
"""
with op.batch_alter_table('vendors', schema=None) as batch_op:
batch_op.add_column(
sa.Column('owner_user_id', sa.Integer(), nullable=True)
)
batch_op.create_foreign_key(
'vendors_owner_user_id_fkey',
'users',
['owner_user_id'],
['id']
)

View File

@@ -51,7 +51,6 @@ class User(Base, TimestampMixin):
"MarketplaceImportJob", back_populates="user"
)
owned_companies = relationship("Company", back_populates="owner")
owned_vendors = relationship("Vendor", back_populates="owner")
vendor_memberships = relationship(
"VendorUser", foreign_keys="[VendorUser.user_id]", back_populates="user"
)
@@ -78,12 +77,20 @@ class User(Base, TimestampMixin):
return self.role == UserRole.VENDOR.value
def is_owner_of(self, vendor_id: int) -> bool:
"""Check if user is the owner of a specific vendor."""
return any(v.id == vendor_id for v in self.owned_vendors)
"""
Check if user is the owner of a specific vendor.
Ownership is determined via company ownership:
User owns Company → Company has Vendor → User owns Vendor
"""
for company in self.owned_companies:
if any(v.id == vendor_id for v in company.vendors):
return True
return False
def is_member_of(self, vendor_id: int) -> bool:
"""Check if user is a member of a specific vendor (owner or team)."""
# Check if owner
# Check if owner (via company)
if self.is_owner_of(vendor_id):
return True
# Check if team member
@@ -93,7 +100,7 @@ class User(Base, TimestampMixin):
def get_vendor_role(self, vendor_id: int) -> str:
"""Get user's role within a specific vendor."""
# Check if owner
# Check if owner (via company)
if self.is_owner_of(vendor_id):
return "owner"

View File

@@ -50,10 +50,6 @@ class Vendor(Base, TimestampMixin):
name = Column(String, nullable=False) # Non-nullable name column for the vendor (brand name)
description = Column(Text) # Optional text description column for the vendor
owner_user_id = Column(
Integer, ForeignKey("users.id"), nullable=True
) # Foreign key to user ID of the vendor's owner (DEPRECATED - use company.owner_user_id instead)
# Letzshop URLs - multi-language support (brand-specific marketplace feeds)
letzshop_csv_url_fr = Column(String) # URL for French CSV in Letzshop
letzshop_csv_url_en = Column(String) # URL for English CSV in Letzshop
@@ -73,9 +69,6 @@ class Vendor(Base, TimestampMixin):
company = relationship(
"Company", back_populates="vendors"
) # Relationship with Company model for the parent company
owner = relationship(
"User", back_populates="owned_vendors"
) # Relationship with User model for the vendor's owner (legacy)
vendor_users = relationship(
"VendorUser", back_populates="vendor"
) # Relationship with VendorUser model for users in this vendor