-
Notifications
You must be signed in to change notification settings - Fork 1
/
db-init.js
34 lines (30 loc) · 1.06 KB
/
db-init.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
28
29
30
31
32
33
34
const { Sequelize, DataTypes } = require('sequelize');
const { Settings } = require('./db-objects.js');
const sequelize = new Sequelize('database', 'username', 'password', {
host: 'localhost',
dialect: 'sqlite',
logging: false,
storage: 'database.sqlite',
});
require('./models/Weather.js')(sequelize, DataTypes);
require('./models/Settings.js')(sequelize, DataTypes);
const force = process.argv.includes('--force') || process.argv.includes('-f');
sequelize.sync({ force }).then(async () => {
const settings = [
Settings.findCreateFind({
where: { setting: 'weather_enable' },
defaults: { setting: 'weather_enable', value: false },
}),
Settings.findCreateFind({
where: { setting: 'weather_channel' },
defaults: { setting: 'weather_channel', value: '' },
}),
Settings.findCreateFind({
where: { setting: 'weather_schedule' },
defaults: { setting: 'weather_schedule', value: '0 0 6,10,16 * * *' },
}),
];
await Promise.all(settings);
console.log('Database synced');
sequelize.close();
}).catch(console.error);