Files
SkyArtShop/initialize-database.csx

251 lines
10 KiB
Plaintext
Raw Normal View History

#!/usr/bin/env dotnet-script
#r "nuget: MongoDB.Driver, 2.23.1"
using System;
using MongoDB.Driver;
using MongoDB.Bson;
// Configuration
var connectionString = "mongodb://localhost:27017";
var databaseName = "SkyArtShopDB";
Console.WriteLine("========================================");
Console.WriteLine("SkyArt Shop - Database Initialization");
Console.WriteLine("========================================");
Console.WriteLine();
try
{
var client = new MongoClient(connectionString);
var database = client.GetDatabase(databaseName);
// 1. Add Sample Products
Console.WriteLine("[1/4] Adding sample products...");
var productsCollection = database.GetCollection<BsonDocument>("Products");
var productCount = await productsCollection.CountDocumentsAsync(new BsonDocument());
if (productCount == 0)
{
var sampleProducts = new[]
{
new BsonDocument
{
{ "Name", "Vintage Scrapbook Paper Set" },
{ "Description", "Beautiful vintage-inspired scrapbook paper collection with 50 unique designs" },
{ "Price", 24.99 },
{ "Category", "Scrapbooking" },
{ "ImageUrl", "/uploads/images/8ba675b9-c4e6-41e6-8f14-382b9ee1d019.jpg" },
{ "StockQuantity", 50 },
{ "IsActive", true },
{ "IsFeatured", true },
{ "IsTopSeller", true },
{ "Tags", new BsonArray { "vintage", "paper", "scrapbooking" } },
{ "CreatedAt", DateTime.UtcNow },
{ "UpdatedAt", DateTime.UtcNow }
},
new BsonDocument
{
{ "Name", "Journal Sticker Pack" },
{ "Description", "Adorable stickers perfect for journaling and planning" },
{ "Price", 12.99 },
{ "Category", "Journaling" },
{ "ImageUrl", "/uploads/images/8ba675b9-c4e6-41e6-8f14-382b9ee1d019.jpg" },
{ "StockQuantity", 100 },
{ "IsActive", true },
{ "IsFeatured", true },
{ "IsTopSeller", true },
{ "Tags", new BsonArray { "stickers", "journal", "cute" } },
{ "CreatedAt", DateTime.UtcNow },
{ "UpdatedAt", DateTime.UtcNow }
},
new BsonDocument
{
{ "Name", "Washi Tape Collection" },
{ "Description", "Set of 20 colorful washi tapes for all your crafting needs" },
{ "Price", 18.99 },
{ "Category", "Supplies" },
{ "ImageUrl", "/uploads/images/8ba675b9-c4e6-41e6-8f14-382b9ee1d019.jpg" },
{ "StockQuantity", 75 },
{ "IsActive", true },
{ "IsFeatured", true },
{ "IsTopSeller", true },
{ "Tags", new BsonArray { "washi", "tape", "colorful" } },
{ "CreatedAt", DateTime.UtcNow },
{ "UpdatedAt", DateTime.UtcNow }
},
new BsonDocument
{
{ "Name", "Card Making Kit" },
{ "Description", "Complete kit for creating beautiful handmade cards" },
{ "Price", 34.99 },
{ "Category", "Cardmaking" },
{ "ImageUrl", "/uploads/images/8ba675b9-c4e6-41e6-8f14-382b9ee1d019.jpg" },
{ "StockQuantity", 30 },
{ "IsActive", true },
{ "IsFeatured", true },
{ "IsTopSeller", true },
{ "Tags", new BsonArray { "cards", "kit", "crafts" } },
{ "CreatedAt", DateTime.UtcNow },
{ "UpdatedAt", DateTime.UtcNow }
},
new BsonDocument
{
{ "Name", "Premium Journaling Pens" },
{ "Description", "Set of fine-tip pens perfect for detailed journaling" },
{ "Price", 15.99 },
{ "Category", "Journaling" },
{ "ImageUrl", "/uploads/images/8ba675b9-c4e6-41e6-8f14-382b9ee1d019.jpg" },
{ "StockQuantity", 60 },
{ "IsActive", true },
{ "IsFeatured", false },
{ "IsTopSeller", false },
{ "Tags", new BsonArray { "pens", "journal", "writing" } },
{ "CreatedAt", DateTime.UtcNow },
{ "UpdatedAt", DateTime.UtcNow }
},
new BsonDocument
{
{ "Name", "Collage Paper Bundle" },
{ "Description", "Mixed media papers perfect for collage projects" },
{ "Price", 22.99 },
{ "Category", "Collaging" },
{ "ImageUrl", "/uploads/images/8ba675b9-c4e6-41e6-8f14-382b9ee1d019.jpg" },
{ "StockQuantity", 40 },
{ "IsActive", true },
{ "IsFeatured", false },
{ "IsTopSeller", false },
{ "Tags", new BsonArray { "collage", "paper", "mixed media" } },
{ "CreatedAt", DateTime.UtcNow },
{ "UpdatedAt", DateTime.UtcNow }
}
};
await productsCollection.InsertManyAsync(sampleProducts);
Console.WriteLine($" ✓ Added {sampleProducts.Length} sample products");
}
else
{
Console.WriteLine($" ⚠ Products already exist ({productCount} products found)");
}
// 2. Add Homepage Sections
Console.WriteLine();
Console.WriteLine("[2/4] Adding homepage sections...");
var sectionsCollection = database.GetCollection<BsonDocument>("HomepageSections");
var sectionCount = await sectionsCollection.CountDocumentsAsync(new BsonDocument());
if (sectionCount == 0)
{
var sampleSections = new[]
{
new BsonDocument
{
{ "SectionType", "hero" },
{ "Title", "Welcome to Sky Art Shop" },
{ "Subtitle", "Your One-Stop Shop for Creative Supplies" },
{ "Content", "Discover beautiful scrapbooking, journaling, and crafting materials" },
{ "ImageUrl", "/uploads/images/8ba675b9-c4e6-41e6-8f14-382b9ee1d019.jpg" },
{ "ButtonText", "Shop Now" },
{ "ButtonUrl", "/Shop" },
{ "DisplayOrder", 1 },
{ "IsActive", true },
{ "CreatedAt", DateTime.UtcNow },
{ "UpdatedAt", DateTime.UtcNow }
},
new BsonDocument
{
{ "SectionType", "collection" },
{ "Title", "Featured Collections" },
{ "Subtitle", "Explore Our Curated Collections" },
{ "Content", "Hand-picked items for your creative projects" },
{ "ImageUrl", "" },
{ "ButtonText", "View All" },
{ "ButtonUrl", "/Shop" },
{ "DisplayOrder", 2 },
{ "IsActive", true },
{ "CreatedAt", DateTime.UtcNow },
{ "UpdatedAt", DateTime.UtcNow }
},
new BsonDocument
{
{ "SectionType", "promotion" },
{ "Title", "Special Offers" },
{ "Subtitle", "Don't Miss Our Latest Deals" },
{ "Content", "Save up to 30% on selected items" },
{ "ImageUrl", "/uploads/images/8ba675b9-c4e6-41e6-8f14-382b9ee1d019.jpg" },
{ "ButtonText", "Shop Sale" },
{ "ButtonUrl", "/Shop" },
{ "DisplayOrder", 3 },
{ "IsActive", true },
{ "CreatedAt", DateTime.UtcNow },
{ "UpdatedAt", DateTime.UtcNow }
}
};
await sectionsCollection.InsertManyAsync(sampleSections);
Console.WriteLine($" ✓ Added {sampleSections.Length} homepage sections");
}
else
{
Console.WriteLine($" ⚠ Homepage sections already exist ({sectionCount} sections found)");
}
// 3. Verify Site Settings
Console.WriteLine();
Console.WriteLine("[3/4] Checking site settings...");
var settingsCollection = database.GetCollection<BsonDocument>("SiteSettings");
var settingsCount = await settingsCollection.CountDocumentsAsync(new BsonDocument());
if (settingsCount == 0)
{
var siteSettings = new BsonDocument
{
{ "SiteName", "Sky Art Shop" },
{ "SiteTagline", "Scrapbooking, Journaling & Crafting Supplies" },
{ "ContactEmail", "info@skyartshop.com" },
{ "ContactPhone", "+501 608-0409" },
{ "InstagramUrl", "https://instagram.com/skyartshop" },
{ "FooterText", "© 2025 by Sky Art Shop. All rights reserved." },
{ "UpdatedAt", DateTime.UtcNow }
};
await settingsCollection.InsertOneAsync(siteSettings);
Console.WriteLine(" ✓ Added site settings");
}
else
{
Console.WriteLine($" ✓ Site settings exist");
}
// 4. Verify Menu Items
Console.WriteLine();
Console.WriteLine("[4/4] Checking navigation menu...");
var menuCollection = database.GetCollection<BsonDocument>("MenuItems");
var menuCount = await menuCollection.CountDocumentsAsync(new BsonDocument());
Console.WriteLine($" ✓ {menuCount} menu items found");
// Summary
Console.WriteLine();
Console.WriteLine("========================================");
Console.WriteLine("✓ Database Initialization Complete!");
Console.WriteLine("========================================");
Console.WriteLine();
var finalProductCount = await productsCollection.CountDocumentsAsync(new BsonDocument());
var finalSectionCount = await sectionsCollection.CountDocumentsAsync(new BsonDocument());
Console.WriteLine($"Products: {finalProductCount}");
Console.WriteLine($"Homepage Sections: {finalSectionCount}");
Console.WriteLine($"Menu Items: {menuCount}");
Console.WriteLine($"Site Settings: {settingsCount}");
Console.WriteLine();
Console.WriteLine("Website should now display properly!");
Console.WriteLine();
}
catch (Exception ex)
{
Console.WriteLine($"✗ Error: {ex.Message}");
Console.WriteLine(ex.StackTrace);
Environment.Exit(1);
}