feat: add Phase 2 migration, make urls command, fix seed script

- Create loyalty_003 migration: company-based architecture (adds
  company_id to all loyalty tables, creates company_loyalty_settings,
  renames vendor_id to enrolled_at_vendor_id on cards)
- Move platform migration back to alembic/versions (not loyalty-specific)
- Add version_locations to alembic.ini for module migration discovery
- Add make urls/urls-dev/urls-prod commands (scripts/show_urls.py)
- Fix seed_demo.py: import all module models to resolve SQLAlchemy
  string relationships, fix multiple admin query, set platform_id
  on vendor content pages
- Fix loyalty test fixtures to match Phase 2 model columns

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-02-06 20:56:07 +01:00
parent 994c6419f0
commit 922616c9e3
7 changed files with 861 additions and 29 deletions

View File

@@ -7,7 +7,6 @@ Provides fixtures for:
- Loyalty cards
- Transactions
- Staff PINs
- Authentication tokens for loyalty tests
"""
import uuid
@@ -23,9 +22,6 @@ from app.modules.loyalty.models import (
)
from app.modules.loyalty.models.loyalty_program import LoyaltyType
from app.modules.loyalty.models.loyalty_transaction import TransactionType
from app.modules.tenancy.models import Company, Vendor, VendorUser, VendorUserType
from app.modules.customers.models import Customer
from middleware.auth import AuthManager
@pytest.fixture
@@ -60,7 +56,6 @@ def test_loyalty_program(db, test_company):
@pytest.fixture
def test_loyalty_program_no_expiration(db, test_company):
"""Create a test loyalty program without point expiration."""
# Use different company to avoid unique constraint
from app.modules.tenancy.models import Company
unique_id = str(uuid.uuid4())[:8]
@@ -101,13 +96,9 @@ def test_loyalty_card(db, test_loyalty_program, test_customer, test_vendor):
customer_id=test_customer.id,
enrolled_at_vendor_id=test_vendor.id,
card_number=f"CARD-{unique_id}",
customer_email=test_customer.email,
customer_phone=test_customer.phone,
customer_name=f"{test_customer.first_name} {test_customer.last_name}",
points_balance=100,
stamps_balance=0,
total_points_earned=150,
total_points_redeemed=50,
points_redeemed=50,
is_active=True,
last_activity_at=datetime.now(UTC),
)
@@ -127,10 +118,7 @@ def test_loyalty_card_inactive(db, test_loyalty_program, test_vendor):
customer_id=None,
enrolled_at_vendor_id=test_vendor.id,
card_number=f"INACTIVE-{unique_id}",
customer_email=f"inactive{unique_id}@test.com",
customer_name="Inactive Customer",
points_balance=500,
stamps_balance=0,
total_points_earned=500,
is_active=True,
# Last activity was 400 days ago (beyond 365-day expiration)
@@ -166,16 +154,15 @@ def test_loyalty_transaction(db, test_loyalty_card, test_vendor):
@pytest.fixture
def test_staff_pin(db, test_loyalty_program, test_vendor):
"""Create a test staff PIN."""
from app.modules.loyalty.services.pin_service import pin_service
unique_id = str(uuid.uuid4())[:8]
pin = StaffPin(
program_id=test_loyalty_program.id,
company_id=test_loyalty_program.company_id,
vendor_id=test_vendor.id,
staff_name=f"Test Staff {unique_id}",
pin_hash=pin_service._hash_pin("1234"),
name=f"Test Staff {unique_id}",
is_active=True,
)
pin.set_pin("1234")
db.add(pin)
db.commit()
db.refresh(pin)