updateweb
This commit is contained in:
46
backend/migrations/003_enhance_products.sql
Normal file
46
backend/migrations/003_enhance_products.sql
Normal file
@@ -0,0 +1,46 @@
|
||||
-- Migration: Enhance Products Table with Color Variants and Rich Text
|
||||
-- Created: 2025-12-19
|
||||
-- Description: Adds color variants, rich text description fields, and product images table
|
||||
|
||||
-- Add new columns to products table (if they don't exist)
|
||||
ALTER TABLE products
|
||||
ADD COLUMN IF NOT EXISTS weight DECIMAL(10,2),
|
||||
ADD COLUMN IF NOT EXISTS dimensions VARCHAR(100),
|
||||
ADD COLUMN IF NOT EXISTS material VARCHAR(255),
|
||||
ADD COLUMN IF NOT EXISTS metakeywords TEXT;
|
||||
|
||||
-- Create product images table with color variant support
|
||||
CREATE TABLE IF NOT EXISTS product_images (
|
||||
id TEXT PRIMARY KEY DEFAULT replace(gen_random_uuid()::text, '-', ''),
|
||||
product_id TEXT NOT NULL,
|
||||
image_url VARCHAR(500) NOT NULL,
|
||||
color_variant VARCHAR(100),
|
||||
alt_text VARCHAR(255),
|
||||
display_order INTEGER DEFAULT 0,
|
||||
is_primary BOOLEAN DEFAULT FALSE,
|
||||
created_at TIMESTAMP DEFAULT NOW(),
|
||||
CONSTRAINT fk_product_images_product FOREIGN KEY (product_id) REFERENCES products(id) ON DELETE CASCADE
|
||||
);
|
||||
|
||||
-- Create indexes for better performance
|
||||
CREATE INDEX IF NOT EXISTS idx_product_images_product_id ON product_images(product_id);
|
||||
CREATE INDEX IF NOT EXISTS idx_product_images_color ON product_images(color_variant);
|
||||
CREATE INDEX IF NOT EXISTS idx_product_images_primary ON product_images(product_id, is_primary) WHERE is_primary = TRUE;
|
||||
|
||||
-- Add comments for documentation
|
||||
COMMENT ON TABLE product_images IS 'Stores product images with color variant associations';
|
||||
COMMENT ON COLUMN product_images.color_variant IS 'Color variant name (e.g., "Red", "Blue", "Black")';
|
||||
COMMENT ON COLUMN product_images.is_primary IS 'Indicates if this is the primary image for the product/variant';
|
||||
|
||||
-- Update products table slug generation for existing products (if needed)
|
||||
UPDATE products
|
||||
SET slug = LOWER(REGEXP_REPLACE(REGEXP_REPLACE(name, '[^a-zA-Z0-9\s-]', '', 'g'), '\s+', '-', 'g'))
|
||||
WHERE slug IS NULL OR slug = '';
|
||||
|
||||
-- Ensure unique slug
|
||||
CREATE UNIQUE INDEX IF NOT EXISTS idx_products_slug_unique ON products(slug) WHERE slug IS NOT NULL AND slug != '';
|
||||
|
||||
-- Add default short description from existing description (if needed)
|
||||
UPDATE products
|
||||
SET shortdescription = LEFT(description, 200)
|
||||
WHERE (shortdescription IS NULL OR shortdescription = '') AND description IS NOT NULL AND description != '';
|
||||
17
backend/migrations/004_enhance_color_variants.sql
Normal file
17
backend/migrations/004_enhance_color_variants.sql
Normal file
@@ -0,0 +1,17 @@
|
||||
-- Migration: Enhance Product Color Variants with Pricing and Stock
|
||||
-- Created: 2025-12-19
|
||||
-- Description: Adds color code, per-variant pricing, and stock to product_images table
|
||||
|
||||
-- Add new columns to product_images table for color variants
|
||||
ALTER TABLE product_images
|
||||
ADD COLUMN IF NOT EXISTS color_code VARCHAR(7), -- Hex color code (e.g., #FF0000)
|
||||
ADD COLUMN IF NOT EXISTS variant_price DECIMAL(10,2), -- Optional variant-specific price
|
||||
ADD COLUMN IF NOT EXISTS variant_stock INTEGER DEFAULT 0; -- Stock quantity for this variant
|
||||
|
||||
-- Create index for color code lookups
|
||||
CREATE INDEX IF NOT EXISTS idx_product_images_color_code ON product_images(color_code);
|
||||
|
||||
-- Add comments for documentation
|
||||
COMMENT ON COLUMN product_images.color_code IS 'Hex color code for the variant (e.g., #FF0000 for red)';
|
||||
COMMENT ON COLUMN product_images.variant_price IS 'Optional price override for this specific color variant';
|
||||
COMMENT ON COLUMN product_images.variant_stock IS 'Stock quantity available for this specific color variant';
|
||||
30
backend/migrations/005-add-pagedata-column.sql
Normal file
30
backend/migrations/005-add-pagedata-column.sql
Normal file
@@ -0,0 +1,30 @@
|
||||
-- Add structured fields to pages table for contact information
|
||||
-- This allows each section to be edited independently without breaking layout
|
||||
|
||||
ALTER TABLE pages
|
||||
ADD COLUMN IF NOT EXISTS pagedata JSONB DEFAULT '{}'::jsonb;
|
||||
|
||||
COMMENT ON COLUMN pages.pagedata IS 'Structured data for pages that need separate editable fields (e.g., contact info)';
|
||||
|
||||
-- Update contact page with structured data
|
||||
UPDATE pages
|
||||
SET pagedata = jsonb_build_object(
|
||||
'contactInfo', jsonb_build_object(
|
||||
'phone', '+1 (555) 123-4567',
|
||||
'email', 'contact@skyartshop.com',
|
||||
'address', '123 Art Street, Creative City, CC 12345'
|
||||
),
|
||||
'businessHours', jsonb_build_array(
|
||||
jsonb_build_object('days', 'Monday - Friday', 'hours', '9:00 AM - 6:00 PM'),
|
||||
jsonb_build_object('days', 'Saturday', 'hours', '10:00 AM - 4:00 PM'),
|
||||
jsonb_build_object('days', 'Sunday', 'hours', 'Closed')
|
||||
),
|
||||
'header', jsonb_build_object(
|
||||
'title', 'Our Contact Information',
|
||||
'subtitle', 'Reach out to us through any of these channels'
|
||||
)
|
||||
)
|
||||
WHERE slug = 'contact';
|
||||
|
||||
-- Verify the update
|
||||
SELECT slug, pagedata FROM pages WHERE slug = 'contact';
|
||||
133
backend/migrations/005_fix_portfolio_and_add_test_data.sql
Normal file
133
backend/migrations/005_fix_portfolio_and_add_test_data.sql
Normal file
@@ -0,0 +1,133 @@
|
||||
-- Fix portfolioprojects table structure
|
||||
-- Add proper serial ID if not exists
|
||||
|
||||
-- First, check if the id column is serial, if not, convert it
|
||||
DO $$
|
||||
BEGIN
|
||||
-- Drop existing id column and recreate as serial
|
||||
IF EXISTS (
|
||||
SELECT 1 FROM information_schema.columns
|
||||
WHERE table_name = 'portfolioprojects' AND column_name = 'id'
|
||||
) THEN
|
||||
-- Create a temporary sequence if it doesn't exist
|
||||
CREATE SEQUENCE IF NOT EXISTS portfolioprojects_id_seq;
|
||||
|
||||
-- Set the id column to use the sequence
|
||||
ALTER TABLE portfolioprojects
|
||||
ALTER COLUMN id SET DEFAULT nextval('portfolioprojects_id_seq');
|
||||
|
||||
-- Set the sequence to the max id + 1
|
||||
PERFORM setval('portfolioprojects_id_seq', COALESCE((SELECT MAX(id) FROM portfolioprojects), 0) + 1, false);
|
||||
END IF;
|
||||
END $$;
|
||||
|
||||
-- Ensure we have the imageurl column
|
||||
ALTER TABLE portfolioprojects ADD COLUMN IF NOT EXISTS imageurl TEXT;
|
||||
|
||||
-- Ensure we have proper timestamps
|
||||
ALTER TABLE portfolioprojects ADD COLUMN IF NOT EXISTS createdat TIMESTAMP DEFAULT NOW();
|
||||
ALTER TABLE portfolioprojects ADD COLUMN IF NOT EXISTS updatedat TIMESTAMP DEFAULT NOW();
|
||||
|
||||
-- Add test portfolio projects
|
||||
INSERT INTO portfolioprojects (title, description, category, imageurl, isactive, createdat, updatedat)
|
||||
VALUES
|
||||
(
|
||||
'Sunset Landscape Series',
|
||||
'<h2>A Beautiful Collection of Sunset Landscapes</h2>
|
||||
<p>This series captures the breathtaking beauty of sunsets across different landscapes. Each piece showcases unique color palettes ranging from warm oranges and reds to cool purples and blues.</p>
|
||||
<h3>Key Features:</h3>
|
||||
<ul>
|
||||
<li>High-resolution digital paintings</li>
|
||||
<li>Vibrant color gradients</li>
|
||||
<li>Emotional depth and atmosphere</li>
|
||||
<li>Available in multiple sizes</li>
|
||||
</ul>
|
||||
<p><strong>Medium:</strong> Digital Art<br>
|
||||
<strong>Year:</strong> 2024<br>
|
||||
<strong>Collection:</strong> Nature Series</p>',
|
||||
'Digital Art',
|
||||
'/uploads/images/8ba675b9-c4e6-41e6-8f14-382b9ee1d019.jpg',
|
||||
true,
|
||||
NOW(),
|
||||
NOW()
|
||||
),
|
||||
(
|
||||
'Abstract Geometric Patterns',
|
||||
'<h2>Modern Abstract Compositions</h2>
|
||||
<p>A collection of abstract artworks featuring <strong>bold geometric patterns</strong> and contemporary design elements. These pieces explore the relationship between shape, color, and space.</p>
|
||||
<h3>Artistic Approach:</h3>
|
||||
<ol>
|
||||
<li>Started with basic geometric shapes</li>
|
||||
<li>Layered multiple patterns and textures</li>
|
||||
<li>Applied vibrant color combinations</li>
|
||||
<li>Refined composition for visual balance</li>
|
||||
</ol>
|
||||
<p><em>These works are inspired by modernist movements and contemporary design trends.</em></p>',
|
||||
'Abstract',
|
||||
'/uploads/images/8ba675b9-c4e6-41e6-8f14-382b9ee1d019.jpg',
|
||||
true,
|
||||
NOW(),
|
||||
NOW()
|
||||
),
|
||||
(
|
||||
'Portrait Photography Collection',
|
||||
'<h2>Capturing Human Emotion</h2>
|
||||
<p>This portrait series explores the <strong>depth of human emotion</strong> through carefully composed photographs. Each subject tells a unique story through their expression and body language.</p>
|
||||
<h3>Technical Details:</h3>
|
||||
<ul>
|
||||
<li><strong>Camera:</strong> Canon EOS R5</li>
|
||||
<li><strong>Lens:</strong> 85mm f/1.4</li>
|
||||
<li><strong>Lighting:</strong> Natural and studio</li>
|
||||
<li><strong>Processing:</strong> Adobe Lightroom & Photoshop</li>
|
||||
</ul>
|
||||
<p>Shot in various locations including urban settings, nature, and professional studios.</p>',
|
||||
'Photography',
|
||||
'/uploads/images/8ba675b9-c4e6-41e6-8f14-382b9ee1d019.jpg',
|
||||
true,
|
||||
NOW(),
|
||||
NOW()
|
||||
),
|
||||
(
|
||||
'Watercolor Botanical Illustrations',
|
||||
'<h2>Delicate Flora Studies</h2>
|
||||
<p>A series of <em>hand-painted watercolor illustrations</em> featuring various botanical subjects. These pieces celebrate the intricate beauty of plants and flowers.</p>
|
||||
<h3>Collection Includes:</h3>
|
||||
<ul>
|
||||
<li>Wildflowers and garden blooms</li>
|
||||
<li>Tropical plants and leaves</li>
|
||||
<li>Herbs and medicinal plants</li>
|
||||
<li>Seasonal botanical studies</li>
|
||||
</ul>
|
||||
<blockquote>
|
||||
<p>"Nature always wears the colors of the spirit." - Ralph Waldo Emerson</p>
|
||||
</blockquote>
|
||||
<p>Each illustration is created using professional-grade watercolors on cold-press paper.</p>',
|
||||
'Illustration',
|
||||
'/uploads/images/8ba675b9-c4e6-41e6-8f14-382b9ee1d019.jpg',
|
||||
true,
|
||||
NOW(),
|
||||
NOW()
|
||||
),
|
||||
(
|
||||
'Urban Architecture Study',
|
||||
'<h2>Modern Cityscapes and Structures</h2>
|
||||
<p>An exploration of <strong>contemporary urban architecture</strong> through the lens of artistic photography and digital manipulation.</p>
|
||||
<h3>Focus Areas:</h3>
|
||||
<ul>
|
||||
<li>Geometric building facades</li>
|
||||
<li>Glass and steel structures</li>
|
||||
<li>Reflections and symmetry</li>
|
||||
<li>Night photography and lighting</li>
|
||||
</ul>
|
||||
<p>This project was completed over 6 months, documenting various cities and their unique architectural personalities.</p>
|
||||
<p><strong>Featured Cities:</strong> New York, Tokyo, Dubai, London</p>',
|
||||
'Photography',
|
||||
'/uploads/images/8ba675b9-c4e6-41e6-8f14-382b9ee1d019.jpg',
|
||||
false,
|
||||
NOW(),
|
||||
NOW()
|
||||
)
|
||||
ON CONFLICT DO NOTHING;
|
||||
|
||||
-- Verify the data
|
||||
SELECT COUNT(*) as portfolio_count FROM portfolioprojects;
|
||||
19
backend/migrations/create-site-settings.sql
Normal file
19
backend/migrations/create-site-settings.sql
Normal file
@@ -0,0 +1,19 @@
|
||||
-- Create site_settings table for menu and other site configurations
|
||||
CREATE TABLE IF NOT EXISTS site_settings (
|
||||
key TEXT PRIMARY KEY,
|
||||
settings JSONB NOT NULL,
|
||||
createdat TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||
updatedat TIMESTAMP DEFAULT CURRENT_TIMESTAMP
|
||||
);
|
||||
|
||||
-- Insert default menu items
|
||||
INSERT INTO site_settings (key, settings)
|
||||
VALUES ('menu', '{"items":[
|
||||
{"label":"Home","url":"/home.html","icon":"bi-house","visible":true},
|
||||
{"label":"Shop","url":"/shop.html","icon":"bi-shop","visible":true},
|
||||
{"label":"Portfolio","url":"/portfolio.html","icon":"bi-images","visible":true},
|
||||
{"label":"About","url":"/about.html","icon":"bi-info-circle","visible":true},
|
||||
{"label":"Blog","url":"/blog.html","icon":"bi-journal-text","visible":true},
|
||||
{"label":"Contact","url":"/contact.html","icon":"bi-envelope","visible":true}
|
||||
]}')
|
||||
ON CONFLICT (key) DO NOTHING;
|
||||
27
backend/migrations/fix-uploaded-by-type.sql
Normal file
27
backend/migrations/fix-uploaded-by-type.sql
Normal file
@@ -0,0 +1,27 @@
|
||||
-- Fix uploaded_by and created_by column types to match adminusers.id (TEXT)
|
||||
-- Date: December 19, 2025
|
||||
-- Issue: Upload failing with "invalid input syntax for type integer: 'admin-default'"
|
||||
-- Root cause: adminusers.id is TEXT but uploads.uploaded_by was INTEGER
|
||||
|
||||
-- Change uploads.uploaded_by from INTEGER to TEXT
|
||||
ALTER TABLE uploads ALTER COLUMN uploaded_by TYPE TEXT;
|
||||
|
||||
-- Change media_folders.created_by from INTEGER to TEXT
|
||||
ALTER TABLE media_folders ALTER COLUMN created_by TYPE TEXT;
|
||||
|
||||
-- Verify the changes
|
||||
SELECT
|
||||
'uploads' as table_name,
|
||||
column_name,
|
||||
data_type
|
||||
FROM information_schema.columns
|
||||
WHERE table_name = 'uploads'
|
||||
AND column_name = 'uploaded_by'
|
||||
UNION ALL
|
||||
SELECT
|
||||
'media_folders' as table_name,
|
||||
column_name,
|
||||
data_type
|
||||
FROM information_schema.columns
|
||||
WHERE table_name = 'media_folders'
|
||||
AND column_name = 'created_by';
|
||||
Reference in New Issue
Block a user