webupdate

This commit is contained in:
Local Server
2026-01-18 02:22:05 -06:00
parent 6fc159051a
commit 2a2a3d99e5
135 changed files with 54897 additions and 9825 deletions

View File

@@ -0,0 +1,65 @@
-- Migration: Create Customers Table for Customer Authentication
-- Date: 2026-01-15
-- Description: Customer accounts for frontend login, email verification, and newsletter
-- Create customers table
CREATE TABLE IF NOT EXISTS customers (
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
first_name VARCHAR(100) NOT NULL,
last_name VARCHAR(100) NOT NULL,
email VARCHAR(255) NOT NULL UNIQUE,
password_hash VARCHAR(255) NOT NULL,
phone VARCHAR(50),
-- Email verification
email_verified BOOLEAN DEFAULT FALSE,
verification_code VARCHAR(6),
verification_code_expires TIMESTAMP WITH TIME ZONE,
-- Password reset
reset_token VARCHAR(100),
reset_token_expires TIMESTAMP WITH TIME ZONE,
-- Account status
is_active BOOLEAN DEFAULT TRUE,
-- Newsletter subscription
newsletter_subscribed BOOLEAN DEFAULT TRUE,
-- OAuth providers (for future Google/Facebook/Apple login)
oauth_provider VARCHAR(50),
oauth_provider_id VARCHAR(255),
-- Metadata
last_login TIMESTAMP WITH TIME ZONE,
login_count INTEGER DEFAULT 0,
created_at TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP
);
-- Create indexes for better performance
CREATE INDEX IF NOT EXISTS idx_customers_email ON customers(email);
CREATE INDEX IF NOT EXISTS idx_customers_verification_code ON customers(verification_code) WHERE verification_code IS NOT NULL;
CREATE INDEX IF NOT EXISTS idx_customers_reset_token ON customers(reset_token) WHERE reset_token IS NOT NULL;
CREATE INDEX IF NOT EXISTS idx_customers_newsletter ON customers(newsletter_subscribed) WHERE newsletter_subscribed = TRUE;
CREATE INDEX IF NOT EXISTS idx_customers_created_at ON customers(created_at DESC);
-- Create trigger to auto-update updated_at
CREATE OR REPLACE FUNCTION update_customers_updated_at()
RETURNS TRIGGER AS $$
BEGIN
NEW.updated_at = CURRENT_TIMESTAMP;
RETURN NEW;
END;
$$ LANGUAGE plpgsql;
DROP TRIGGER IF EXISTS customers_updated_at_trigger ON customers;
CREATE TRIGGER customers_updated_at_trigger
BEFORE UPDATE ON customers
FOR EACH ROW
EXECUTE FUNCTION update_customers_updated_at();
-- Add comment for documentation
COMMENT ON TABLE customers IS 'Customer accounts for frontend authentication and newsletter';
COMMENT ON COLUMN customers.verification_code IS '6-digit code sent via email for verification';
COMMENT ON COLUMN customers.newsletter_subscribed IS 'Whether customer wants to receive newsletter emails';

View File

@@ -0,0 +1,49 @@
-- Migration 008: Create customer cart and wishlist tables
-- For storing customer shopping cart and wishlist items
-- Customer Cart Items Table
CREATE TABLE IF NOT EXISTS customer_cart (
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
customer_id UUID NOT NULL REFERENCES customers(id) ON DELETE CASCADE,
product_id TEXT NOT NULL REFERENCES products(id) ON DELETE CASCADE,
quantity INTEGER NOT NULL DEFAULT 1 CHECK (quantity > 0),
variant_color VARCHAR(100),
variant_size VARCHAR(50),
added_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
UNIQUE(customer_id, product_id, variant_color, variant_size)
);
-- Customer Wishlist Table
CREATE TABLE IF NOT EXISTS customer_wishlist (
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
customer_id UUID NOT NULL REFERENCES customers(id) ON DELETE CASCADE,
product_id TEXT NOT NULL REFERENCES products(id) ON DELETE CASCADE,
added_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
UNIQUE(customer_id, product_id)
);
-- Indexes for performance
CREATE INDEX IF NOT EXISTS idx_cart_customer_id ON customer_cart(customer_id);
CREATE INDEX IF NOT EXISTS idx_cart_product_id ON customer_cart(product_id);
CREATE INDEX IF NOT EXISTS idx_wishlist_customer_id ON customer_wishlist(customer_id);
CREATE INDEX IF NOT EXISTS idx_wishlist_product_id ON customer_wishlist(product_id);
-- Trigger to update updated_at on cart items
CREATE OR REPLACE FUNCTION update_cart_updated_at()
RETURNS TRIGGER AS $$
BEGIN
NEW.updated_at = CURRENT_TIMESTAMP;
RETURN NEW;
END;
$$ LANGUAGE plpgsql;
DROP TRIGGER IF EXISTS cart_updated_at_trigger ON customer_cart;
CREATE TRIGGER cart_updated_at_trigger
BEFORE UPDATE ON customer_cart
FOR EACH ROW
EXECUTE FUNCTION update_cart_updated_at();
-- Add comments
COMMENT ON TABLE customer_cart IS 'Customer shopping cart items - persisted across sessions';
COMMENT ON TABLE customer_wishlist IS 'Customer wishlist/saved items';