623 lines
15 KiB
JavaScript
623 lines
15 KiB
JavaScript
const db = require('../models');
|
|
const Users = db.users;
|
|
|
|
const Cases = db.cases;
|
|
|
|
const CrimePatterns = db.crime_patterns;
|
|
|
|
const Predictions = db.predictions;
|
|
|
|
const Suspects = db.suspects;
|
|
|
|
const Organizations = db.organizations;
|
|
|
|
const CasesData = [
|
|
{
|
|
case_number: 'C12345',
|
|
|
|
description: 'Burglary at 123 Main St.',
|
|
|
|
date_reported: new Date('2023-10-01T10:00:00Z'),
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_many" field
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
case_number: 'C12346',
|
|
|
|
description: 'Vandalism in Central Park',
|
|
|
|
date_reported: new Date('2023-10-02T11:30:00Z'),
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_many" field
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
case_number: 'C12347',
|
|
|
|
description: 'Arson at 456 Elm St.',
|
|
|
|
date_reported: new Date('2023-10-03T14:00:00Z'),
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_many" field
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
case_number: 'C12348',
|
|
|
|
description: 'Robbery at 789 Oak St.',
|
|
|
|
date_reported: new Date('2023-10-04T09:00:00Z'),
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_many" field
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
];
|
|
|
|
const CrimePatternsData = [
|
|
{
|
|
pattern_name: 'Burglary Spree',
|
|
|
|
description: 'Series of burglaries in the downtown area.',
|
|
|
|
// type code here for "relation_many" field
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
pattern_name: 'Vandalism Wave',
|
|
|
|
description: 'Multiple vandalism incidents in parks.',
|
|
|
|
// type code here for "relation_many" field
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
pattern_name: 'Arson Attacks',
|
|
|
|
description: 'Several arson cases in residential areas.',
|
|
|
|
// type code here for "relation_many" field
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
pattern_name: 'Robbery Series',
|
|
|
|
description: 'String of robberies in commercial districts.',
|
|
|
|
// type code here for "relation_many" field
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
];
|
|
|
|
const PredictionsData = [
|
|
{
|
|
prediction_id: 'P001',
|
|
|
|
predicted_date: new Date('2023-10-10T12:00:00Z'),
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
predicted_activity: 'Possible burglary in the downtown area.',
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
prediction_id: 'P002',
|
|
|
|
predicted_date: new Date('2023-10-11T15:00:00Z'),
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
predicted_activity: 'Potential vandalism in Central Park.',
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
prediction_id: 'P003',
|
|
|
|
predicted_date: new Date('2023-10-12T18:00:00Z'),
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
predicted_activity: 'Likely arson attempt in residential zone.',
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
prediction_id: 'P004',
|
|
|
|
predicted_date: new Date('2023-10-13T20:00:00Z'),
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
predicted_activity: 'Possible robbery in commercial district.',
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
];
|
|
|
|
const SuspectsData = [
|
|
{
|
|
name: 'James Smith',
|
|
|
|
date_of_birth: new Date('1985-05-15T00:00:00Z'),
|
|
|
|
status: 'Arrested',
|
|
|
|
// type code here for "relation_many" field
|
|
|
|
// type code here for "relation_many" field
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
name: 'Robert Johnson',
|
|
|
|
date_of_birth: new Date('1990-07-20T00:00:00Z'),
|
|
|
|
status: 'Arrested',
|
|
|
|
// type code here for "relation_many" field
|
|
|
|
// type code here for "relation_many" field
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
name: 'Michael Williams',
|
|
|
|
date_of_birth: new Date('1982-11-30T00:00:00Z'),
|
|
|
|
status: 'Released',
|
|
|
|
// type code here for "relation_many" field
|
|
|
|
// type code here for "relation_many" field
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
name: 'David Brown',
|
|
|
|
date_of_birth: new Date('1978-02-25T00:00:00Z'),
|
|
|
|
status: 'UnderInvestigation',
|
|
|
|
// type code here for "relation_many" field
|
|
|
|
// type code here for "relation_many" field
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
];
|
|
|
|
const OrganizationsData = [
|
|
{
|
|
name: 'Robert Koch',
|
|
},
|
|
|
|
{
|
|
name: 'Claude Levi-Strauss',
|
|
},
|
|
|
|
{
|
|
name: 'Johannes Kepler',
|
|
},
|
|
|
|
{
|
|
name: 'Werner Heisenberg',
|
|
},
|
|
];
|
|
|
|
// Similar logic for "relation_many"
|
|
|
|
async function associateUserWithOrganization() {
|
|
const relatedOrganization0 = await Organizations.findOne({
|
|
offset: Math.floor(Math.random() * (await Organizations.count())),
|
|
});
|
|
const User0 = await Users.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (User0?.setOrganization) {
|
|
await User0.setOrganization(relatedOrganization0);
|
|
}
|
|
|
|
const relatedOrganization1 = await Organizations.findOne({
|
|
offset: Math.floor(Math.random() * (await Organizations.count())),
|
|
});
|
|
const User1 = await Users.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (User1?.setOrganization) {
|
|
await User1.setOrganization(relatedOrganization1);
|
|
}
|
|
|
|
const relatedOrganization2 = await Organizations.findOne({
|
|
offset: Math.floor(Math.random() * (await Organizations.count())),
|
|
});
|
|
const User2 = await Users.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (User2?.setOrganization) {
|
|
await User2.setOrganization(relatedOrganization2);
|
|
}
|
|
|
|
const relatedOrganization3 = await Organizations.findOne({
|
|
offset: Math.floor(Math.random() * (await Organizations.count())),
|
|
});
|
|
const User3 = await Users.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 3,
|
|
});
|
|
if (User3?.setOrganization) {
|
|
await User3.setOrganization(relatedOrganization3);
|
|
}
|
|
}
|
|
|
|
async function associateCaseWithOfficer() {
|
|
const relatedOfficer0 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const Case0 = await Cases.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (Case0?.setOfficer) {
|
|
await Case0.setOfficer(relatedOfficer0);
|
|
}
|
|
|
|
const relatedOfficer1 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const Case1 = await Cases.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (Case1?.setOfficer) {
|
|
await Case1.setOfficer(relatedOfficer1);
|
|
}
|
|
|
|
const relatedOfficer2 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const Case2 = await Cases.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (Case2?.setOfficer) {
|
|
await Case2.setOfficer(relatedOfficer2);
|
|
}
|
|
|
|
const relatedOfficer3 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const Case3 = await Cases.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 3,
|
|
});
|
|
if (Case3?.setOfficer) {
|
|
await Case3.setOfficer(relatedOfficer3);
|
|
}
|
|
}
|
|
|
|
// Similar logic for "relation_many"
|
|
|
|
async function associateCaseWithOrganization() {
|
|
const relatedOrganization0 = await Organizations.findOne({
|
|
offset: Math.floor(Math.random() * (await Organizations.count())),
|
|
});
|
|
const Case0 = await Cases.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (Case0?.setOrganization) {
|
|
await Case0.setOrganization(relatedOrganization0);
|
|
}
|
|
|
|
const relatedOrganization1 = await Organizations.findOne({
|
|
offset: Math.floor(Math.random() * (await Organizations.count())),
|
|
});
|
|
const Case1 = await Cases.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (Case1?.setOrganization) {
|
|
await Case1.setOrganization(relatedOrganization1);
|
|
}
|
|
|
|
const relatedOrganization2 = await Organizations.findOne({
|
|
offset: Math.floor(Math.random() * (await Organizations.count())),
|
|
});
|
|
const Case2 = await Cases.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (Case2?.setOrganization) {
|
|
await Case2.setOrganization(relatedOrganization2);
|
|
}
|
|
|
|
const relatedOrganization3 = await Organizations.findOne({
|
|
offset: Math.floor(Math.random() * (await Organizations.count())),
|
|
});
|
|
const Case3 = await Cases.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 3,
|
|
});
|
|
if (Case3?.setOrganization) {
|
|
await Case3.setOrganization(relatedOrganization3);
|
|
}
|
|
}
|
|
|
|
// Similar logic for "relation_many"
|
|
|
|
async function associateCrimePatternWithOrganization() {
|
|
const relatedOrganization0 = await Organizations.findOne({
|
|
offset: Math.floor(Math.random() * (await Organizations.count())),
|
|
});
|
|
const CrimePattern0 = await CrimePatterns.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (CrimePattern0?.setOrganization) {
|
|
await CrimePattern0.setOrganization(relatedOrganization0);
|
|
}
|
|
|
|
const relatedOrganization1 = await Organizations.findOne({
|
|
offset: Math.floor(Math.random() * (await Organizations.count())),
|
|
});
|
|
const CrimePattern1 = await CrimePatterns.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (CrimePattern1?.setOrganization) {
|
|
await CrimePattern1.setOrganization(relatedOrganization1);
|
|
}
|
|
|
|
const relatedOrganization2 = await Organizations.findOne({
|
|
offset: Math.floor(Math.random() * (await Organizations.count())),
|
|
});
|
|
const CrimePattern2 = await CrimePatterns.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (CrimePattern2?.setOrganization) {
|
|
await CrimePattern2.setOrganization(relatedOrganization2);
|
|
}
|
|
|
|
const relatedOrganization3 = await Organizations.findOne({
|
|
offset: Math.floor(Math.random() * (await Organizations.count())),
|
|
});
|
|
const CrimePattern3 = await CrimePatterns.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 3,
|
|
});
|
|
if (CrimePattern3?.setOrganization) {
|
|
await CrimePattern3.setOrganization(relatedOrganization3);
|
|
}
|
|
}
|
|
|
|
async function associatePredictionWithSuspect() {
|
|
const relatedSuspect0 = await Suspects.findOne({
|
|
offset: Math.floor(Math.random() * (await Suspects.count())),
|
|
});
|
|
const Prediction0 = await Predictions.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (Prediction0?.setSuspect) {
|
|
await Prediction0.setSuspect(relatedSuspect0);
|
|
}
|
|
|
|
const relatedSuspect1 = await Suspects.findOne({
|
|
offset: Math.floor(Math.random() * (await Suspects.count())),
|
|
});
|
|
const Prediction1 = await Predictions.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (Prediction1?.setSuspect) {
|
|
await Prediction1.setSuspect(relatedSuspect1);
|
|
}
|
|
|
|
const relatedSuspect2 = await Suspects.findOne({
|
|
offset: Math.floor(Math.random() * (await Suspects.count())),
|
|
});
|
|
const Prediction2 = await Predictions.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (Prediction2?.setSuspect) {
|
|
await Prediction2.setSuspect(relatedSuspect2);
|
|
}
|
|
|
|
const relatedSuspect3 = await Suspects.findOne({
|
|
offset: Math.floor(Math.random() * (await Suspects.count())),
|
|
});
|
|
const Prediction3 = await Predictions.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 3,
|
|
});
|
|
if (Prediction3?.setSuspect) {
|
|
await Prediction3.setSuspect(relatedSuspect3);
|
|
}
|
|
}
|
|
|
|
async function associatePredictionWithOrganization() {
|
|
const relatedOrganization0 = await Organizations.findOne({
|
|
offset: Math.floor(Math.random() * (await Organizations.count())),
|
|
});
|
|
const Prediction0 = await Predictions.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (Prediction0?.setOrganization) {
|
|
await Prediction0.setOrganization(relatedOrganization0);
|
|
}
|
|
|
|
const relatedOrganization1 = await Organizations.findOne({
|
|
offset: Math.floor(Math.random() * (await Organizations.count())),
|
|
});
|
|
const Prediction1 = await Predictions.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (Prediction1?.setOrganization) {
|
|
await Prediction1.setOrganization(relatedOrganization1);
|
|
}
|
|
|
|
const relatedOrganization2 = await Organizations.findOne({
|
|
offset: Math.floor(Math.random() * (await Organizations.count())),
|
|
});
|
|
const Prediction2 = await Predictions.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (Prediction2?.setOrganization) {
|
|
await Prediction2.setOrganization(relatedOrganization2);
|
|
}
|
|
|
|
const relatedOrganization3 = await Organizations.findOne({
|
|
offset: Math.floor(Math.random() * (await Organizations.count())),
|
|
});
|
|
const Prediction3 = await Predictions.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 3,
|
|
});
|
|
if (Prediction3?.setOrganization) {
|
|
await Prediction3.setOrganization(relatedOrganization3);
|
|
}
|
|
}
|
|
|
|
// Similar logic for "relation_many"
|
|
|
|
// Similar logic for "relation_many"
|
|
|
|
async function associateSuspectWithOrganization() {
|
|
const relatedOrganization0 = await Organizations.findOne({
|
|
offset: Math.floor(Math.random() * (await Organizations.count())),
|
|
});
|
|
const Suspect0 = await Suspects.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (Suspect0?.setOrganization) {
|
|
await Suspect0.setOrganization(relatedOrganization0);
|
|
}
|
|
|
|
const relatedOrganization1 = await Organizations.findOne({
|
|
offset: Math.floor(Math.random() * (await Organizations.count())),
|
|
});
|
|
const Suspect1 = await Suspects.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (Suspect1?.setOrganization) {
|
|
await Suspect1.setOrganization(relatedOrganization1);
|
|
}
|
|
|
|
const relatedOrganization2 = await Organizations.findOne({
|
|
offset: Math.floor(Math.random() * (await Organizations.count())),
|
|
});
|
|
const Suspect2 = await Suspects.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (Suspect2?.setOrganization) {
|
|
await Suspect2.setOrganization(relatedOrganization2);
|
|
}
|
|
|
|
const relatedOrganization3 = await Organizations.findOne({
|
|
offset: Math.floor(Math.random() * (await Organizations.count())),
|
|
});
|
|
const Suspect3 = await Suspects.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 3,
|
|
});
|
|
if (Suspect3?.setOrganization) {
|
|
await Suspect3.setOrganization(relatedOrganization3);
|
|
}
|
|
}
|
|
|
|
module.exports = {
|
|
up: async (queryInterface, Sequelize) => {
|
|
await Cases.bulkCreate(CasesData);
|
|
|
|
await CrimePatterns.bulkCreate(CrimePatternsData);
|
|
|
|
await Predictions.bulkCreate(PredictionsData);
|
|
|
|
await Suspects.bulkCreate(SuspectsData);
|
|
|
|
await Organizations.bulkCreate(OrganizationsData);
|
|
|
|
await Promise.all([
|
|
// Similar logic for "relation_many"
|
|
|
|
await associateUserWithOrganization(),
|
|
|
|
await associateCaseWithOfficer(),
|
|
|
|
// Similar logic for "relation_many"
|
|
|
|
await associateCaseWithOrganization(),
|
|
|
|
// Similar logic for "relation_many"
|
|
|
|
await associateCrimePatternWithOrganization(),
|
|
|
|
await associatePredictionWithSuspect(),
|
|
|
|
await associatePredictionWithOrganization(),
|
|
|
|
// Similar logic for "relation_many"
|
|
|
|
// Similar logic for "relation_many"
|
|
|
|
await associateSuspectWithOrganization(),
|
|
]);
|
|
},
|
|
|
|
down: async (queryInterface, Sequelize) => {
|
|
await queryInterface.bulkDelete('cases', null, {});
|
|
|
|
await queryInterface.bulkDelete('crime_patterns', null, {});
|
|
|
|
await queryInterface.bulkDelete('predictions', null, {});
|
|
|
|
await queryInterface.bulkDelete('suspects', null, {});
|
|
|
|
await queryInterface.bulkDelete('organizations', null, {});
|
|
},
|
|
};
|