update,
This commit is contained in:
45
tsc1877/task1/project/admin/db_seed_local/auth.js
Normal file
45
tsc1877/task1/project/admin/db_seed_local/auth.js
Normal file
@@ -0,0 +1,45 @@
|
||||
const { Sequelize, DataTypes } = require('sequelize');
|
||||
const bcrypt = require('bcrypt');
|
||||
|
||||
const sequelize = new Sequelize('app_db', 'db_user', 'db_user_pass', {
|
||||
host: 'mysql',
|
||||
port: 3306,
|
||||
dialect: 'mysql',
|
||||
});
|
||||
|
||||
const Auth = sequelize.define(
|
||||
'Auths',
|
||||
{
|
||||
uid: { type: DataTypes.INTEGER, primaryKey: true, autoIncrement: true, unique: true },
|
||||
username: { type: DataTypes.STRING, allowNull: false },
|
||||
password: { type: DataTypes.STRING, allowNull: false },
|
||||
},
|
||||
{ timestamps: false },
|
||||
);
|
||||
|
||||
async function hashPassword(plainTextPassword) {
|
||||
const saltRounds = 10;
|
||||
return await bcrypt.hash(plainTextPassword, saltRounds);
|
||||
}
|
||||
|
||||
(async () => {
|
||||
try {
|
||||
await sequelize.authenticate();
|
||||
console.log('Connection has been established successfully.');
|
||||
|
||||
// create table
|
||||
await sequelize.sync();
|
||||
|
||||
await Auth.destroy({ truncate: true, cascade: true, force: true });
|
||||
|
||||
let user_row, password;
|
||||
user_row = await Auth.create({ username: 'admin@vtkhmall.com', password: await hashPassword('nimda') });
|
||||
user_row = await Auth.create({ username: 'cust1@vtkhmall.com', password: await hashPassword('1tsuc') });
|
||||
user_row = await Auth.create({ username: 'cust2@vtkhmall.com', password: await hashPassword('2tsuc') });
|
||||
user_row = await Auth.create({ username: 'cust3@vtkhmall.com', password: await hashPassword('3tsuc') });
|
||||
|
||||
await sequelize.close();
|
||||
} catch (error) {
|
||||
console.error('Unable to connect to the database:', error);
|
||||
}
|
||||
})();
|
56
tsc1877/task1/project/admin/db_seed_local/categories.js
Normal file
56
tsc1877/task1/project/admin/db_seed_local/categories.js
Normal file
@@ -0,0 +1,56 @@
|
||||
const { Sequelize, DataTypes } = require('sequelize');
|
||||
|
||||
const sequelize = new Sequelize('app_db', 'db_user', 'db_user_pass', {
|
||||
host: 'mysql',
|
||||
port: 3306,
|
||||
dialect: 'mysql',
|
||||
});
|
||||
|
||||
const Category = sequelize.define(
|
||||
'Categories',
|
||||
{
|
||||
cid: { type: DataTypes.INTEGER, primaryKey: true, autoIncrement: true, unique: true },
|
||||
name: { type: DataTypes.STRING, allowNull: false },
|
||||
description: { type: DataTypes.STRING, allowNull: false },
|
||||
},
|
||||
{ timestamps: false },
|
||||
);
|
||||
|
||||
(async () => {
|
||||
try {
|
||||
await sequelize.authenticate();
|
||||
console.log('Connection has been established successfully.');
|
||||
|
||||
// create table
|
||||
await sequelize.sync();
|
||||
|
||||
await Category.destroy({ truncate: true, cascade: true, force: true });
|
||||
|
||||
let category;
|
||||
|
||||
category = await Category.create({ name: 'Bakery', description: 'Bread, pastries, cakes, cookies' });
|
||||
category = await Category.create({ name: 'Dairy', description: 'Milk, cheese, eggs, yogurt, butter' });
|
||||
category = await Category.create({
|
||||
name: 'Meat & Seafood',
|
||||
description: 'Raw meat products, poultry, fish, shellfish',
|
||||
});
|
||||
category = await Category.create({
|
||||
name: 'Deli Counter',
|
||||
description: 'Prepared foods such as sandwiches, salads, and cold cuts',
|
||||
});
|
||||
category = await Category.create({
|
||||
name: 'Frozen Foods',
|
||||
description: 'Ice cream, frozen meals, pizza, vegetables, berries',
|
||||
});
|
||||
category = await Category.create({
|
||||
name: 'Pantry Staples',
|
||||
description: 'Pasta, rice, sauces, oils, vinegar, spices, canned goods',
|
||||
});
|
||||
|
||||
const categories = await Category.findAll();
|
||||
|
||||
await sequelize.close();
|
||||
} catch (error) {
|
||||
console.error('Unable to connect to the database:', error);
|
||||
}
|
||||
})();
|
37
tsc1877/task1/project/admin/db_seed_local/helloworld.js
Normal file
37
tsc1877/task1/project/admin/db_seed_local/helloworld.js
Normal file
@@ -0,0 +1,37 @@
|
||||
const { Sequelize, DataTypes } = require('sequelize');
|
||||
|
||||
const sequelize = new Sequelize('app_db', 'db_user', 'db_user_pass', {
|
||||
host: 'mysql',
|
||||
port: 3306,
|
||||
dialect: 'mysql',
|
||||
});
|
||||
|
||||
const User = sequelize.define(
|
||||
'User',
|
||||
{
|
||||
id: { type: DataTypes.INTEGER, primaryKey: true, autoIncrement: true, unique: true },
|
||||
firstName: { type: DataTypes.STRING, allowNull: false },
|
||||
lastName: { type: DataTypes.STRING, allowNull: false },
|
||||
},
|
||||
{ timestamps: false },
|
||||
);
|
||||
|
||||
(async () => {
|
||||
try {
|
||||
await sequelize.authenticate();
|
||||
console.log('Connection has been established successfully.');
|
||||
|
||||
// create table
|
||||
await sequelize.sync();
|
||||
|
||||
let users = await User.findAll({ attributes: ['firstName'] });
|
||||
User.destroy({ truncate: true, cascade: true, force: true });
|
||||
|
||||
const user = await User.create({ firstName: 'John', lastName: 'Doe' });
|
||||
users = await User.findAll();
|
||||
|
||||
await sequelize.close();
|
||||
} catch (error) {
|
||||
console.error('Unable to connect to the database:', error);
|
||||
}
|
||||
})();
|
35
tsc1877/task1/project/admin/db_seed_local/products.js
Normal file
35
tsc1877/task1/project/admin/db_seed_local/products.js
Normal file
@@ -0,0 +1,35 @@
|
||||
const { Sequelize, DataTypes } = require('sequelize');
|
||||
|
||||
const sequelize = new Sequelize('app_db', 'db_user', 'db_user_pass', {
|
||||
host: 'mysql',
|
||||
port: 3306,
|
||||
dialect: 'mysql',
|
||||
});
|
||||
|
||||
const Product = sequelize.define(
|
||||
'Products',
|
||||
{
|
||||
pid: { type: DataTypes.INTEGER, primaryKey: true, autoIncrement: true, unique: true },
|
||||
cid: { type: DataTypes.INTEGER, allowNull: false },
|
||||
name: { type: DataTypes.STRING, allowNull: false },
|
||||
description: { type: DataTypes.STRING, allowNull: false },
|
||||
price: { type: DataTypes.DECIMAL, allowNull: false },
|
||||
product_image: { type: DataTypes.STRING, allowNull: true, defaultValue: '' },
|
||||
},
|
||||
{ timestamps: false },
|
||||
);
|
||||
|
||||
(async () => {
|
||||
try {
|
||||
await sequelize.authenticate();
|
||||
console.log('Connection has been established successfully.');
|
||||
|
||||
await Product.drop();
|
||||
|
||||
await sequelize.sync();
|
||||
|
||||
await sequelize.close();
|
||||
} catch (error) {
|
||||
console.error('Unable to connect to the database:', error);
|
||||
}
|
||||
})();
|
85
tsc1877/task1/project/admin/db_seed_local/products_cid_1.js
Normal file
85
tsc1877/task1/project/admin/db_seed_local/products_cid_1.js
Normal file
@@ -0,0 +1,85 @@
|
||||
const { Sequelize, DataTypes } = require('sequelize');
|
||||
|
||||
const sequelize = new Sequelize('app_db', 'db_user', 'db_user_pass', {
|
||||
host: 'mysql',
|
||||
port: 3306,
|
||||
dialect: 'mysql',
|
||||
});
|
||||
|
||||
const Product = sequelize.define(
|
||||
'Products',
|
||||
{
|
||||
pid: { type: DataTypes.INTEGER, primaryKey: true, autoIncrement: true, unique: true },
|
||||
cid: { type: DataTypes.INTEGER, allowNull: false },
|
||||
name: { type: DataTypes.STRING, allowNull: false },
|
||||
product_image: { type: DataTypes.STRING, allowNull: false },
|
||||
description: { type: DataTypes.STRING, allowNull: false },
|
||||
price: { type: DataTypes.FLOAT, allowNull: false },
|
||||
},
|
||||
{ timestamps: false },
|
||||
);
|
||||
|
||||
(async () => {
|
||||
try {
|
||||
await sequelize.authenticate();
|
||||
console.log('Connection has been established successfully.');
|
||||
|
||||
// create table
|
||||
await sequelize.sync();
|
||||
|
||||
let products = [
|
||||
{
|
||||
cid: 1,
|
||||
name: 'French Baguette',
|
||||
description: 'A long, crusty loaf of French bread with a soft interior.',
|
||||
price: 5.5,
|
||||
product_image: 'BREAD1',
|
||||
},
|
||||
{
|
||||
cid: 1,
|
||||
name: 'Whole Wheat Bread',
|
||||
description: 'A nutritious bread made with whole wheat flour and grains.',
|
||||
price: 6.5,
|
||||
product_image: 'BREAD2',
|
||||
},
|
||||
{
|
||||
cid: 1,
|
||||
name: 'Croissants',
|
||||
description: 'Buttery, flaky pastries often enjoyed with coffee or tea.',
|
||||
price: 8.5,
|
||||
product_image: 'BREAD3',
|
||||
},
|
||||
{
|
||||
cid: 1,
|
||||
name: 'Donuts',
|
||||
description: 'Sweet, fried pastries with a variety of toppings and fillings.',
|
||||
price: 4.95,
|
||||
product_image: 'BREAD4',
|
||||
},
|
||||
{
|
||||
cid: 1,
|
||||
name: 'Whole Wheat Bread',
|
||||
description: 'A nutritious bread made with whole wheat flour and grains.',
|
||||
price: 6.5,
|
||||
product_image: 'BREAD2',
|
||||
},
|
||||
{
|
||||
cid: 1,
|
||||
name: 'Croissants',
|
||||
description: 'Buttery, flaky pastries often enjoyed with coffee or tea.',
|
||||
price: 8.5,
|
||||
product_image: 'BREAD3',
|
||||
},
|
||||
];
|
||||
|
||||
for (var i = 0; i < products.length; i++) {
|
||||
await Product.create(products[i]);
|
||||
}
|
||||
|
||||
const categories = await Product.findAll();
|
||||
|
||||
await sequelize.close();
|
||||
} catch (error) {
|
||||
console.error('Unable to connect to the database:', error);
|
||||
}
|
||||
})();
|
71
tsc1877/task1/project/admin/db_seed_local/products_cid_2.js
Normal file
71
tsc1877/task1/project/admin/db_seed_local/products_cid_2.js
Normal file
@@ -0,0 +1,71 @@
|
||||
const { Sequelize, DataTypes } = require('sequelize');
|
||||
|
||||
const sequelize = new Sequelize('app_db', 'db_user', 'db_user_pass', {
|
||||
host: 'mysql',
|
||||
port: 3306,
|
||||
dialect: 'mysql',
|
||||
});
|
||||
|
||||
const Product = sequelize.define(
|
||||
'Products',
|
||||
{
|
||||
pid: { type: DataTypes.INTEGER, primaryKey: true, autoIncrement: true, unique: true },
|
||||
cid: { type: DataTypes.INTEGER, allowNull: false },
|
||||
name: { type: DataTypes.STRING, allowNull: false },
|
||||
description: { type: DataTypes.STRING, allowNull: false },
|
||||
price: { type: DataTypes.DECIMAL, allowNull: false },
|
||||
product_image: { type: DataTypes.STRING, allowNull: false },
|
||||
},
|
||||
{ timestamps: false },
|
||||
);
|
||||
|
||||
(async () => {
|
||||
try {
|
||||
await sequelize.authenticate();
|
||||
console.log('Connection has been established successfully.');
|
||||
|
||||
// create table
|
||||
await sequelize.sync();
|
||||
|
||||
let products = [
|
||||
{
|
||||
cid: 2,
|
||||
name: 'Milk',
|
||||
description: 'A nutritious beverage made from the milk of cows, goats, or other mammals.',
|
||||
price: 5.5,
|
||||
product_image: 'DAIRY_1',
|
||||
},
|
||||
{
|
||||
cid: 2,
|
||||
name: 'Cheese',
|
||||
description: 'A versatile dairy product made from milk, available in a variety of flavors and textures.',
|
||||
price: 6.5,
|
||||
product_image: 'DAIRY_2',
|
||||
},
|
||||
{
|
||||
cid: 2,
|
||||
name: 'Yogurt',
|
||||
description: 'A creamy, fermented dairy product that comes in many flavors and styles.',
|
||||
price: 8.5,
|
||||
product_image: 'DAIRY_3',
|
||||
},
|
||||
{
|
||||
cid: 2,
|
||||
name: 'Butter',
|
||||
description: 'A dairy product made by churning cream, used for cooking and baking.',
|
||||
price: 4.95,
|
||||
product_image: 'DAIRY_4',
|
||||
},
|
||||
];
|
||||
|
||||
for (var i = 0; i < products.length; i++) {
|
||||
await Product.create(products[i]);
|
||||
}
|
||||
|
||||
const categories = await Product.findAll();
|
||||
|
||||
await sequelize.close();
|
||||
} catch (error) {
|
||||
console.error('Unable to connect to the database:', error);
|
||||
}
|
||||
})();
|
71
tsc1877/task1/project/admin/db_seed_local/products_cid_3.js
Normal file
71
tsc1877/task1/project/admin/db_seed_local/products_cid_3.js
Normal file
@@ -0,0 +1,71 @@
|
||||
const { Sequelize, DataTypes } = require('sequelize');
|
||||
|
||||
const sequelize = new Sequelize('app_db', 'db_user', 'db_user_pass', {
|
||||
host: 'mysql',
|
||||
port: 3306,
|
||||
dialect: 'mysql',
|
||||
});
|
||||
|
||||
const Product = sequelize.define(
|
||||
'Products',
|
||||
{
|
||||
pid: { type: DataTypes.INTEGER, primaryKey: true, autoIncrement: true, unique: true },
|
||||
cid: { type: DataTypes.INTEGER, allowNull: false },
|
||||
name: { type: DataTypes.STRING, allowNull: false },
|
||||
description: { type: DataTypes.STRING, allowNull: false },
|
||||
price: { type: DataTypes.DECIMAL, allowNull: false },
|
||||
product_image: { type: DataTypes.STRING, allowNull: true, defaultValue: '' },
|
||||
},
|
||||
{ timestamps: false },
|
||||
);
|
||||
|
||||
(async () => {
|
||||
try {
|
||||
await sequelize.authenticate();
|
||||
console.log('Connection has been established successfully.');
|
||||
|
||||
// create table
|
||||
await sequelize.sync();
|
||||
|
||||
let products = [
|
||||
{
|
||||
cid: 3,
|
||||
name: 'Chicken',
|
||||
description: 'A versatile and popular type of poultry, available in many cuts and preparations.',
|
||||
price: 9.95,
|
||||
product_image: 'MEAT1',
|
||||
},
|
||||
{
|
||||
cid: 3,
|
||||
name: 'Beef',
|
||||
description: 'A type of red meat that comes from cows, available in a variety of cuts and grades.',
|
||||
price: 13.5,
|
||||
product_image: 'MEAT2',
|
||||
},
|
||||
{
|
||||
cid: 3,
|
||||
name: 'Pork',
|
||||
description: 'A type of meat that comes from pigs, available in many cuts and preparations.',
|
||||
price: 27.8,
|
||||
product_image: 'MEAT3',
|
||||
},
|
||||
{
|
||||
cid: 3,
|
||||
name: 'Lamb',
|
||||
description: 'A type of red meat that comes from sheep, available in many cuts and preparations.',
|
||||
price: 25.95,
|
||||
product_image: 'MEAT4',
|
||||
},
|
||||
];
|
||||
|
||||
for (var i = 0; i < products.length; i++) {
|
||||
await Product.create(products[i]);
|
||||
}
|
||||
|
||||
const categories = await Product.findAll();
|
||||
|
||||
await sequelize.close();
|
||||
} catch (error) {
|
||||
console.error('Unable to connect to the database:', error);
|
||||
}
|
||||
})();
|
71
tsc1877/task1/project/admin/db_seed_local/products_cid_4.js
Normal file
71
tsc1877/task1/project/admin/db_seed_local/products_cid_4.js
Normal file
@@ -0,0 +1,71 @@
|
||||
const { Sequelize, DataTypes } = require('sequelize');
|
||||
|
||||
const sequelize = new Sequelize('app_db', 'db_user', 'db_user_pass', {
|
||||
host: 'mysql',
|
||||
port: 3306,
|
||||
dialect: 'mysql',
|
||||
});
|
||||
|
||||
const Product = sequelize.define(
|
||||
'Products',
|
||||
{
|
||||
pid: { type: DataTypes.INTEGER, primaryKey: true, autoIncrement: true, unique: true },
|
||||
cid: { type: DataTypes.INTEGER, allowNull: false },
|
||||
name: { type: DataTypes.STRING, allowNull: false },
|
||||
description: { type: DataTypes.STRING, allowNull: false },
|
||||
price: { type: DataTypes.DECIMAL, allowNull: false },
|
||||
product_image: { type: DataTypes.STRING, allowNull: false },
|
||||
},
|
||||
{ timestamps: false },
|
||||
);
|
||||
|
||||
(async () => {
|
||||
try {
|
||||
await sequelize.authenticate();
|
||||
console.log('Connection has been established successfully.');
|
||||
|
||||
// create table
|
||||
await sequelize.sync();
|
||||
|
||||
let products = [
|
||||
{
|
||||
cid: 4,
|
||||
name: 'Sliced Meats',
|
||||
description: 'Deli meats such as ham, turkey, salami, and roast beef, sliced to order.',
|
||||
price: 6.95,
|
||||
product_image: 'DELI_1',
|
||||
},
|
||||
{
|
||||
cid: 4,
|
||||
name: 'Cheese',
|
||||
description: 'A variety of cheeses, such as cheddar, Swiss, and mozzarella, sliced to order.',
|
||||
price: 7.5,
|
||||
product_image: 'DELI_2',
|
||||
},
|
||||
{
|
||||
cid: 4,
|
||||
name: 'Prepared Salads',
|
||||
description: 'Salads such as pasta salad, potato salad, and coleslaw, made fresh in-store.',
|
||||
price: 8.5,
|
||||
product_image: 'DELI_3',
|
||||
},
|
||||
{
|
||||
cid: 4,
|
||||
name: 'Rotisserie Chicken',
|
||||
description: 'Whole chickens that have been seasoned and roasted in-store, ready to take home and serve.',
|
||||
price: 7.5,
|
||||
product_image: 'DELI_4',
|
||||
},
|
||||
];
|
||||
|
||||
for (var i = 0; i < products.length; i++) {
|
||||
await Product.create(products[i]);
|
||||
}
|
||||
|
||||
const categories = await Product.findAll();
|
||||
|
||||
await sequelize.close();
|
||||
} catch (error) {
|
||||
console.error('Unable to connect to the database:', error);
|
||||
}
|
||||
})();
|
74
tsc1877/task1/project/admin/db_seed_local/products_cid_5.js
Normal file
74
tsc1877/task1/project/admin/db_seed_local/products_cid_5.js
Normal file
@@ -0,0 +1,74 @@
|
||||
const { Sequelize, DataTypes } = require('sequelize');
|
||||
|
||||
const sequelize = new Sequelize('app_db', 'db_user', 'db_user_pass', {
|
||||
host: 'mysql',
|
||||
port: 3306,
|
||||
dialect: 'mysql',
|
||||
});
|
||||
|
||||
const Product = sequelize.define(
|
||||
'Products',
|
||||
{
|
||||
pid: { type: DataTypes.INTEGER, primaryKey: true, autoIncrement: true, unique: true },
|
||||
cid: { type: DataTypes.INTEGER, allowNull: false },
|
||||
name: { type: DataTypes.STRING, allowNull: false },
|
||||
product_image: { type: DataTypes.STRING, allowNull: false },
|
||||
description: { type: DataTypes.STRING, allowNull: false },
|
||||
price: { type: DataTypes.DECIMAL, allowNull: false },
|
||||
},
|
||||
{ timestamps: false },
|
||||
);
|
||||
|
||||
(async () => {
|
||||
try {
|
||||
await sequelize.authenticate();
|
||||
console.log('Connection has been established successfully.');
|
||||
|
||||
// create table
|
||||
await sequelize.sync();
|
||||
|
||||
let products = [
|
||||
{
|
||||
cid: 5,
|
||||
name: 'Frozen Vegetables',
|
||||
description: 'A variety of vegetables, such as peas, corn, and broccoli, frozen at peak freshness.',
|
||||
price: 5.5,
|
||||
product_image: 'FROZEN_1',
|
||||
},
|
||||
{
|
||||
cid: 5,
|
||||
name: 'Frozen Seafood',
|
||||
description: 'A variety of seafood, such as shrimp, fish, and scallops, frozen for freshness and convenience.',
|
||||
|
||||
price: 6.5,
|
||||
product_image: 'FROZEN_2',
|
||||
},
|
||||
{
|
||||
cid: 5,
|
||||
name: 'Frozen Meals',
|
||||
description: 'Pre-made meals such as pizza, lasagna, and stir-fry, available for quick and easy dinners.',
|
||||
|
||||
price: 8.5,
|
||||
product_image: 'FROZEN_3',
|
||||
},
|
||||
{
|
||||
cid: 5,
|
||||
name: 'Frozen Fruits',
|
||||
description: 'A variety of fruits, such as berries, mango, and pineapple, frozen at peak freshness.',
|
||||
|
||||
price: 4.95,
|
||||
product_image: 'FROZEN_4',
|
||||
},
|
||||
];
|
||||
|
||||
for (var i = 0; i < products.length; i++) {
|
||||
await Product.create(products[i]);
|
||||
}
|
||||
|
||||
const categories = await Product.findAll();
|
||||
|
||||
await sequelize.close();
|
||||
} catch (error) {
|
||||
console.error('Unable to connect to the database:', error);
|
||||
}
|
||||
})();
|
85
tsc1877/task1/project/admin/db_seed_local/products_cid_6.js
Normal file
85
tsc1877/task1/project/admin/db_seed_local/products_cid_6.js
Normal file
@@ -0,0 +1,85 @@
|
||||
const { Sequelize, DataTypes } = require('sequelize');
|
||||
|
||||
const sequelize = new Sequelize('app_db', 'db_user', 'db_user_pass', {
|
||||
host: 'mysql',
|
||||
port: 3306,
|
||||
dialect: 'mysql',
|
||||
});
|
||||
|
||||
const Product = sequelize.define(
|
||||
'Products',
|
||||
{
|
||||
pid: { type: DataTypes.INTEGER, primaryKey: true, autoIncrement: true, unique: true },
|
||||
cid: { type: DataTypes.INTEGER, allowNull: false },
|
||||
name: { type: DataTypes.STRING, allowNull: false },
|
||||
product_image: { type: DataTypes.STRING, allowNull: false },
|
||||
description: { type: DataTypes.STRING, allowNull: false },
|
||||
price: { type: DataTypes.DECIMAL, allowNull: false },
|
||||
},
|
||||
{ timestamps: false },
|
||||
);
|
||||
|
||||
(async () => {
|
||||
try {
|
||||
await sequelize.authenticate();
|
||||
console.log('Connection has been established successfully.');
|
||||
|
||||
// create table
|
||||
await sequelize.sync();
|
||||
|
||||
let products = [
|
||||
{
|
||||
cid: 6,
|
||||
name: 'Pasta',
|
||||
description: 'A variety of pasta shapes and types, such as spaghetti, macaroni, and lasagna noodles.',
|
||||
price: 5.5,
|
||||
product_image: 'PANTRY_1',
|
||||
},
|
||||
{
|
||||
cid: 6,
|
||||
name: 'Rice',
|
||||
description: 'A variety of rice types, such as white rice, brown rice, and jasmine rice.',
|
||||
price: 6.5,
|
||||
product_image: 'PANTRY_2',
|
||||
},
|
||||
{
|
||||
cid: 6,
|
||||
name: 'Canned Beans',
|
||||
description: 'A variety of beans, such as black beans, kidney beans, and chickpeas, canned for convenience.',
|
||||
price: 8.5,
|
||||
product_image: 'PANTRY_3',
|
||||
},
|
||||
{
|
||||
cid: 6,
|
||||
name: 'Canned Tomatoes',
|
||||
description: 'A variety of canned tomatoes, such as diced tomatoes, crushed tomatoes, and tomato sauce.',
|
||||
price: 4.95,
|
||||
product_image: 'PANTRY_4',
|
||||
},
|
||||
{
|
||||
cid: 6,
|
||||
name: 'Canned Beans',
|
||||
description: 'A variety of beans, such as black beans, kidney beans, and chickpeas, canned for convenience.',
|
||||
price: 8.5,
|
||||
product_image: 'PANTRY_3',
|
||||
},
|
||||
{
|
||||
cid: 6,
|
||||
name: 'Canned Tomatoes',
|
||||
description: 'A variety of canned tomatoes, such as diced tomatoes, crushed tomatoes, and tomato sauce.',
|
||||
price: 4.95,
|
||||
product_image: 'PANTRY_4',
|
||||
},
|
||||
];
|
||||
|
||||
for (var i = 0; i < products.length; i++) {
|
||||
await Product.create(products[i]);
|
||||
}
|
||||
|
||||
const categories = await Product.findAll();
|
||||
|
||||
await sequelize.close();
|
||||
} catch (error) {
|
||||
console.error('Unable to connect to the database:', error);
|
||||
}
|
||||
})();
|
77
tsc1877/task1/project/admin/db_seed_local/products_cid_7.js
Normal file
77
tsc1877/task1/project/admin/db_seed_local/products_cid_7.js
Normal file
@@ -0,0 +1,77 @@
|
||||
const { Sequelize, DataTypes } = require('sequelize');
|
||||
|
||||
const sequelize = new Sequelize('app_db', 'db_user', 'db_user_pass', {
|
||||
host: 'mysql',
|
||||
port: 3306,
|
||||
dialect: 'mysql',
|
||||
});
|
||||
|
||||
const Product = sequelize.define(
|
||||
'Products',
|
||||
{
|
||||
pid: { type: DataTypes.INTEGER, primaryKey: true, autoIncrement: true, unique: true },
|
||||
cid: { type: DataTypes.INTEGER, allowNull: false },
|
||||
name: { type: DataTypes.STRING, allowNull: false },
|
||||
description: { type: DataTypes.STRING, allowNull: false },
|
||||
price: { type: DataTypes.DECIMAL, allowNull: false },
|
||||
},
|
||||
{ timestamps: false },
|
||||
);
|
||||
|
||||
(async () => {
|
||||
try {
|
||||
await sequelize.authenticate();
|
||||
console.log('Connection has been established successfully.');
|
||||
|
||||
// create table
|
||||
await sequelize.sync();
|
||||
|
||||
let products = [
|
||||
{
|
||||
cid: 7,
|
||||
name: 'Organic Cold Brew Coffee',
|
||||
description: 'Rich cold brew coffee crafted with organic fair trade arabica beans.',
|
||||
price: 3.5,
|
||||
product_image: 'BREAD1',
|
||||
},
|
||||
{
|
||||
cid: 7,
|
||||
name: 'Strawberry Banana Smoothie',
|
||||
description: 'Blended smoothie combining fresh strawberries and bananas with yogurt.',
|
||||
price: 4.5,
|
||||
product_image: 'BREAD2',
|
||||
},
|
||||
{
|
||||
cid: 7,
|
||||
name: 'Matcha Green Tea Latte',
|
||||
description: 'Warm frothy latte infused with antioxcidan7-rich Japanese green tea powder.',
|
||||
price: 4.95,
|
||||
product_image: 'BREAD3',
|
||||
},
|
||||
{
|
||||
cid: 7,
|
||||
name: 'Iced Passionfruit Black Tea Lemonade',
|
||||
description: 'Refreshing summertime drink blending passionfruit, black tea, and lemonade.',
|
||||
price: 3.95,
|
||||
product_image: 'BREAD4',
|
||||
},
|
||||
{
|
||||
cid: 7,
|
||||
name: 'Espresso Con Panna',
|
||||
description: 'Double shot espresso topped with whipped cream.',
|
||||
price: 3.95,
|
||||
product_image: 'BREAD5',
|
||||
},
|
||||
];
|
||||
|
||||
for (var i = 0; i < products.length; i++) {
|
||||
await Product.create(products[i]);
|
||||
}
|
||||
|
||||
const categories = await Product.findAll();
|
||||
|
||||
await sequelize.close();
|
||||
} catch (error) {
|
||||
console.error('Unable to connect to the database:', error);
|
||||
}
|
||||
})();
|
27
tsc1877/task1/project/admin/db_seed_local/seed_all.js
Normal file
27
tsc1877/task1/project/admin/db_seed_local/seed_all.js
Normal file
@@ -0,0 +1,27 @@
|
||||
function delay(time_ms) {
|
||||
return new Promise((res, rej) => {
|
||||
setTimeout(() => {
|
||||
res();
|
||||
}, time_ms);
|
||||
});
|
||||
}
|
||||
|
||||
(async () => {
|
||||
await require('./helloworld');
|
||||
await delay(1000);
|
||||
await require('./categories');
|
||||
await delay(1000);
|
||||
|
||||
await require('./products');
|
||||
await delay(1000);
|
||||
|
||||
await require('./products_cid_1');
|
||||
await require('./products_cid_2');
|
||||
await require('./products_cid_3');
|
||||
await require('./products_cid_4');
|
||||
await require('./products_cid_5');
|
||||
await require('./products_cid_6');
|
||||
// await require('./products_cid_7');
|
||||
|
||||
console.log('done');
|
||||
})();
|
Reference in New Issue
Block a user