add createdAt, updatedAt fields; add default values for not null fields

This commit is contained in:
Bilal Catic
2019-09-13 10:56:46 +02:00
parent 81ecb37493
commit e32e98537c
3 changed files with 51 additions and 16 deletions

View File

@@ -53,12 +53,20 @@ module.exports = {
sold: { sold: {
type: Sequelize.BOOLEAN, type: Sequelize.BOOLEAN,
allowNull: false allowNull: false
},
createdAt: {
type: Sequelize.DATE,
defaultValue: Sequelize.literal("NOW()")
},
updatedAt: {
type: Sequelize.DATE,
defaultValue: Sequelize.literal("NOW()")
} }
}; };
return queryInterface.createTable("realEstates", tableFields); return queryInterface.createTable("RealEstates", tableFields);
}, },
down: queryInterface => { down: queryInterface => {
return queryInterface.dropTable("realEstates", {}); return queryInterface.dropTable("RealEstates", {});
} }
}; };

View File

@@ -10,8 +10,13 @@ module.exports = {
primaryKey: true primaryKey: true
}, },
areaToSearch: { areaToSearch: {
type: Sequelize.GEOMETRY("POINT", 4326), type: Sequelize.GEOMETRY("POLYGON", 4326),
allowNull: false allowNull: false,
defaultValue: {
type: "Polygon",
coordinates: [[[0, 0], [0, 0], [0, 0], [0, 0], [0, 0]]],
crs: { type: "name", properties: { name: "EPSG:4326" } }
}
}, },
realEstateType: { realEstateType: {
type: Sequelize.TEXT, type: Sequelize.TEXT,
@@ -19,7 +24,8 @@ module.exports = {
}, },
adType: { adType: {
type: Sequelize.TEXT, type: Sequelize.TEXT,
allowNull: false allowNull: false,
defaultValue: "sell"
}, },
email: Sequelize.TEXT, email: Sequelize.TEXT,
locality: Sequelize.TEXT, locality: Sequelize.TEXT,
@@ -30,31 +36,44 @@ module.exports = {
country: Sequelize.TEXT, country: Sequelize.TEXT,
sizeMin: { sizeMin: {
type: Sequelize.INTEGER, type: Sequelize.INTEGER,
allowNull: false allowNull: false,
defaultValue: 0
}, },
sizeMax: { sizeMax: {
type: Sequelize.INTEGER, type: Sequelize.INTEGER,
allowNull: false allowNull: false,
defaultValue: 0
}, },
priceMin: { priceMin: {
type: Sequelize.INTEGER, type: Sequelize.INTEGER,
allowNull: false allowNull: false,
defaultValue: 0
}, },
priceMax: { priceMax: {
type: Sequelize.INTEGER, type: Sequelize.INTEGER,
allowNull: false allowNull: false,
defaultValue: 0
}, },
gardenSizeMin: Sequelize.INTEGER, gardenSizeMin: Sequelize.INTEGER,
gardenSizeMax: Sequelize.INTEGER, gardenSizeMax: Sequelize.INTEGER,
subscribed: { subscribed: {
type: Sequelize.BOOLEAN, type: Sequelize.BOOLEAN,
allowNull: false allowNull: false,
defaultValue: true
},
createdAt: {
type: Sequelize.DATE,
defaultValue: Sequelize.literal("NOW()")
},
updatedAt: {
type: Sequelize.DATE,
defaultValue: Sequelize.literal("NOW()")
} }
}; };
return queryInterface.createTable("searchRequests", tableFields); return queryInterface.createTable("SearchRequests", tableFields);
}, },
down: queryInterface => { down: queryInterface => {
return queryInterface.dropTable("searchRequests", {}); return queryInterface.dropTable("SearchRequests", {});
} }
}; };

View File

@@ -13,7 +13,7 @@ module.exports = {
allowNull: false, allowNull: false,
primaryKey: true, primaryKey: true,
references: { references: {
model: "searchRequests", model: "SearchRequests",
key: "id" key: "id"
}, },
onUpdate: "CASCADE", onUpdate: "CASCADE",
@@ -24,7 +24,7 @@ module.exports = {
allowNull: false, allowNull: false,
primaryKey: true, primaryKey: true,
references: { references: {
model: "realEstates", model: "RealEstates",
key: "id" key: "id"
}, },
onUpdate: "CASCADE", onUpdate: "CASCADE",
@@ -34,12 +34,20 @@ module.exports = {
type: Sequelize.BOOLEAN, type: Sequelize.BOOLEAN,
allowNull: false, allowNull: false,
defaultValue: false defaultValue: false
},
createdAt: {
type: Sequelize.DATE,
defaultValue: Sequelize.literal("NOW()")
},
updatedAt: {
type: Sequelize.DATE,
defaultValue: Sequelize.literal("NOW()")
} }
}; };
return queryInterface.createTable("searchRequestMatches", tableFields); return queryInterface.createTable("SearchRequestMatches", tableFields);
}, },
down: queryInterface => { down: queryInterface => {
return queryInterface.dropTable("searchRequestMatches", {}); return queryInterface.dropTable("SearchRequestMatches", {});
} }
}; };