Database migration to support more weather properties
This commit is contained in:
parent
e2285e2deb
commit
a549149452
4 changed files with 60 additions and 13 deletions
35
db/migrations/03_weather.js
Normal file
35
db/migrations/03_weather.js
Normal file
|
@ -0,0 +1,35 @@
|
|||
const { DataTypes } = require('sequelize');
|
||||
const { INTEGER, FLOAT } = DataTypes;
|
||||
const loadConfig = require('../../utils/loadConfig');
|
||||
const getExternalWeather = require('../../utils/getExternalWeather');
|
||||
|
||||
const up = async (query) => {
|
||||
await query.addColumn('weather', 'humidity', {
|
||||
type: INTEGER,
|
||||
});
|
||||
|
||||
await query.addColumn('weather', 'windK', {
|
||||
type: FLOAT,
|
||||
});
|
||||
|
||||
await query.addColumn('weather', 'windM', {
|
||||
type: FLOAT,
|
||||
});
|
||||
|
||||
const { WEATHER_API_KEY: secret } = await loadConfig();
|
||||
|
||||
if (secret) {
|
||||
await getExternalWeather();
|
||||
}
|
||||
};
|
||||
|
||||
const down = async (query) => {
|
||||
await query.removeColumn('weather', 'humidity');
|
||||
await query.removeColumn('weather', 'windK');
|
||||
await query.removeColumn('weather', 'windM');
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
up,
|
||||
down,
|
||||
};
|
|
@ -1,16 +1,23 @@
|
|||
const { DataTypes } = require('sequelize');
|
||||
const { sequelize } = require('../db');
|
||||
|
||||
const Weather = sequelize.define('Weather', {
|
||||
externalLastUpdate: DataTypes.STRING,
|
||||
tempC: DataTypes.FLOAT,
|
||||
tempF: DataTypes.FLOAT,
|
||||
isDay: DataTypes.INTEGER,
|
||||
cloud: DataTypes.INTEGER,
|
||||
conditionText: DataTypes.TEXT,
|
||||
conditionCode: DataTypes.INTEGER
|
||||
}, {
|
||||
tableName: 'weather'
|
||||
});
|
||||
const Weather = sequelize.define(
|
||||
'Weather',
|
||||
{
|
||||
externalLastUpdate: DataTypes.STRING,
|
||||
tempC: DataTypes.FLOAT,
|
||||
tempF: DataTypes.FLOAT,
|
||||
isDay: DataTypes.INTEGER,
|
||||
cloud: DataTypes.INTEGER,
|
||||
conditionText: DataTypes.TEXT,
|
||||
conditionCode: DataTypes.INTEGER,
|
||||
humidity: DataTypes.INTEGER,
|
||||
windK: DataTypes.FLOAT,
|
||||
windM: DataTypes.FLOAT,
|
||||
},
|
||||
{
|
||||
tableName: 'weather',
|
||||
}
|
||||
);
|
||||
|
||||
module.exports = Weather;
|
||||
module.exports = Weather;
|
||||
|
|
|
@ -21,6 +21,9 @@ const getExternalWeather = async () => {
|
|||
cloud: cursor.cloud,
|
||||
conditionText: cursor.condition.text,
|
||||
conditionCode: cursor.condition.code,
|
||||
humidity: cursor.humidity,
|
||||
windK: cursor.wind_kph,
|
||||
windM: cursor.wind_mph,
|
||||
});
|
||||
return weatherData;
|
||||
} catch (err) {
|
||||
|
|
|
@ -25,5 +25,7 @@
|
|||
"daySchema": "Sunday;Monday;Tuesday;Wednesday;Thursday;Friday;Saturday",
|
||||
"monthSchema": "January;February;March;April;May;June;July;August;September;October;November;December",
|
||||
"showTime": false,
|
||||
"defaultTheme": "tron"
|
||||
"defaultTheme": "tron",
|
||||
"isKilometer": true,
|
||||
"weatherData": "cloud"
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue