38442-vm/backend/src/db/seeders/20231127130745-sample-data.js
2026-02-15 09:42:36 +00:00

2340 lines
42 KiB
JavaScript

const db = require('../models');
const Users = db.users;
const Categories = db.categories;
const Products = db.products;
const Tags = db.tags;
const ProductReviews = db.product_reviews;
const ProductAttributes = db.product_attributes;
const ProductVariants = db.product_variants;
const VariantAttributeValues = db.variant_attribute_values;
const CategoriesData = [
{
"name": "Elektronika",
"slug": "elektronika",
"description": "Sprzet elektroniczny do domu i biura.",
// type code here for "images" field
"is_active": true,
"sort_order": 10,
// type code here for "relation_one" field
},
{
"name": "Komputery i laptopy",
"slug": "komputery-i-laptopy",
"description": "Laptopy, komputery stacjonarne oraz akcesoria.",
// type code here for "images" field
"is_active": true,
"sort_order": 20,
// type code here for "relation_one" field
},
{
"name": "Smartfony",
"slug": "smartfony",
"description": "Telefony, etui i akcesoria mobilne.",
// type code here for "images" field
"is_active": true,
"sort_order": 30,
// type code here for "relation_one" field
},
{
"name": "Dom i kuchnia",
"slug": "dom-i-kuchnia",
"description": "Wyposazenie domu, kuchni i sprzatania.",
// type code here for "images" field
"is_active": true,
"sort_order": 40,
// type code here for "relation_one" field
},
];
const ProductsData = [
{
"name": "Laptop NovaBook 14",
"slug": "laptop-novabook-14",
"short_description": "Lekki laptop do pracy i nauki.",
"description": "Wydajny laptop 14 cali z szybkim dyskiem SSD i dlugim czasem pracy na baterii.",
"sku": "NB14-2026",
"price": 3299.99,
"compare_at_price": 3599.99,
"stock_quantity": 18,
"status": "draft",
"is_featured": true,
"published_at": new Date('2026-01-20T10:00:00Z'),
// type code here for "images" field
// type code here for "relation_one" field
// type code here for "relation_many" field
// type code here for "relation_many" field
},
{
"name": "Smartfon PixelWave X",
"slug": "smartfon-pixelwave-x",
"short_description": "Szybki smartfon z dobrym aparatem.",
"description": "Smartfon z ekranem OLED, aparatem 50 MP i szybkim ladowaniem.",
"sku": "PWX-128",
"price": 2499.0,
"compare_at_price": 2699.0,
"stock_quantity": 42,
"status": "archived",
"is_featured": true,
"published_at": new Date('2026-01-28T09:00:00Z'),
// type code here for "images" field
// type code here for "relation_one" field
// type code here for "relation_many" field
// type code here for "relation_many" field
},
{
"name": "Blender KitchenPro 900",
"slug": "blender-kitchenpro-900",
"short_description": "Mocny blender do koktajli i zup.",
"description": "Blender o mocy 900 W z kilkoma trybami pracy i ostrzami ze stali nierdzewnej.",
"sku": "KP-BL900",
"price": 329.9,
"compare_at_price": 399.9,
"stock_quantity": 65,
"status": "active",
"is_featured": false,
"published_at": new Date('2026-02-02T11:30:00Z'),
// type code here for "images" field
// type code here for "relation_one" field
// type code here for "relation_many" field
// type code here for "relation_many" field
},
{
"name": "Mata do cwiczen FlexMat",
"slug": "mata-do-cwiczen-flexmat",
"short_description": "Antyposlizgowa mata treningowa.",
"description": "Mata o grubszej strukturze, idealna do jogi i treningu domowego.",
"sku": "FM-6MM",
"price": 99.99,
"compare_at_price": 119.99,
"stock_quantity": 120,
"status": "archived",
"is_featured": true,
"published_at": new Date('2026-02-05T08:15:00Z'),
// type code here for "images" field
// type code here for "relation_one" field
// type code here for "relation_many" field
// type code here for "relation_many" field
},
];
const TagsData = [
{
"name": "Bestseller",
"slug": "bestseller",
},
{
"name": "Nowosc",
"slug": "nowosc",
},
{
"name": "Promocja",
"slug": "promocja",
},
{
"name": "Premium",
"slug": "premium",
},
];
const ProductReviewsData = [
{
// type code here for "relation_one" field
// type code here for "relation_one" field
"rating": 5,
"title": "Bardzo dobry laptop",
"content": "Lekki, szybki i cichy. Idealny do pracy zdalnej.",
"status": "pending",
"submitted_at": new Date('2026-02-03T14:20:00Z'),
"moderated_at": new Date('2026-02-03T16:00:00Z'),
},
{
// type code here for "relation_one" field
// type code here for "relation_one" field
"rating": 4,
"title": "Swietny aparat",
"content": "Zdjecia wychodza bardzo dobrze, bateria moglaby byc lepsza.",
"status": "published",
"submitted_at": new Date('2026-02-06T10:05:00Z'),
"moderated_at": new Date('2026-02-06T12:30:00Z'),
},
{
// type code here for "relation_one" field
// type code here for "relation_one" field
"rating": 5,
"title": "Mocny i latwy w czyszczeniu",
"content": "Radzi sobie nawet z orzechami. Polecam.",
"status": "published",
"submitted_at": new Date('2026-02-08T18:10:00Z'),
"moderated_at": new Date('2026-02-08T19:00:00Z'),
},
{
// type code here for "relation_one" field
// type code here for "relation_one" field
"rating": 3,
"title": "OK, ale moglaby byc grubsza",
"content": "Nie slizga sie, ale na twardej podlodze czuc nacisk.",
"status": "pending",
"submitted_at": new Date('2026-02-09T07:55:00Z'),
"moderated_at": new Date('2026-02-09T08:05:00Z'),
},
];
const ProductAttributesData = [
{
"name": "Kolor",
"value_type": "text",
"is_filterable": true,
"sort_order": 10,
},
{
"name": "Rozmiar",
"value_type": "number",
"is_filterable": true,
"sort_order": 20,
},
{
"name": "Pojemnosc",
"value_type": "number",
"is_filterable": true,
"sort_order": 30,
},
{
"name": "Material",
"value_type": "select",
"is_filterable": true,
"sort_order": 40,
},
];
const ProductVariantsData = [
{
// type code here for "relation_one" field
"name": "NovaBook 14 16GB 512GB",
"sku": "NB14-16-512",
"price": 3299.99,
"stock_quantity": 10,
"is_default": true,
// type code here for "images" field
// type code here for "relation_many" field
},
{
// type code here for "relation_one" field
"name": "NovaBook 14 32GB 1TB",
"sku": "NB14-32-1TB",
"price": 3899.99,
"stock_quantity": 8,
"is_default": false,
// type code here for "images" field
// type code here for "relation_many" field
},
{
// type code here for "relation_one" field
"name": "PixelWave X 64GB",
"sku": "PWX-64",
"price": 2399.0,
"stock_quantity": 20,
"is_default": false,
// type code here for "images" field
// type code here for "relation_many" field
},
{
// type code here for "relation_one" field
"name": "PixelWave X 128GB",
"sku": "PWX-128",
"price": 2499.0,
"stock_quantity": 22,
"is_default": true,
// type code here for "images" field
// type code here for "relation_many" field
},
];
const VariantAttributeValuesData = [
{
// type code here for "relation_one" field
"value_text": "Czarny",
"value_number": 0,
"value_boolean": true,
},
{
// type code here for "relation_one" field
"value_text": "Bialy",
"value_number": 0,
"value_boolean": false,
},
{
// type code here for "relation_one" field
"value_text": "M",
"value_number": 0,
"value_boolean": true,
},
{
// type code here for "relation_one" field
"value_text": "64 GB",
"value_number": 64,
"value_boolean": true,
},
];
// Similar logic for "relation_many"
async function associateCategoryWithParent_category() {
const relatedParent_category0 = await Categories.findOne({
offset: Math.floor(Math.random() * (await Categories.count())),
});
const Category0 = await Categories.findOne({
order: [['id', 'ASC']],
offset: 0
});
if (Category0?.setParent_category)
{
await
Category0.
setParent_category(relatedParent_category0);
}
const relatedParent_category1 = await Categories.findOne({
offset: Math.floor(Math.random() * (await Categories.count())),
});
const Category1 = await Categories.findOne({
order: [['id', 'ASC']],
offset: 1
});
if (Category1?.setParent_category)
{
await
Category1.
setParent_category(relatedParent_category1);
}
const relatedParent_category2 = await Categories.findOne({
offset: Math.floor(Math.random() * (await Categories.count())),
});
const Category2 = await Categories.findOne({
order: [['id', 'ASC']],
offset: 2
});
if (Category2?.setParent_category)
{
await
Category2.
setParent_category(relatedParent_category2);
}
const relatedParent_category3 = await Categories.findOne({
offset: Math.floor(Math.random() * (await Categories.count())),
});
const Category3 = await Categories.findOne({
order: [['id', 'ASC']],
offset: 3
});
if (Category3?.setParent_category)
{
await
Category3.
setParent_category(relatedParent_category3);
}
}
async function associateProductWithPrimary_category() {
const relatedPrimary_category0 = await Categories.findOne({
offset: Math.floor(Math.random() * (await Categories.count())),
});
const Product0 = await Products.findOne({
order: [['id', 'ASC']],
offset: 0
});
if (Product0?.setPrimary_category)
{
await
Product0.
setPrimary_category(relatedPrimary_category0);
}
const relatedPrimary_category1 = await Categories.findOne({
offset: Math.floor(Math.random() * (await Categories.count())),
});
const Product1 = await Products.findOne({
order: [['id', 'ASC']],
offset: 1
});
if (Product1?.setPrimary_category)
{
await
Product1.
setPrimary_category(relatedPrimary_category1);
}
const relatedPrimary_category2 = await Categories.findOne({
offset: Math.floor(Math.random() * (await Categories.count())),
});
const Product2 = await Products.findOne({
order: [['id', 'ASC']],
offset: 2
});
if (Product2?.setPrimary_category)
{
await
Product2.
setPrimary_category(relatedPrimary_category2);
}
const relatedPrimary_category3 = await Categories.findOne({
offset: Math.floor(Math.random() * (await Categories.count())),
});
const Product3 = await Products.findOne({
order: [['id', 'ASC']],
offset: 3
});
if (Product3?.setPrimary_category)
{
await
Product3.
setPrimary_category(relatedPrimary_category3);
}
}
// Similar logic for "relation_many"
// Similar logic for "relation_many"
async function associateProductReviewWithProduct() {
const relatedProduct0 = await Products.findOne({
offset: Math.floor(Math.random() * (await Products.count())),
});
const ProductReview0 = await ProductReviews.findOne({
order: [['id', 'ASC']],
offset: 0
});
if (ProductReview0?.setProduct)
{
await
ProductReview0.
setProduct(relatedProduct0);
}
const relatedProduct1 = await Products.findOne({
offset: Math.floor(Math.random() * (await Products.count())),
});
const ProductReview1 = await ProductReviews.findOne({
order: [['id', 'ASC']],
offset: 1
});
if (ProductReview1?.setProduct)
{
await
ProductReview1.
setProduct(relatedProduct1);
}
const relatedProduct2 = await Products.findOne({
offset: Math.floor(Math.random() * (await Products.count())),
});
const ProductReview2 = await ProductReviews.findOne({
order: [['id', 'ASC']],
offset: 2
});
if (ProductReview2?.setProduct)
{
await
ProductReview2.
setProduct(relatedProduct2);
}
const relatedProduct3 = await Products.findOne({
offset: Math.floor(Math.random() * (await Products.count())),
});
const ProductReview3 = await ProductReviews.findOne({
order: [['id', 'ASC']],
offset: 3
});
if (ProductReview3?.setProduct)
{
await
ProductReview3.
setProduct(relatedProduct3);
}
}
async function associateProductReviewWithUser() {
const relatedUser0 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const ProductReview0 = await ProductReviews.findOne({
order: [['id', 'ASC']],
offset: 0
});
if (ProductReview0?.setUser)
{
await
ProductReview0.
setUser(relatedUser0);
}
const relatedUser1 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const ProductReview1 = await ProductReviews.findOne({
order: [['id', 'ASC']],
offset: 1
});
if (ProductReview1?.setUser)
{
await
ProductReview1.
setUser(relatedUser1);
}
const relatedUser2 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const ProductReview2 = await ProductReviews.findOne({
order: [['id', 'ASC']],
offset: 2
});
if (ProductReview2?.setUser)
{
await
ProductReview2.
setUser(relatedUser2);
}
const relatedUser3 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const ProductReview3 = await ProductReviews.findOne({
order: [['id', 'ASC']],
offset: 3
});
if (ProductReview3?.setUser)
{
await
ProductReview3.
setUser(relatedUser3);
}
}
async function associateProductVariantWithProduct() {
const relatedProduct0 = await Products.findOne({
offset: Math.floor(Math.random() * (await Products.count())),
});
const ProductVariant0 = await ProductVariants.findOne({
order: [['id', 'ASC']],
offset: 0
});
if (ProductVariant0?.setProduct)
{
await
ProductVariant0.
setProduct(relatedProduct0);
}
const relatedProduct1 = await Products.findOne({
offset: Math.floor(Math.random() * (await Products.count())),
});
const ProductVariant1 = await ProductVariants.findOne({
order: [['id', 'ASC']],
offset: 1
});
if (ProductVariant1?.setProduct)
{
await
ProductVariant1.
setProduct(relatedProduct1);
}
const relatedProduct2 = await Products.findOne({
offset: Math.floor(Math.random() * (await Products.count())),
});
const ProductVariant2 = await ProductVariants.findOne({
order: [['id', 'ASC']],
offset: 2
});
if (ProductVariant2?.setProduct)
{
await
ProductVariant2.
setProduct(relatedProduct2);
}
const relatedProduct3 = await Products.findOne({
offset: Math.floor(Math.random() * (await Products.count())),
});
const ProductVariant3 = await ProductVariants.findOne({
order: [['id', 'ASC']],
offset: 3
});
if (ProductVariant3?.setProduct)
{
await
ProductVariant3.
setProduct(relatedProduct3);
}
}
// Similar logic for "relation_many"
async function associateVariantAttributeValueWithAttribute() {
const relatedAttribute0 = await ProductAttributes.findOne({
offset: Math.floor(Math.random() * (await ProductAttributes.count())),
});
const VariantAttributeValue0 = await VariantAttributeValues.findOne({
order: [['id', 'ASC']],
offset: 0
});
if (VariantAttributeValue0?.setAttribute)
{
await
VariantAttributeValue0.
setAttribute(relatedAttribute0);
}
const relatedAttribute1 = await ProductAttributes.findOne({
offset: Math.floor(Math.random() * (await ProductAttributes.count())),
});
const VariantAttributeValue1 = await VariantAttributeValues.findOne({
order: [['id', 'ASC']],
offset: 1
});
if (VariantAttributeValue1?.setAttribute)
{
await
VariantAttributeValue1.
setAttribute(relatedAttribute1);
}
const relatedAttribute2 = await ProductAttributes.findOne({
offset: Math.floor(Math.random() * (await ProductAttributes.count())),
});
const VariantAttributeValue2 = await VariantAttributeValues.findOne({
order: [['id', 'ASC']],
offset: 2
});
if (VariantAttributeValue2?.setAttribute)
{
await
VariantAttributeValue2.
setAttribute(relatedAttribute2);
}
const relatedAttribute3 = await ProductAttributes.findOne({
offset: Math.floor(Math.random() * (await ProductAttributes.count())),
});
const VariantAttributeValue3 = await VariantAttributeValues.findOne({
order: [['id', 'ASC']],
offset: 3
});
if (VariantAttributeValue3?.setAttribute)
{
await
VariantAttributeValue3.
setAttribute(relatedAttribute3);
}
}
module.exports = {
up: async (queryInterface, Sequelize) => {
await Categories.bulkCreate(CategoriesData);
await Products.bulkCreate(ProductsData);
await Tags.bulkCreate(TagsData);
await ProductReviews.bulkCreate(ProductReviewsData);
await ProductAttributes.bulkCreate(ProductAttributesData);
await ProductVariants.bulkCreate(ProductVariantsData);
await VariantAttributeValues.bulkCreate(VariantAttributeValuesData);
await Promise.all([
// Similar logic for "relation_many"
await associateCategoryWithParent_category(),
await associateProductWithPrimary_category(),
// Similar logic for "relation_many"
// Similar logic for "relation_many"
await associateProductReviewWithProduct(),
await associateProductReviewWithUser(),
await associateProductVariantWithProduct(),
// Similar logic for "relation_many"
await associateVariantAttributeValueWithAttribute(),
]);
},
down: async (queryInterface, Sequelize) => {
await queryInterface.bulkDelete('categories', null, {});
await queryInterface.bulkDelete('products', null, {});
await queryInterface.bulkDelete('tags', null, {});
await queryInterface.bulkDelete('product_reviews', null, {});
await queryInterface.bulkDelete('product_attributes', null, {});
await queryInterface.bulkDelete('product_variants', null, {});
await queryInterface.bulkDelete('variant_attribute_values', null, {});
},
};