-
Notifications
You must be signed in to change notification settings - Fork 0
/
dbInit.js
27 lines (21 loc) · 822 Bytes
/
dbInit.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
const Sequelize = require("sequelize");
const sequelize = new Sequelize("database", "username", "password", {
host: "localhost",
dialect: "sqlite",
logging: false,
storage: "database.sqlite",
});
const CurrencyShop = require("./models/CurrencyShop.js")(sequelize, Sequelize.DataTypes);
require("./models/Users.js")(sequelize, Sequelize.DataTypes);
require("./models/UserItems.js")(sequelize, Sequelize.DataTypes);
const alter = process.argv.includes("--alter") || process.argv.includes("-a");
sequelize.sync({ alter }).then(async () => {
const shop = [
CurrencyShop.upsert({ name: "Tea", cost: 1 }),
CurrencyShop.upsert({ name: "Coffee", cost: 2 }),
CurrencyShop.upsert({ name: "Cake", cost: 5 }),
];
await Promise.all(shop);
console.log("Database synced");
sequelize.close();
}).catch(console.error);