B:BD[
5.4726] → [
2.282:415]
∅:D[
2.415] → [
5.4807:5303]
B:BD[
5.4807] → [
5.4807:5303]
B:BD[
5.5303] → [
2.416:478]
∅:D[
2.478] → [
5.5365:5632]
B:BD[
5.5365] → [
5.5365:5632]
B:BD[
5.5632] → [
2.479:523]
∅:D[
2.523] → [
5.5676:6381]
B:BD[
5.5676] → [
5.5676:6381]
B:BD[
5.6381] → [
2.524:589]
∅:D[
2.589] → [
5.6446:6831]
B:BD[
5.6446] → [
5.6446:6831]
// Process without transaction (Neon HTTP driver doesn't support transactions)
// Verify all referenced entities exist first
// Verify all referenced entities exist
const allFileIds = [...new Set(selectionsData.map(s => s.fileId))];
const allSpeciesIds = [...new Set(selectionsData.flatMap((s: SelectionImportItem) => s.species.map((sp: SelectionImportSpecies) => sp.speciesId)))];
const allCallTypeIds = [...new Set(selectionsData.flatMap((s: SelectionImportItem) =>
s.species.flatMap((sp: SelectionImportSpecies) => sp.callTypes || [])
))];
// Check if filter exists
const filterExists = await db.select({ id: filter.id })
.from(filter)
.where(eq(filter.id, filterId))
.limit(1);
if (filterExists.length === 0) {
throw new Error(`Filter with ID ${filterId} not found`);
}
// Check if all files exist and belong to the dataset
const fileResults = await db.select({
id: file.id,
clusterId: file.clusterId
})
.from(file)
.innerJoin(cluster, eq(file.clusterId, cluster.id))
.innerJoin(location, eq(cluster.locationId, location.id))
.where(
and(
inArray(file.id, allFileIds),
eq(location.datasetId, datasetId),
eq(file.active, true)
)
);
if (fileResults.length !== allFileIds.length) {
const foundFileIds = fileResults.map(f => f.id);
const missingFileIds = allFileIds.filter(id => !foundFileIds.includes(id));
throw new Error(`Files not found in dataset: ${missingFileIds.join(', ')}`);
}
// Check if all species exist
const speciesResults = await db.select({ id: species.id })
.from(species)
.where(inArray(species.id, allSpeciesIds));
if (speciesResults.length !== allSpeciesIds.length) {
const foundSpeciesIds = speciesResults.map(s => s.id);
const missingSpeciesIds = allSpeciesIds.filter(id => !foundSpeciesIds.includes(id));
throw new Error(`Species not found: ${missingSpeciesIds.join(', ')}`);
}
// Validate all referenced entities exist before processing
const allFileIds = [...new Set(selectionsData.map(s => s.fileId))];
const allSpeciesIds = [...new Set(selectionsData.flatMap((s: SelectionImportItem) => s.species.map((sp: SelectionImportSpecies) => sp.speciesId)))];
const allCallTypeIds = [...new Set(selectionsData.flatMap((s: SelectionImportItem) =>
s.species.flatMap((sp: SelectionImportSpecies) => sp.callTypes || [])
))];
// Check if filter exists
const filterExists = await db.select({ id: filter.id })
.from(filter)
.where(eq(filter.id, filterId))
.limit(1);
if (filterExists.length === 0) {
throw new Error(`Filter with ID ${filterId} not found`);
}
// Check if all files exist and belong to the dataset
const fileResults = await db.select({
id: file.id,
clusterId: file.clusterId
})
.from(file)
.innerJoin(cluster, eq(file.clusterId, cluster.id))
.innerJoin(location, eq(cluster.locationId, location.id))
.where(
and(
inArray(file.id, allFileIds),
eq(location.datasetId, datasetId),
eq(file.active, true)
)
);
if (fileResults.length !== allFileIds.length) {
const foundFileIds = fileResults.map(f => f.id);
const missingFileIds = allFileIds.filter(id => !foundFileIds.includes(id));
throw new Error(`Files not found in dataset: ${missingFileIds.join(', ')}`);
}
// Check if all species exist
const speciesResults = await db.select({ id: species.id })
.from(species)
.where(inArray(species.id, allSpeciesIds));
if (speciesResults.length !== allSpeciesIds.length) {
const foundSpeciesIds = speciesResults.map(s => s.id);
const missingSpeciesIds = allSpeciesIds.filter(id => !foundSpeciesIds.includes(id));
throw new Error(`Species not found: ${missingSpeciesIds.join(', ')}`);
}
// Check if all call types exist (if any specified)
if (allCallTypeIds.length > 0) {
const callTypeResults = await db.select({ id: callType.id })
.from(callType)
.where(inArray(callType.id, allCallTypeIds));