mirror of
https://github.com/pawelmalak/flame.git
synced 2025-06-28 09:14:04 -04:00
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 { DataTypes } = require('sequelize');
|
||||||
const { sequelize } = require('../db');
|
const { sequelize } = require('../db');
|
||||||
|
|
||||||
const Weather = sequelize.define('Weather', {
|
const Weather = sequelize.define(
|
||||||
|
'Weather',
|
||||||
|
{
|
||||||
externalLastUpdate: DataTypes.STRING,
|
externalLastUpdate: DataTypes.STRING,
|
||||||
tempC: DataTypes.FLOAT,
|
tempC: DataTypes.FLOAT,
|
||||||
tempF: DataTypes.FLOAT,
|
tempF: DataTypes.FLOAT,
|
||||||
isDay: DataTypes.INTEGER,
|
isDay: DataTypes.INTEGER,
|
||||||
cloud: DataTypes.INTEGER,
|
cloud: DataTypes.INTEGER,
|
||||||
conditionText: DataTypes.TEXT,
|
conditionText: DataTypes.TEXT,
|
||||||
conditionCode: DataTypes.INTEGER
|
conditionCode: DataTypes.INTEGER,
|
||||||
}, {
|
humidity: DataTypes.INTEGER,
|
||||||
tableName: 'weather'
|
windK: DataTypes.FLOAT,
|
||||||
});
|
windM: DataTypes.FLOAT,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
tableName: 'weather',
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
module.exports = Weather;
|
module.exports = Weather;
|
|
@ -21,6 +21,9 @@ const getExternalWeather = async () => {
|
||||||
cloud: cursor.cloud,
|
cloud: cursor.cloud,
|
||||||
conditionText: cursor.condition.text,
|
conditionText: cursor.condition.text,
|
||||||
conditionCode: cursor.condition.code,
|
conditionCode: cursor.condition.code,
|
||||||
|
humidity: cursor.humidity,
|
||||||
|
windK: cursor.wind_kph,
|
||||||
|
windM: cursor.wind_mph,
|
||||||
});
|
});
|
||||||
return weatherData;
|
return weatherData;
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
|
|
|
@ -25,5 +25,7 @@
|
||||||
"daySchema": "Sunday;Monday;Tuesday;Wednesday;Thursday;Friday;Saturday",
|
"daySchema": "Sunday;Monday;Tuesday;Wednesday;Thursday;Friday;Saturday",
|
||||||
"monthSchema": "January;February;March;April;May;June;July;August;September;October;November;December",
|
"monthSchema": "January;February;March;April;May;June;July;August;September;October;November;December",
|
||||||
"showTime": false,
|
"showTime": false,
|
||||||
"defaultTheme": "tron"
|
"defaultTheme": "tron",
|
||||||
|
"isKilometer": true,
|
||||||
|
"weatherData": "cloud"
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue