WIP Added model and migration for new table priceHistory.
This commit is contained in:
38
app/migrations/20200120215830-add-priceHistory-table.js
Normal file
38
app/migrations/20200120215830-add-priceHistory-table.js
Normal file
@@ -0,0 +1,38 @@
|
|||||||
|
"use strict";
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
up: (queryInterface, Sequelize) => {
|
||||||
|
const tableFields = {
|
||||||
|
id: {
|
||||||
|
type: Sequelize.BIGINT,
|
||||||
|
autoIncrement: true,
|
||||||
|
allowNull: false,
|
||||||
|
primaryKey: true
|
||||||
|
},
|
||||||
|
realEstateId: {
|
||||||
|
type: Sequelize.BIGINT,
|
||||||
|
allowNull: false,
|
||||||
|
references: {
|
||||||
|
model: "RealEstate",
|
||||||
|
key: "id"
|
||||||
|
},
|
||||||
|
onUpdate: "CASCADE",
|
||||||
|
onDelete: "SET NULL"
|
||||||
|
},
|
||||||
|
price: Sequelize.REAL,
|
||||||
|
createdAt: {
|
||||||
|
type: Sequelize.DATE,
|
||||||
|
defaultValue: Sequelize.literal("NOW()")
|
||||||
|
},
|
||||||
|
updatedAt: {
|
||||||
|
type: Sequelize.DATE,
|
||||||
|
defaultValue: Sequelize.literal("NOW()")
|
||||||
|
}
|
||||||
|
};
|
||||||
|
return queryInterface.createTable("PriceHistory", tableFields);
|
||||||
|
},
|
||||||
|
|
||||||
|
down: queryInterface => {
|
||||||
|
return queryInterface.dropTable("PriceHistory", {});
|
||||||
|
}
|
||||||
|
};
|
||||||
35
app/models/priceHistory.js
Normal file
35
app/models/priceHistory.js
Normal 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;
|
||||||
|
};
|
||||||
Reference in New Issue
Block a user