feat: Complete onboarding system with No Website functionality

- Add No Website button to Step 2 with business description form
- Implement onboarding cache service for browser-side data storage
- Add business info database models and API endpoints
- Update API key manager to save keys to .env file immediately
- Add database migration scripts for business info table
- Create reset onboarding script for fresh starts
- Implement hybrid data storage (API keys to backend, other data to cache)
- Add comprehensive business info CRUD operations
- Include database table creation and migration tools
This commit is contained in:
Om-Singh1808
2025-09-04 11:03:35 +05:30
committed by ي
parent 201960ce9d
commit aeb7751d48
5 changed files with 333 additions and 4 deletions

View File

@@ -0,0 +1,27 @@
-- Migration: Add user_business_info table
-- Description: Creates table for storing business information when users don't have websites
-- Date: 2024-01-XX
CREATE TABLE IF NOT EXISTS user_business_info (
id INTEGER PRIMARY KEY AUTOINCREMENT,
user_id INTEGER,
business_description TEXT NOT NULL,
industry VARCHAR(100),
target_audience TEXT,
business_goals TEXT,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
-- Create index for faster user lookups
CREATE INDEX IF NOT EXISTS idx_user_business_info_user_id ON user_business_info(user_id);
-- Add trigger to automatically update updated_at timestamp
CREATE TRIGGER IF NOT EXISTS update_user_business_info_timestamp
AFTER UPDATE ON user_business_info
FOR EACH ROW
BEGIN
UPDATE user_business_info
SET updated_at = CURRENT_TIMESTAMP
WHERE id = NEW.id;
END;

View File

@@ -0,0 +1,100 @@
#!/usr/bin/env python3
"""
Migration script to create the user_business_info table.
This script should be run once to set up the database schema.
"""
import os
import sys
import sqlite3
from pathlib import Path
from loguru import logger
# Add the backend directory to the Python path
backend_dir = Path(__file__).parent.parent
sys.path.insert(0, str(backend_dir))
def run_migration():
"""Run the business info table migration."""
try:
# Get the database path
db_path = backend_dir / "alwrity.db"
logger.info(f"🔄 Starting business info table migration...")
logger.info(f"📁 Database path: {db_path}")
# Check if database exists
if not db_path.exists():
logger.warning(f"⚠️ Database file not found at {db_path}")
logger.info("📝 Creating new database file...")
# Read the migration SQL
migration_file = backend_dir / "database" / "migrations" / "add_business_info_table.sql"
if not migration_file.exists():
logger.error(f"❌ Migration file not found: {migration_file}")
return False
with open(migration_file, 'r') as f:
migration_sql = f.read()
logger.info("📋 Migration SQL loaded successfully")
# Connect to database and run migration
conn = sqlite3.connect(str(db_path))
cursor = conn.cursor()
# Check if table already exists
cursor.execute("""
SELECT name FROM sqlite_master
WHERE type='table' AND name='user_business_info'
""")
if cursor.fetchone():
logger.info(" Table 'user_business_info' already exists, skipping migration")
conn.close()
return True
# Execute the migration
cursor.executescript(migration_sql)
conn.commit()
# Verify the table was created
cursor.execute("""
SELECT name FROM sqlite_master
WHERE type='table' AND name='user_business_info'
""")
if cursor.fetchone():
logger.success("✅ Migration completed successfully!")
logger.info("📊 Table 'user_business_info' created with the following structure:")
# Show table structure
cursor.execute("PRAGMA table_info(user_business_info)")
columns = cursor.fetchall()
for col in columns:
logger.info(f" - {col[1]} ({col[2]}) {'NOT NULL' if col[3] else 'NULL'}")
conn.close()
return True
else:
logger.error("❌ Migration failed - table was not created")
conn.close()
return False
except Exception as e:
logger.error(f"❌ Migration failed with error: {str(e)}")
return False
if __name__ == "__main__":
logger.info("🚀 Starting ALwrity Business Info Migration")
success = run_migration()
if success:
logger.success("🎉 Migration completed successfully!")
sys.exit(0)
else:
logger.error("💥 Migration failed!")
sys.exit(1)

View File

@@ -430,8 +430,11 @@ class APIKeyManager:
def load_api_keys(self):
"""Load API keys from environment variables."""
# Reload environment variables first
load_dotenv(override=True)
# Reload environment variables first - use backend directory path
import os
backend_dir = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
env_path = os.path.join(backend_dir, ".env")
load_dotenv(env_path, override=True)
env_mapping = {
"OPENAI_API_KEY": "openai",
@@ -492,8 +495,10 @@ class APIKeyManager:
# Update environment variable
os.environ[env_var] = api_key
# Update .env file
env_path = ".env"
# Update .env file - use backend directory path
import os
backend_dir = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
env_path = os.path.join(backend_dir, ".env")
if os.path.exists(env_path):
with open(env_path, 'r') as f:
lines = f.readlines()