30375/backend/src/db/seeders/20231127130745-sample-data.js
2025-04-01 10:13:11 +00:00

299 lines
6.2 KiB
JavaScript

const db = require('../models');
const Users = db.users;
const GeospatialFiles = db.geospatial_files;
const MapLayers = db.map_layers;
const Maps = db.maps;
const GeospatialFilesData = [
{
file_name: 'land_cover.tif',
file_type: 'GeoTIFF',
// type code here for "files" field
// type code here for "relation_one" field
uploaded_at: new Date('2023-10-01T10:00:00Z'),
},
{
file_name: 'city_boundaries.shp',
file_type: 'Shapefile',
// type code here for "files" field
// type code here for "relation_one" field
uploaded_at: new Date('2023-10-02T11:30:00Z'),
},
{
file_name: 'rivers.geojson',
file_type: 'Shapefile',
// type code here for "files" field
// type code here for "relation_one" field
uploaded_at: new Date('2023-10-03T09:15:00Z'),
},
{
file_name: 'elevation.tif',
file_type: 'GeoTIFF',
// type code here for "files" field
// type code here for "relation_one" field
uploaded_at: new Date('2023-10-04T14:45:00Z'),
},
];
const MapLayersData = [
{
layer_name: 'Land Cover',
layer_type: 'Raster',
// type code here for "relation_one" field
color: '#FF5733',
is_visible: true,
},
{
layer_name: 'City Boundaries',
layer_type: 'Raster',
// type code here for "relation_one" field
color: '#33FF57',
is_visible: true,
},
{
layer_name: 'Rivers',
layer_type: 'Raster',
// type code here for "relation_one" field
color: '#3357FF',
is_visible: false,
},
{
layer_name: 'Elevation',
layer_type: 'Vector',
// type code here for "relation_one" field
color: '#FF33A1',
is_visible: true,
},
];
const MapsData = [
{
title: 'Urban Development',
subtitle: 'City Expansion Analysis',
// type code here for "relation_many" field
show_basemap: true,
show_admin_boundaries: true,
latitude: 28.6139,
longitude: 77.209,
},
{
title: 'Water Resources',
subtitle: 'River and Lake Distribution',
// type code here for "relation_many" field
show_basemap: false,
show_admin_boundaries: true,
latitude: 34.0522,
longitude: -118.2437,
},
{
title: 'Topography',
subtitle: 'Elevation and Terrain',
// type code here for "relation_many" field
show_basemap: true,
show_admin_boundaries: true,
latitude: 40.7128,
longitude: -74.006,
},
{
title: 'Forest Conservation',
subtitle: 'Protected Areas',
// type code here for "relation_many" field
show_basemap: false,
show_admin_boundaries: true,
latitude: 48.8566,
longitude: 2.3522,
},
];
// Similar logic for "relation_many"
async function associateGeospatialFileWithUploaded_by() {
const relatedUploaded_by0 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const GeospatialFile0 = await GeospatialFiles.findOne({
order: [['id', 'ASC']],
offset: 0,
});
if (GeospatialFile0?.setUploaded_by) {
await GeospatialFile0.setUploaded_by(relatedUploaded_by0);
}
const relatedUploaded_by1 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const GeospatialFile1 = await GeospatialFiles.findOne({
order: [['id', 'ASC']],
offset: 1,
});
if (GeospatialFile1?.setUploaded_by) {
await GeospatialFile1.setUploaded_by(relatedUploaded_by1);
}
const relatedUploaded_by2 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const GeospatialFile2 = await GeospatialFiles.findOne({
order: [['id', 'ASC']],
offset: 2,
});
if (GeospatialFile2?.setUploaded_by) {
await GeospatialFile2.setUploaded_by(relatedUploaded_by2);
}
const relatedUploaded_by3 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const GeospatialFile3 = await GeospatialFiles.findOne({
order: [['id', 'ASC']],
offset: 3,
});
if (GeospatialFile3?.setUploaded_by) {
await GeospatialFile3.setUploaded_by(relatedUploaded_by3);
}
}
async function associateMapLayerWithGeospatial_file() {
const relatedGeospatial_file0 = await GeospatialFiles.findOne({
offset: Math.floor(Math.random() * (await GeospatialFiles.count())),
});
const MapLayer0 = await MapLayers.findOne({
order: [['id', 'ASC']],
offset: 0,
});
if (MapLayer0?.setGeospatial_file) {
await MapLayer0.setGeospatial_file(relatedGeospatial_file0);
}
const relatedGeospatial_file1 = await GeospatialFiles.findOne({
offset: Math.floor(Math.random() * (await GeospatialFiles.count())),
});
const MapLayer1 = await MapLayers.findOne({
order: [['id', 'ASC']],
offset: 1,
});
if (MapLayer1?.setGeospatial_file) {
await MapLayer1.setGeospatial_file(relatedGeospatial_file1);
}
const relatedGeospatial_file2 = await GeospatialFiles.findOne({
offset: Math.floor(Math.random() * (await GeospatialFiles.count())),
});
const MapLayer2 = await MapLayers.findOne({
order: [['id', 'ASC']],
offset: 2,
});
if (MapLayer2?.setGeospatial_file) {
await MapLayer2.setGeospatial_file(relatedGeospatial_file2);
}
const relatedGeospatial_file3 = await GeospatialFiles.findOne({
offset: Math.floor(Math.random() * (await GeospatialFiles.count())),
});
const MapLayer3 = await MapLayers.findOne({
order: [['id', 'ASC']],
offset: 3,
});
if (MapLayer3?.setGeospatial_file) {
await MapLayer3.setGeospatial_file(relatedGeospatial_file3);
}
}
// Similar logic for "relation_many"
module.exports = {
up: async (queryInterface, Sequelize) => {
await GeospatialFiles.bulkCreate(GeospatialFilesData);
await MapLayers.bulkCreate(MapLayersData);
await Maps.bulkCreate(MapsData);
await Promise.all([
// Similar logic for "relation_many"
await associateGeospatialFileWithUploaded_by(),
await associateMapLayerWithGeospatial_file(),
// Similar logic for "relation_many"
]);
},
down: async (queryInterface, Sequelize) => {
await queryInterface.bulkDelete('geospatial_files', null, {});
await queryInterface.bulkDelete('map_layers', null, {});
await queryInterface.bulkDelete('maps', null, {});
},
};