WIP Added model and migration for new table priceHistory.

This commit is contained in:
Naida Vatric
2020-01-20 23:09:02 +01:00
parent 259799144e
commit 0a181f742f
2 changed files with 73 additions and 0 deletions

View File

@@ -0,0 +1,35 @@
"use strict";
module.exports = (sequalize, DataTypes) => {
const PriceHistory = sequalize.define("PriceHistory", {
id: {
type: DataTypes.BIGINT,
autoIncrement: true,
primaryKey: true,
allowNull: false
},
realEstateId: {
type: DataTypes.BIGINT,
allowNull: false,
references: {
model: "RealEstate",
key: "id"
},
onUpdate: "CASCADE",
onDelete: "SET NULL"
},
price: DataTypes.REAL
});
PriceHistory.associate = models => {
PriceHistory.hasMany(models.RealEstate, {
foreignKey: "id",
sourceKey: "realEstateId",
targetKey: "id",
as: "realEstates"
});
};
return PriceHistory;
};