39545-vm/backend/src/db/seeders/20231127130745-sample-data.js
2026-04-10 19:12:46 +00:00

5809 lines
110 KiB
JavaScript

const db = require('../models');
const Users = db.users;
const Organizations = db.organizations;
const Stores = db.stores;
const Customers = db.customers;
const ProductCategories = db.product_categories;
const Products = db.products;
const DiscountCodes = db.discount_codes;
const Orders = db.orders;
const OrderItems = db.order_items;
const Payments = db.payments;
const Refunds = db.refunds;
const Shipments = db.shipments;
const ActivityLogs = db.activity_logs;
const OrganizationsData = [
{
"name": "Grace Hopper",
},
{
"name": "Grace Hopper",
},
{
"name": "Grace Hopper",
},
];
const StoresData = [
{
"name": "Marie Curie",
"code": "Marie Curie",
"timezone": "Alan Turing",
"currency_code": "Alan Turing",
"support_email": "Ada Lovelace",
"support_phone": "Alan Turing",
"address_line1": "Alan Turing",
"address_line2": "Alan Turing",
"city": "Ada Lovelace",
"state_region": "Marie Curie",
"postal_code": "Ada Lovelace",
"country_code": "Ada Lovelace",
"is_active": false,
// type code here for "relation_one" field
},
{
"name": "Marie Curie",
"code": "Marie Curie",
"timezone": "Ada Lovelace",
"currency_code": "Marie Curie",
"support_email": "Marie Curie",
"support_phone": "Ada Lovelace",
"address_line1": "Ada Lovelace",
"address_line2": "Ada Lovelace",
"city": "Marie Curie",
"state_region": "Marie Curie",
"postal_code": "Ada Lovelace",
"country_code": "Marie Curie",
"is_active": true,
// type code here for "relation_one" field
},
{
"name": "Ada Lovelace",
"code": "Ada Lovelace",
"timezone": "Alan Turing",
"currency_code": "Alan Turing",
"support_email": "Marie Curie",
"support_phone": "Grace Hopper",
"address_line1": "Ada Lovelace",
"address_line2": "Ada Lovelace",
"city": "Alan Turing",
"state_region": "Alan Turing",
"postal_code": "Grace Hopper",
"country_code": "Marie Curie",
"is_active": false,
// type code here for "relation_one" field
},
];
const CustomersData = [
{
// type code here for "relation_one" field
"email": "Grace Hopper",
"first_name": "Ada Lovelace",
"last_name": "Marie Curie",
"phone": "Marie Curie",
"registered_at": new Date(Date.now()),
"email_verified": true,
"notes": "Grace Hopper",
"billing_address_line1": "Grace Hopper",
"billing_address_line2": "Alan Turing",
"billing_city": "Marie Curie",
"billing_state_region": "Grace Hopper",
"billing_postal_code": "Grace Hopper",
"billing_country_code": "Ada Lovelace",
"shipping_address_line1": "Ada Lovelace",
"shipping_address_line2": "Marie Curie",
"shipping_city": "Marie Curie",
"shipping_state_region": "Alan Turing",
"shipping_postal_code": "Marie Curie",
"shipping_country_code": "Alan Turing",
// type code here for "relation_one" field
},
{
// type code here for "relation_one" field
"email": "Alan Turing",
"first_name": "Alan Turing",
"last_name": "Marie Curie",
"phone": "Marie Curie",
"registered_at": new Date(Date.now()),
"email_verified": true,
"notes": "Marie Curie",
"billing_address_line1": "Alan Turing",
"billing_address_line2": "Alan Turing",
"billing_city": "Ada Lovelace",
"billing_state_region": "Grace Hopper",
"billing_postal_code": "Ada Lovelace",
"billing_country_code": "Grace Hopper",
"shipping_address_line1": "Alan Turing",
"shipping_address_line2": "Ada Lovelace",
"shipping_city": "Marie Curie",
"shipping_state_region": "Alan Turing",
"shipping_postal_code": "Grace Hopper",
"shipping_country_code": "Ada Lovelace",
// type code here for "relation_one" field
},
{
// type code here for "relation_one" field
"email": "Grace Hopper",
"first_name": "Grace Hopper",
"last_name": "Grace Hopper",
"phone": "Marie Curie",
"registered_at": new Date(Date.now()),
"email_verified": true,
"notes": "Grace Hopper",
"billing_address_line1": "Alan Turing",
"billing_address_line2": "Marie Curie",
"billing_city": "Alan Turing",
"billing_state_region": "Alan Turing",
"billing_postal_code": "Ada Lovelace",
"billing_country_code": "Ada Lovelace",
"shipping_address_line1": "Marie Curie",
"shipping_address_line2": "Ada Lovelace",
"shipping_city": "Ada Lovelace",
"shipping_state_region": "Marie Curie",
"shipping_postal_code": "Ada Lovelace",
"shipping_country_code": "Grace Hopper",
// type code here for "relation_one" field
},
];
const ProductCategoriesData = [
{
// type code here for "relation_one" field
"name": "Grace Hopper",
"slug": "Marie Curie",
"description": "Grace Hopper",
"is_active": false,
// type code here for "relation_one" field
},
{
// type code here for "relation_one" field
"name": "Ada Lovelace",
"slug": "Alan Turing",
"description": "Ada Lovelace",
"is_active": true,
// type code here for "relation_one" field
},
{
// type code here for "relation_one" field
"name": "Grace Hopper",
"slug": "Grace Hopper",
"description": "Grace Hopper",
"is_active": false,
// type code here for "relation_one" field
},
];
const ProductsData = [
{
// type code here for "relation_one" field
// type code here for "relation_one" field
"name": "Alan Turing",
"sku": "Alan Turing",
"barcode": "Marie Curie",
"description": "Marie Curie",
// type code here for "images" field
"price": 5.9,
"compare_at_price": 6.5,
"cost": 6.42,
"stock_on_hand": 8,
"stock_reserved": 7,
"track_inventory": true,
"status": "active",
"weight": 7.73,
"weight_unit": "Ada Lovelace",
// type code here for "relation_one" field
},
{
// type code here for "relation_one" field
// type code here for "relation_one" field
"name": "Alan Turing",
"sku": "Grace Hopper",
"barcode": "Ada Lovelace",
"description": "Alan Turing",
// type code here for "images" field
"price": 0.29,
"compare_at_price": 1.41,
"cost": 2.12,
"stock_on_hand": 2,
"stock_reserved": 9,
"track_inventory": false,
"status": "active",
"weight": 3.78,
"weight_unit": "Ada Lovelace",
// type code here for "relation_one" field
},
{
// type code here for "relation_one" field
// type code here for "relation_one" field
"name": "Marie Curie",
"sku": "Alan Turing",
"barcode": "Alan Turing",
"description": "Ada Lovelace",
// type code here for "images" field
"price": 0.27,
"compare_at_price": 7.21,
"cost": 0.91,
"stock_on_hand": 1,
"stock_reserved": 6,
"track_inventory": true,
"status": "archived",
"weight": 5.96,
"weight_unit": "Alan Turing",
// type code here for "relation_one" field
},
];
const DiscountCodesData = [
{
// type code here for "relation_one" field
"code": "Grace Hopper",
"name": "Ada Lovelace",
"discount_type": "fixed_amount",
"value": 9.36,
"minimum_order_amount": 4.91,
"starts_at": new Date(Date.now()),
"ends_at": new Date(Date.now()),
"usage_limit": 7,
"usage_count": 3,
"is_active": false,
// type code here for "relation_one" field
},
{
// type code here for "relation_one" field
"code": "Grace Hopper",
"name": "Ada Lovelace",
"discount_type": "fixed_amount",
"value": 4.07,
"minimum_order_amount": 5.91,
"starts_at": new Date(Date.now()),
"ends_at": new Date(Date.now()),
"usage_limit": 4,
"usage_count": 8,
"is_active": true,
// type code here for "relation_one" field
},
{
// type code here for "relation_one" field
"code": "Grace Hopper",
"name": "Grace Hopper",
"discount_type": "fixed_amount",
"value": 1.99,
"minimum_order_amount": 3.68,
"starts_at": new Date(Date.now()),
"ends_at": new Date(Date.now()),
"usage_limit": 4,
"usage_count": 9,
"is_active": true,
// type code here for "relation_one" field
},
];
const OrdersData = [
{
// type code here for "relation_one" field
// type code here for "relation_one" field
// type code here for "relation_one" field
"order_number": "Alan Turing",
"status": "pending_payment",
"payment_status": "failed",
"fulfillment_status": "returned",
"placed_at": new Date(Date.now()),
"paid_at": new Date(Date.now()),
"packed_at": new Date(Date.now()),
"shipped_at": new Date(Date.now()),
"delivered_at": new Date(Date.now()),
"shipping_method": "Marie Curie",
"tracking_number": "Alan Turing",
"tracking_url": "Ada Lovelace",
"ship_to_name": "Grace Hopper",
"ship_to_phone": "Grace Hopper",
"ship_to_address_line1": "Grace Hopper",
"ship_to_address_line2": "Marie Curie",
"ship_to_city": "Grace Hopper",
"ship_to_state_region": "Ada Lovelace",
"ship_to_postal_code": "Alan Turing",
"ship_to_country_code": "Alan Turing",
"subtotal_amount": 3.08,
"discount_amount": 2.87,
"shipping_amount": 6.74,
"tax_amount": 4.61,
"total_amount": 3.48,
"currency_code": "Ada Lovelace",
"internal_notes": "Alan Turing",
// type code here for "relation_one" field
},
{
// type code here for "relation_one" field
// type code here for "relation_one" field
// type code here for "relation_one" field
"order_number": "Grace Hopper",
"status": "shipped",
"payment_status": "failed",
"fulfillment_status": "returned",
"placed_at": new Date(Date.now()),
"paid_at": new Date(Date.now()),
"packed_at": new Date(Date.now()),
"shipped_at": new Date(Date.now()),
"delivered_at": new Date(Date.now()),
"shipping_method": "Grace Hopper",
"tracking_number": "Grace Hopper",
"tracking_url": "Marie Curie",
"ship_to_name": "Grace Hopper",
"ship_to_phone": "Marie Curie",
"ship_to_address_line1": "Ada Lovelace",
"ship_to_address_line2": "Marie Curie",
"ship_to_city": "Grace Hopper",
"ship_to_state_region": "Grace Hopper",
"ship_to_postal_code": "Alan Turing",
"ship_to_country_code": "Alan Turing",
"subtotal_amount": 0.71,
"discount_amount": 8.36,
"shipping_amount": 7.61,
"tax_amount": 7.45,
"total_amount": 6.06,
"currency_code": "Grace Hopper",
"internal_notes": "Ada Lovelace",
// type code here for "relation_one" field
},
{
// type code here for "relation_one" field
// type code here for "relation_one" field
// type code here for "relation_one" field
"order_number": "Marie Curie",
"status": "paid",
"payment_status": "paid",
"fulfillment_status": "fulfilled",
"placed_at": new Date(Date.now()),
"paid_at": new Date(Date.now()),
"packed_at": new Date(Date.now()),
"shipped_at": new Date(Date.now()),
"delivered_at": new Date(Date.now()),
"shipping_method": "Ada Lovelace",
"tracking_number": "Ada Lovelace",
"tracking_url": "Ada Lovelace",
"ship_to_name": "Grace Hopper",
"ship_to_phone": "Ada Lovelace",
"ship_to_address_line1": "Marie Curie",
"ship_to_address_line2": "Marie Curie",
"ship_to_city": "Ada Lovelace",
"ship_to_state_region": "Ada Lovelace",
"ship_to_postal_code": "Marie Curie",
"ship_to_country_code": "Grace Hopper",
"subtotal_amount": 4.19,
"discount_amount": 5.99,
"shipping_amount": 3.57,
"tax_amount": 0.4,
"total_amount": 2.21,
"currency_code": "Grace Hopper",
"internal_notes": "Marie Curie",
// type code here for "relation_one" field
},
];
const OrderItemsData = [
{
// type code here for "relation_one" field
// type code here for "relation_one" field
"product_name_snapshot": "Ada Lovelace",
"sku_snapshot": "Marie Curie",
"unit_price": 9.3,
"quantity": 1,
"line_discount_amount": 5.84,
"line_tax_amount": 7.67,
"line_total_amount": 2.1,
"item_status": "backordered",
// type code here for "relation_one" field
},
{
// type code here for "relation_one" field
// type code here for "relation_one" field
"product_name_snapshot": "Alan Turing",
"sku_snapshot": "Ada Lovelace",
"unit_price": 2.32,
"quantity": 6,
"line_discount_amount": 8.44,
"line_tax_amount": 4.33,
"line_total_amount": 5.81,
"item_status": "backordered",
// type code here for "relation_one" field
},
{
// type code here for "relation_one" field
// type code here for "relation_one" field
"product_name_snapshot": "Marie Curie",
"sku_snapshot": "Ada Lovelace",
"unit_price": 9.16,
"quantity": 3,
"line_discount_amount": 5.31,
"line_tax_amount": 4.32,
"line_total_amount": 2.11,
"item_status": "backordered",
// type code here for "relation_one" field
},
];
const PaymentsData = [
{
// type code here for "relation_one" field
"provider": "Grace Hopper",
"provider_reference": "Ada Lovelace",
"method": "cash_on_delivery",
"status": "initiated",
"amount": 4.06,
"currency_code": "Grace Hopper",
"authorized_at": new Date(Date.now()),
"captured_at": new Date(Date.now()),
"refunded_at": new Date(Date.now()),
"failure_reason": "Ada Lovelace",
// type code here for "files" field
// type code here for "relation_one" field
},
{
// type code here for "relation_one" field
"provider": "Marie Curie",
"provider_reference": "Marie Curie",
"method": "card",
"status": "cancelled",
"amount": 0.89,
"currency_code": "Alan Turing",
"authorized_at": new Date(Date.now()),
"captured_at": new Date(Date.now()),
"refunded_at": new Date(Date.now()),
"failure_reason": "Grace Hopper",
// type code here for "files" field
// type code here for "relation_one" field
},
{
// type code here for "relation_one" field
"provider": "Grace Hopper",
"provider_reference": "Marie Curie",
"method": "other",
"status": "cancelled",
"amount": 7.12,
"currency_code": "Ada Lovelace",
"authorized_at": new Date(Date.now()),
"captured_at": new Date(Date.now()),
"refunded_at": new Date(Date.now()),
"failure_reason": "Alan Turing",
// type code here for "files" field
// type code here for "relation_one" field
},
];
const RefundsData = [
{
// type code here for "relation_one" field
"amount": 8.08,
"currency_code": "Marie Curie",
"status": "cancelled",
"reason": "Grace Hopper",
"requested_at": new Date(Date.now()),
"processed_at": new Date(Date.now()),
"provider_reference": "Alan Turing",
// type code here for "relation_one" field
},
{
// type code here for "relation_one" field
"amount": 2.42,
"currency_code": "Grace Hopper",
"status": "processed",
"reason": "Alan Turing",
"requested_at": new Date(Date.now()),
"processed_at": new Date(Date.now()),
"provider_reference": "Alan Turing",
// type code here for "relation_one" field
},
{
// type code here for "relation_one" field
"amount": 5.96,
"currency_code": "Ada Lovelace",
"status": "requested",
"reason": "Marie Curie",
"requested_at": new Date(Date.now()),
"processed_at": new Date(Date.now()),
"provider_reference": "Ada Lovelace",
// type code here for "relation_one" field
},
];
const ShipmentsData = [
{
// type code here for "relation_one" field
"status": "ready",
"carrier": "Alan Turing",
"service_level": "Grace Hopper",
"tracking_number": "Alan Turing",
"tracking_url": "Marie Curie",
"shipped_at": new Date(Date.now()),
"delivered_at": new Date(Date.now()),
"shipping_cost": 3.92,
"label_url": "Ada Lovelace",
// type code here for "files" field
// type code here for "relation_one" field
},
{
// type code here for "relation_one" field
"status": "shipped",
"carrier": "Grace Hopper",
"service_level": "Marie Curie",
"tracking_number": "Grace Hopper",
"tracking_url": "Grace Hopper",
"shipped_at": new Date(Date.now()),
"delivered_at": new Date(Date.now()),
"shipping_cost": 5.66,
"label_url": "Alan Turing",
// type code here for "files" field
// type code here for "relation_one" field
},
{
// type code here for "relation_one" field
"status": "in_transit",
"carrier": "Marie Curie",
"service_level": "Grace Hopper",
"tracking_number": "Alan Turing",
"tracking_url": "Marie Curie",
"shipped_at": new Date(Date.now()),
"delivered_at": new Date(Date.now()),
"shipping_cost": 4.21,
"label_url": "Alan Turing",
// type code here for "files" field
// type code here for "relation_one" field
},
];
const ActivityLogsData = [
{
// type code here for "relation_one" field
// type code here for "relation_one" field
"entity_name": "Grace Hopper",
"entity_record_key": "Marie Curie",
"action": "create",
"message": "Grace Hopper",
"occurred_at": new Date(Date.now()),
"ip_address": "Ada Lovelace",
// type code here for "relation_one" field
},
{
// type code here for "relation_one" field
// type code here for "relation_one" field
"entity_name": "Marie Curie",
"entity_record_key": "Alan Turing",
"action": "export",
"message": "Ada Lovelace",
"occurred_at": new Date(Date.now()),
"ip_address": "Ada Lovelace",
// type code here for "relation_one" field
},
{
// type code here for "relation_one" field
// type code here for "relation_one" field
"entity_name": "Grace Hopper",
"entity_record_key": "Ada Lovelace",
"action": "status_change",
"message": "Ada Lovelace",
"occurred_at": new Date(Date.now()),
"ip_address": "Alan Turing",
// type code here for "relation_one" field
},
];
// Similar logic for "relation_many"
async function associateUserWithOrganization() {
const relatedOrganization0 = await Organizations.findOne({
offset: Math.floor(Math.random() * (await Organizations.count())),
});
const User0 = await Users.findOne({
order: [['id', 'ASC']],
offset: 0
});
if (User0?.setOrganization)
{
await
User0.
setOrganization(relatedOrganization0);
}
const relatedOrganization1 = await Organizations.findOne({
offset: Math.floor(Math.random() * (await Organizations.count())),
});
const User1 = await Users.findOne({
order: [['id', 'ASC']],
offset: 1
});
if (User1?.setOrganization)
{
await
User1.
setOrganization(relatedOrganization1);
}
const relatedOrganization2 = await Organizations.findOne({
offset: Math.floor(Math.random() * (await Organizations.count())),
});
const User2 = await Users.findOne({
order: [['id', 'ASC']],
offset: 2
});
if (User2?.setOrganization)
{
await
User2.
setOrganization(relatedOrganization2);
}
}
async function associateStoreWithOrganization() {
const relatedOrganization0 = await Organizations.findOne({
offset: Math.floor(Math.random() * (await Organizations.count())),
});
const Store0 = await Stores.findOne({
order: [['id', 'ASC']],
offset: 0
});
if (Store0?.setOrganization)
{
await
Store0.
setOrganization(relatedOrganization0);
}
const relatedOrganization1 = await Organizations.findOne({
offset: Math.floor(Math.random() * (await Organizations.count())),
});
const Store1 = await Stores.findOne({
order: [['id', 'ASC']],
offset: 1
});
if (Store1?.setOrganization)
{
await
Store1.
setOrganization(relatedOrganization1);
}
const relatedOrganization2 = await Organizations.findOne({
offset: Math.floor(Math.random() * (await Organizations.count())),
});
const Store2 = await Stores.findOne({
order: [['id', 'ASC']],
offset: 2
});
if (Store2?.setOrganization)
{
await
Store2.
setOrganization(relatedOrganization2);
}
}
async function associateCustomerWithStore() {
const relatedStore0 = await Stores.findOne({
offset: Math.floor(Math.random() * (await Stores.count())),
});
const Customer0 = await Customers.findOne({
order: [['id', 'ASC']],
offset: 0
});
if (Customer0?.setStore)
{
await
Customer0.
setStore(relatedStore0);
}
const relatedStore1 = await Stores.findOne({
offset: Math.floor(Math.random() * (await Stores.count())),
});
const Customer1 = await Customers.findOne({
order: [['id', 'ASC']],
offset: 1
});
if (Customer1?.setStore)
{
await
Customer1.
setStore(relatedStore1);
}
const relatedStore2 = await Stores.findOne({
offset: Math.floor(Math.random() * (await Stores.count())),
});
const Customer2 = await Customers.findOne({
order: [['id', 'ASC']],
offset: 2
});
if (Customer2?.setStore)
{
await
Customer2.
setStore(relatedStore2);
}
}
async function associateCustomerWithOrganization() {
const relatedOrganization0 = await Organizations.findOne({
offset: Math.floor(Math.random() * (await Organizations.count())),
});
const Customer0 = await Customers.findOne({
order: [['id', 'ASC']],
offset: 0
});
if (Customer0?.setOrganization)
{
await
Customer0.
setOrganization(relatedOrganization0);
}
const relatedOrganization1 = await Organizations.findOne({
offset: Math.floor(Math.random() * (await Organizations.count())),
});
const Customer1 = await Customers.findOne({
order: [['id', 'ASC']],
offset: 1
});
if (Customer1?.setOrganization)
{
await
Customer1.
setOrganization(relatedOrganization1);
}
const relatedOrganization2 = await Organizations.findOne({
offset: Math.floor(Math.random() * (await Organizations.count())),
});
const Customer2 = await Customers.findOne({
order: [['id', 'ASC']],
offset: 2
});
if (Customer2?.setOrganization)
{
await
Customer2.
setOrganization(relatedOrganization2);
}
}
async function associateProductCategoryWithStore() {
const relatedStore0 = await Stores.findOne({
offset: Math.floor(Math.random() * (await Stores.count())),
});
const ProductCategory0 = await ProductCategories.findOne({
order: [['id', 'ASC']],
offset: 0
});
if (ProductCategory0?.setStore)
{
await
ProductCategory0.
setStore(relatedStore0);
}
const relatedStore1 = await Stores.findOne({
offset: Math.floor(Math.random() * (await Stores.count())),
});
const ProductCategory1 = await ProductCategories.findOne({
order: [['id', 'ASC']],
offset: 1
});
if (ProductCategory1?.setStore)
{
await
ProductCategory1.
setStore(relatedStore1);
}
const relatedStore2 = await Stores.findOne({
offset: Math.floor(Math.random() * (await Stores.count())),
});
const ProductCategory2 = await ProductCategories.findOne({
order: [['id', 'ASC']],
offset: 2
});
if (ProductCategory2?.setStore)
{
await
ProductCategory2.
setStore(relatedStore2);
}
}
async function associateProductCategoryWithOrganization() {
const relatedOrganization0 = await Organizations.findOne({
offset: Math.floor(Math.random() * (await Organizations.count())),
});
const ProductCategory0 = await ProductCategories.findOne({
order: [['id', 'ASC']],
offset: 0
});
if (ProductCategory0?.setOrganization)
{
await
ProductCategory0.
setOrganization(relatedOrganization0);
}
const relatedOrganization1 = await Organizations.findOne({
offset: Math.floor(Math.random() * (await Organizations.count())),
});
const ProductCategory1 = await ProductCategories.findOne({
order: [['id', 'ASC']],
offset: 1
});
if (ProductCategory1?.setOrganization)
{
await
ProductCategory1.
setOrganization(relatedOrganization1);
}
const relatedOrganization2 = await Organizations.findOne({
offset: Math.floor(Math.random() * (await Organizations.count())),
});
const ProductCategory2 = await ProductCategories.findOne({
order: [['id', 'ASC']],
offset: 2
});
if (ProductCategory2?.setOrganization)
{
await
ProductCategory2.
setOrganization(relatedOrganization2);
}
}
async function associateProductWithStore() {
const relatedStore0 = await Stores.findOne({
offset: Math.floor(Math.random() * (await Stores.count())),
});
const Product0 = await Products.findOne({
order: [['id', 'ASC']],
offset: 0
});
if (Product0?.setStore)
{
await
Product0.
setStore(relatedStore0);
}
const relatedStore1 = await Stores.findOne({
offset: Math.floor(Math.random() * (await Stores.count())),
});
const Product1 = await Products.findOne({
order: [['id', 'ASC']],
offset: 1
});
if (Product1?.setStore)
{
await
Product1.
setStore(relatedStore1);
}
const relatedStore2 = await Stores.findOne({
offset: Math.floor(Math.random() * (await Stores.count())),
});
const Product2 = await Products.findOne({
order: [['id', 'ASC']],
offset: 2
});
if (Product2?.setStore)
{
await
Product2.
setStore(relatedStore2);
}
}
async function associateProductWithCategory() {
const relatedCategory0 = await ProductCategories.findOne({
offset: Math.floor(Math.random() * (await ProductCategories.count())),
});
const Product0 = await Products.findOne({
order: [['id', 'ASC']],
offset: 0
});
if (Product0?.setCategory)
{
await
Product0.
setCategory(relatedCategory0);
}
const relatedCategory1 = await ProductCategories.findOne({
offset: Math.floor(Math.random() * (await ProductCategories.count())),
});
const Product1 = await Products.findOne({
order: [['id', 'ASC']],
offset: 1
});
if (Product1?.setCategory)
{
await
Product1.
setCategory(relatedCategory1);
}
const relatedCategory2 = await ProductCategories.findOne({
offset: Math.floor(Math.random() * (await ProductCategories.count())),
});
const Product2 = await Products.findOne({
order: [['id', 'ASC']],
offset: 2
});
if (Product2?.setCategory)
{
await
Product2.
setCategory(relatedCategory2);
}
}
async function associateProductWithOrganization() {
const relatedOrganization0 = await Organizations.findOne({
offset: Math.floor(Math.random() * (await Organizations.count())),
});
const Product0 = await Products.findOne({
order: [['id', 'ASC']],
offset: 0
});
if (Product0?.setOrganization)
{
await
Product0.
setOrganization(relatedOrganization0);
}
const relatedOrganization1 = await Organizations.findOne({
offset: Math.floor(Math.random() * (await Organizations.count())),
});
const Product1 = await Products.findOne({
order: [['id', 'ASC']],
offset: 1
});
if (Product1?.setOrganization)
{
await
Product1.
setOrganization(relatedOrganization1);
}
const relatedOrganization2 = await Organizations.findOne({
offset: Math.floor(Math.random() * (await Organizations.count())),
});
const Product2 = await Products.findOne({
order: [['id', 'ASC']],
offset: 2
});
if (Product2?.setOrganization)
{
await
Product2.
setOrganization(relatedOrganization2);
}
}
async function associateDiscountCodeWithStore() {
const relatedStore0 = await Stores.findOne({
offset: Math.floor(Math.random() * (await Stores.count())),
});
const DiscountCode0 = await DiscountCodes.findOne({
order: [['id', 'ASC']],
offset: 0
});
if (DiscountCode0?.setStore)
{
await
DiscountCode0.
setStore(relatedStore0);
}
const relatedStore1 = await Stores.findOne({
offset: Math.floor(Math.random() * (await Stores.count())),
});
const DiscountCode1 = await DiscountCodes.findOne({
order: [['id', 'ASC']],
offset: 1
});
if (DiscountCode1?.setStore)
{
await
DiscountCode1.
setStore(relatedStore1);
}
const relatedStore2 = await Stores.findOne({
offset: Math.floor(Math.random() * (await Stores.count())),
});
const DiscountCode2 = await DiscountCodes.findOne({
order: [['id', 'ASC']],
offset: 2
});
if (DiscountCode2?.setStore)
{
await
DiscountCode2.
setStore(relatedStore2);
}
}
async function associateDiscountCodeWithOrganization() {
const relatedOrganization0 = await Organizations.findOne({
offset: Math.floor(Math.random() * (await Organizations.count())),
});
const DiscountCode0 = await DiscountCodes.findOne({
order: [['id', 'ASC']],
offset: 0
});
if (DiscountCode0?.setOrganization)
{
await
DiscountCode0.
setOrganization(relatedOrganization0);
}
const relatedOrganization1 = await Organizations.findOne({
offset: Math.floor(Math.random() * (await Organizations.count())),
});
const DiscountCode1 = await DiscountCodes.findOne({
order: [['id', 'ASC']],
offset: 1
});
if (DiscountCode1?.setOrganization)
{
await
DiscountCode1.
setOrganization(relatedOrganization1);
}
const relatedOrganization2 = await Organizations.findOne({
offset: Math.floor(Math.random() * (await Organizations.count())),
});
const DiscountCode2 = await DiscountCodes.findOne({
order: [['id', 'ASC']],
offset: 2
});
if (DiscountCode2?.setOrganization)
{
await
DiscountCode2.
setOrganization(relatedOrganization2);
}
}
async function associateOrderWithStore() {
const relatedStore0 = await Stores.findOne({
offset: Math.floor(Math.random() * (await Stores.count())),
});
const Order0 = await Orders.findOne({
order: [['id', 'ASC']],
offset: 0
});
if (Order0?.setStore)
{
await
Order0.
setStore(relatedStore0);
}
const relatedStore1 = await Stores.findOne({
offset: Math.floor(Math.random() * (await Stores.count())),
});
const Order1 = await Orders.findOne({
order: [['id', 'ASC']],
offset: 1
});
if (Order1?.setStore)
{
await
Order1.
setStore(relatedStore1);
}
const relatedStore2 = await Stores.findOne({
offset: Math.floor(Math.random() * (await Stores.count())),
});
const Order2 = await Orders.findOne({
order: [['id', 'ASC']],
offset: 2
});
if (Order2?.setStore)
{
await
Order2.
setStore(relatedStore2);
}
}
async function associateOrderWithCustomer() {
const relatedCustomer0 = await Customers.findOne({
offset: Math.floor(Math.random() * (await Customers.count())),
});
const Order0 = await Orders.findOne({
order: [['id', 'ASC']],
offset: 0
});
if (Order0?.setCustomer)
{
await
Order0.
setCustomer(relatedCustomer0);
}
const relatedCustomer1 = await Customers.findOne({
offset: Math.floor(Math.random() * (await Customers.count())),
});
const Order1 = await Orders.findOne({
order: [['id', 'ASC']],
offset: 1
});
if (Order1?.setCustomer)
{
await
Order1.
setCustomer(relatedCustomer1);
}
const relatedCustomer2 = await Customers.findOne({
offset: Math.floor(Math.random() * (await Customers.count())),
});
const Order2 = await Orders.findOne({
order: [['id', 'ASC']],
offset: 2
});
if (Order2?.setCustomer)
{
await
Order2.
setCustomer(relatedCustomer2);
}
}
async function associateOrderWithDiscount_code() {
const relatedDiscount_code0 = await DiscountCodes.findOne({
offset: Math.floor(Math.random() * (await DiscountCodes.count())),
});
const Order0 = await Orders.findOne({
order: [['id', 'ASC']],
offset: 0
});
if (Order0?.setDiscount_code)
{
await
Order0.
setDiscount_code(relatedDiscount_code0);
}
const relatedDiscount_code1 = await DiscountCodes.findOne({
offset: Math.floor(Math.random() * (await DiscountCodes.count())),
});
const Order1 = await Orders.findOne({
order: [['id', 'ASC']],
offset: 1
});
if (Order1?.setDiscount_code)
{
await
Order1.
setDiscount_code(relatedDiscount_code1);
}
const relatedDiscount_code2 = await DiscountCodes.findOne({
offset: Math.floor(Math.random() * (await DiscountCodes.count())),
});
const Order2 = await Orders.findOne({
order: [['id', 'ASC']],
offset: 2
});
if (Order2?.setDiscount_code)
{
await
Order2.
setDiscount_code(relatedDiscount_code2);
}
}
async function associateOrderWithOrganization() {
const relatedOrganization0 = await Organizations.findOne({
offset: Math.floor(Math.random() * (await Organizations.count())),
});
const Order0 = await Orders.findOne({
order: [['id', 'ASC']],
offset: 0
});
if (Order0?.setOrganization)
{
await
Order0.
setOrganization(relatedOrganization0);
}
const relatedOrganization1 = await Organizations.findOne({
offset: Math.floor(Math.random() * (await Organizations.count())),
});
const Order1 = await Orders.findOne({
order: [['id', 'ASC']],
offset: 1
});
if (Order1?.setOrganization)
{
await
Order1.
setOrganization(relatedOrganization1);
}
const relatedOrganization2 = await Organizations.findOne({
offset: Math.floor(Math.random() * (await Organizations.count())),
});
const Order2 = await Orders.findOne({
order: [['id', 'ASC']],
offset: 2
});
if (Order2?.setOrganization)
{
await
Order2.
setOrganization(relatedOrganization2);
}
}
async function associateOrderItemWithOrder() {
const relatedOrder0 = await Orders.findOne({
offset: Math.floor(Math.random() * (await Orders.count())),
});
const OrderItem0 = await OrderItems.findOne({
order: [['id', 'ASC']],
offset: 0
});
if (OrderItem0?.setOrder)
{
await
OrderItem0.
setOrder(relatedOrder0);
}
const relatedOrder1 = await Orders.findOne({
offset: Math.floor(Math.random() * (await Orders.count())),
});
const OrderItem1 = await OrderItems.findOne({
order: [['id', 'ASC']],
offset: 1
});
if (OrderItem1?.setOrder)
{
await
OrderItem1.
setOrder(relatedOrder1);
}
const relatedOrder2 = await Orders.findOne({
offset: Math.floor(Math.random() * (await Orders.count())),
});
const OrderItem2 = await OrderItems.findOne({
order: [['id', 'ASC']],
offset: 2
});
if (OrderItem2?.setOrder)
{
await
OrderItem2.
setOrder(relatedOrder2);
}
}
async function associateOrderItemWithProduct() {
const relatedProduct0 = await Products.findOne({
offset: Math.floor(Math.random() * (await Products.count())),
});
const OrderItem0 = await OrderItems.findOne({
order: [['id', 'ASC']],
offset: 0
});
if (OrderItem0?.setProduct)
{
await
OrderItem0.
setProduct(relatedProduct0);
}
const relatedProduct1 = await Products.findOne({
offset: Math.floor(Math.random() * (await Products.count())),
});
const OrderItem1 = await OrderItems.findOne({
order: [['id', 'ASC']],
offset: 1
});
if (OrderItem1?.setProduct)
{
await
OrderItem1.
setProduct(relatedProduct1);
}
const relatedProduct2 = await Products.findOne({
offset: Math.floor(Math.random() * (await Products.count())),
});
const OrderItem2 = await OrderItems.findOne({
order: [['id', 'ASC']],
offset: 2
});
if (OrderItem2?.setProduct)
{
await
OrderItem2.
setProduct(relatedProduct2);
}
}
async function associateOrderItemWithOrganization() {
const relatedOrganization0 = await Organizations.findOne({
offset: Math.floor(Math.random() * (await Organizations.count())),
});
const OrderItem0 = await OrderItems.findOne({
order: [['id', 'ASC']],
offset: 0
});
if (OrderItem0?.setOrganization)
{
await
OrderItem0.
setOrganization(relatedOrganization0);
}
const relatedOrganization1 = await Organizations.findOne({
offset: Math.floor(Math.random() * (await Organizations.count())),
});
const OrderItem1 = await OrderItems.findOne({
order: [['id', 'ASC']],
offset: 1
});
if (OrderItem1?.setOrganization)
{
await
OrderItem1.
setOrganization(relatedOrganization1);
}
const relatedOrganization2 = await Organizations.findOne({
offset: Math.floor(Math.random() * (await Organizations.count())),
});
const OrderItem2 = await OrderItems.findOne({
order: [['id', 'ASC']],
offset: 2
});
if (OrderItem2?.setOrganization)
{
await
OrderItem2.
setOrganization(relatedOrganization2);
}
}
async function associatePaymentWithOrder() {
const relatedOrder0 = await Orders.findOne({
offset: Math.floor(Math.random() * (await Orders.count())),
});
const Payment0 = await Payments.findOne({
order: [['id', 'ASC']],
offset: 0
});
if (Payment0?.setOrder)
{
await
Payment0.
setOrder(relatedOrder0);
}
const relatedOrder1 = await Orders.findOne({
offset: Math.floor(Math.random() * (await Orders.count())),
});
const Payment1 = await Payments.findOne({
order: [['id', 'ASC']],
offset: 1
});
if (Payment1?.setOrder)
{
await
Payment1.
setOrder(relatedOrder1);
}
const relatedOrder2 = await Orders.findOne({
offset: Math.floor(Math.random() * (await Orders.count())),
});
const Payment2 = await Payments.findOne({
order: [['id', 'ASC']],
offset: 2
});
if (Payment2?.setOrder)
{
await
Payment2.
setOrder(relatedOrder2);
}
}
async function associatePaymentWithOrganization() {
const relatedOrganization0 = await Organizations.findOne({
offset: Math.floor(Math.random() * (await Organizations.count())),
});
const Payment0 = await Payments.findOne({
order: [['id', 'ASC']],
offset: 0
});
if (Payment0?.setOrganization)
{
await
Payment0.
setOrganization(relatedOrganization0);
}
const relatedOrganization1 = await Organizations.findOne({
offset: Math.floor(Math.random() * (await Organizations.count())),
});
const Payment1 = await Payments.findOne({
order: [['id', 'ASC']],
offset: 1
});
if (Payment1?.setOrganization)
{
await
Payment1.
setOrganization(relatedOrganization1);
}
const relatedOrganization2 = await Organizations.findOne({
offset: Math.floor(Math.random() * (await Organizations.count())),
});
const Payment2 = await Payments.findOne({
order: [['id', 'ASC']],
offset: 2
});
if (Payment2?.setOrganization)
{
await
Payment2.
setOrganization(relatedOrganization2);
}
}
async function associateRefundWithPayment() {
const relatedPayment0 = await Payments.findOne({
offset: Math.floor(Math.random() * (await Payments.count())),
});
const Refund0 = await Refunds.findOne({
order: [['id', 'ASC']],
offset: 0
});
if (Refund0?.setPayment)
{
await
Refund0.
setPayment(relatedPayment0);
}
const relatedPayment1 = await Payments.findOne({
offset: Math.floor(Math.random() * (await Payments.count())),
});
const Refund1 = await Refunds.findOne({
order: [['id', 'ASC']],
offset: 1
});
if (Refund1?.setPayment)
{
await
Refund1.
setPayment(relatedPayment1);
}
const relatedPayment2 = await Payments.findOne({
offset: Math.floor(Math.random() * (await Payments.count())),
});
const Refund2 = await Refunds.findOne({
order: [['id', 'ASC']],
offset: 2
});
if (Refund2?.setPayment)
{
await
Refund2.
setPayment(relatedPayment2);
}
}
async function associateRefundWithOrganization() {
const relatedOrganization0 = await Organizations.findOne({
offset: Math.floor(Math.random() * (await Organizations.count())),
});
const Refund0 = await Refunds.findOne({
order: [['id', 'ASC']],
offset: 0
});
if (Refund0?.setOrganization)
{
await
Refund0.
setOrganization(relatedOrganization0);
}
const relatedOrganization1 = await Organizations.findOne({
offset: Math.floor(Math.random() * (await Organizations.count())),
});
const Refund1 = await Refunds.findOne({
order: [['id', 'ASC']],
offset: 1
});
if (Refund1?.setOrganization)
{
await
Refund1.
setOrganization(relatedOrganization1);
}
const relatedOrganization2 = await Organizations.findOne({
offset: Math.floor(Math.random() * (await Organizations.count())),
});
const Refund2 = await Refunds.findOne({
order: [['id', 'ASC']],
offset: 2
});
if (Refund2?.setOrganization)
{
await
Refund2.
setOrganization(relatedOrganization2);
}
}
async function associateShipmentWithOrder() {
const relatedOrder0 = await Orders.findOne({
offset: Math.floor(Math.random() * (await Orders.count())),
});
const Shipment0 = await Shipments.findOne({
order: [['id', 'ASC']],
offset: 0
});
if (Shipment0?.setOrder)
{
await
Shipment0.
setOrder(relatedOrder0);
}
const relatedOrder1 = await Orders.findOne({
offset: Math.floor(Math.random() * (await Orders.count())),
});
const Shipment1 = await Shipments.findOne({
order: [['id', 'ASC']],
offset: 1
});
if (Shipment1?.setOrder)
{
await
Shipment1.
setOrder(relatedOrder1);
}
const relatedOrder2 = await Orders.findOne({
offset: Math.floor(Math.random() * (await Orders.count())),
});
const Shipment2 = await Shipments.findOne({
order: [['id', 'ASC']],
offset: 2
});
if (Shipment2?.setOrder)
{
await
Shipment2.
setOrder(relatedOrder2);
}
}
async function associateShipmentWithOrganization() {
const relatedOrganization0 = await Organizations.findOne({
offset: Math.floor(Math.random() * (await Organizations.count())),
});
const Shipment0 = await Shipments.findOne({
order: [['id', 'ASC']],
offset: 0
});
if (Shipment0?.setOrganization)
{
await
Shipment0.
setOrganization(relatedOrganization0);
}
const relatedOrganization1 = await Organizations.findOne({
offset: Math.floor(Math.random() * (await Organizations.count())),
});
const Shipment1 = await Shipments.findOne({
order: [['id', 'ASC']],
offset: 1
});
if (Shipment1?.setOrganization)
{
await
Shipment1.
setOrganization(relatedOrganization1);
}
const relatedOrganization2 = await Organizations.findOne({
offset: Math.floor(Math.random() * (await Organizations.count())),
});
const Shipment2 = await Shipments.findOne({
order: [['id', 'ASC']],
offset: 2
});
if (Shipment2?.setOrganization)
{
await
Shipment2.
setOrganization(relatedOrganization2);
}
}
async function associateActivityLogWithStore() {
const relatedStore0 = await Stores.findOne({
offset: Math.floor(Math.random() * (await Stores.count())),
});
const ActivityLog0 = await ActivityLogs.findOne({
order: [['id', 'ASC']],
offset: 0
});
if (ActivityLog0?.setStore)
{
await
ActivityLog0.
setStore(relatedStore0);
}
const relatedStore1 = await Stores.findOne({
offset: Math.floor(Math.random() * (await Stores.count())),
});
const ActivityLog1 = await ActivityLogs.findOne({
order: [['id', 'ASC']],
offset: 1
});
if (ActivityLog1?.setStore)
{
await
ActivityLog1.
setStore(relatedStore1);
}
const relatedStore2 = await Stores.findOne({
offset: Math.floor(Math.random() * (await Stores.count())),
});
const ActivityLog2 = await ActivityLogs.findOne({
order: [['id', 'ASC']],
offset: 2
});
if (ActivityLog2?.setStore)
{
await
ActivityLog2.
setStore(relatedStore2);
}
}
async function associateActivityLogWithUser() {
const relatedUser0 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const ActivityLog0 = await ActivityLogs.findOne({
order: [['id', 'ASC']],
offset: 0
});
if (ActivityLog0?.setUser)
{
await
ActivityLog0.
setUser(relatedUser0);
}
const relatedUser1 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const ActivityLog1 = await ActivityLogs.findOne({
order: [['id', 'ASC']],
offset: 1
});
if (ActivityLog1?.setUser)
{
await
ActivityLog1.
setUser(relatedUser1);
}
const relatedUser2 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const ActivityLog2 = await ActivityLogs.findOne({
order: [['id', 'ASC']],
offset: 2
});
if (ActivityLog2?.setUser)
{
await
ActivityLog2.
setUser(relatedUser2);
}
}
async function associateActivityLogWithOrganization() {
const relatedOrganization0 = await Organizations.findOne({
offset: Math.floor(Math.random() * (await Organizations.count())),
});
const ActivityLog0 = await ActivityLogs.findOne({
order: [['id', 'ASC']],
offset: 0
});
if (ActivityLog0?.setOrganization)
{
await
ActivityLog0.
setOrganization(relatedOrganization0);
}
const relatedOrganization1 = await Organizations.findOne({
offset: Math.floor(Math.random() * (await Organizations.count())),
});
const ActivityLog1 = await ActivityLogs.findOne({
order: [['id', 'ASC']],
offset: 1
});
if (ActivityLog1?.setOrganization)
{
await
ActivityLog1.
setOrganization(relatedOrganization1);
}
const relatedOrganization2 = await Organizations.findOne({
offset: Math.floor(Math.random() * (await Organizations.count())),
});
const ActivityLog2 = await ActivityLogs.findOne({
order: [['id', 'ASC']],
offset: 2
});
if (ActivityLog2?.setOrganization)
{
await
ActivityLog2.
setOrganization(relatedOrganization2);
}
}
module.exports = {
up: async (queryInterface, Sequelize) => {
await Organizations.bulkCreate(OrganizationsData);
await Stores.bulkCreate(StoresData);
await Customers.bulkCreate(CustomersData);
await ProductCategories.bulkCreate(ProductCategoriesData);
await Products.bulkCreate(ProductsData);
await DiscountCodes.bulkCreate(DiscountCodesData);
await Orders.bulkCreate(OrdersData);
await OrderItems.bulkCreate(OrderItemsData);
await Payments.bulkCreate(PaymentsData);
await Refunds.bulkCreate(RefundsData);
await Shipments.bulkCreate(ShipmentsData);
await ActivityLogs.bulkCreate(ActivityLogsData);
await Promise.all([
// Similar logic for "relation_many"
await associateUserWithOrganization(),
await associateStoreWithOrganization(),
await associateCustomerWithStore(),
await associateCustomerWithOrganization(),
await associateProductCategoryWithStore(),
await associateProductCategoryWithOrganization(),
await associateProductWithStore(),
await associateProductWithCategory(),
await associateProductWithOrganization(),
await associateDiscountCodeWithStore(),
await associateDiscountCodeWithOrganization(),
await associateOrderWithStore(),
await associateOrderWithCustomer(),
await associateOrderWithDiscount_code(),
await associateOrderWithOrganization(),
await associateOrderItemWithOrder(),
await associateOrderItemWithProduct(),
await associateOrderItemWithOrganization(),
await associatePaymentWithOrder(),
await associatePaymentWithOrganization(),
await associateRefundWithPayment(),
await associateRefundWithOrganization(),
await associateShipmentWithOrder(),
await associateShipmentWithOrganization(),
await associateActivityLogWithStore(),
await associateActivityLogWithUser(),
await associateActivityLogWithOrganization(),
]);
},
down: async (queryInterface, Sequelize) => {
await queryInterface.bulkDelete('organizations', null, {});
await queryInterface.bulkDelete('stores', null, {});
await queryInterface.bulkDelete('customers', null, {});
await queryInterface.bulkDelete('product_categories', null, {});
await queryInterface.bulkDelete('products', null, {});
await queryInterface.bulkDelete('discount_codes', null, {});
await queryInterface.bulkDelete('orders', null, {});
await queryInterface.bulkDelete('order_items', null, {});
await queryInterface.bulkDelete('payments', null, {});
await queryInterface.bulkDelete('refunds', null, {});
await queryInterface.bulkDelete('shipments', null, {});
await queryInterface.bulkDelete('activity_logs', null, {});
},
};