WIP Added model, migration and bulk upsert fnc.

This commit is contained in:
Naida Vatric
2020-01-21 16:28:47 +01:00
parent 42eddb3aa5
commit 8d3f001678
5 changed files with 65 additions and 22 deletions

View File

@@ -1,29 +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,
unique: "uniquePriceRealEstate",
references: {
model: "RealEstates",
key: "id"
const PriceHistory = sequalize.define(
"PriceHistory",
{
id: {
type: DataTypes.BIGINT,
autoIncrement: true,
primaryKey: true,
allowNull: false
},
onUpdate: "CASCADE",
onDelete: "SET NULL"
realEstateId: {
type: DataTypes.BIGINT,
allowNull: false,
unique: "uniquePriceRealEstate",
references: {
model: "RealEstates",
key: "id"
},
onUpdate: "CASCADE",
onDelete: "SET NULL"
},
price: {
type: DataTypes.REAL,
unique: "uniquePriceRealEstate"
}
},
price: {
type: DataTypes.REAL,
unique: "uniquePriceRealEstate"
{
freezeTableName: true
}
});
);
PriceHistory.associate = models => {
PriceHistory.hasMany(models.RealEstate, {