From 58ef9deaa906f1252f7830e2ea4a31880183fb8f Mon Sep 17 00:00:00 2001 From: Sharad S Date: Tue, 22 Oct 2024 11:51:16 -0400 Subject: [PATCH] Add changes for COG -> children --- .../js_src/lib/components/DataModel/types.ts | 168 +++++++++--------- specifyweb/specify/datamodel.py | 4 +- .../migrations/0007_schema_config_update.py | 35 ++-- specifyweb/specify/models.py | 2 +- 4 files changed, 113 insertions(+), 96 deletions(-) diff --git a/specifyweb/frontend/js_src/lib/components/DataModel/types.ts b/specifyweb/frontend/js_src/lib/components/DataModel/types.ts index 9617ddc85c0..bd48e39f985 100644 --- a/specifyweb/frontend/js_src/lib/components/DataModel/types.ts +++ b/specifyweb/frontend/js_src/lib/components/DataModel/types.ts @@ -242,20 +242,20 @@ export type Tables = { export type Accession = { readonly tableName: 'Accession'; readonly fields: { - readonly accessionNumber: string; readonly accessionCondition: string | null; - readonly dateAccessioned: string | null; + readonly accessionNumber: string; readonly actualTotalCountAmt: number | null; readonly collectionObjectCount: number | null; + readonly dateAccessioned: string | null; readonly dateAcknowledged: string | null; - readonly remarks: string | null; + readonly dateReceived: string | null; readonly integer1: number | null; readonly integer2: number | null; readonly integer3: number | null; readonly number1: number | null; readonly number2: number | null; readonly preparationCount: number | null; - readonly dateReceived: string | null; + readonly remarks: string | null; readonly status: string | null; readonly text1: string | null; readonly text2: string | null; @@ -461,10 +461,10 @@ export type Agent = { readonly initials: string | null; readonly integer1: number | null; readonly integer2: number | null; + readonly interests: string | null; readonly jobTitle: string | null; readonly lastName: string | null; readonly middleInitial: string | null; - readonly interests: string | null; readonly remarks: string | null; readonly suffix: string | null; readonly text1: string | null; @@ -497,8 +497,8 @@ export type Agent = { readonly agentAttachments: RA; readonly agentGeographies: RA; readonly agentSpecialties: RA; - readonly identifiers: RA; readonly groups: RA; + readonly identifiers: RA; readonly variants: RA; }; readonly toManyIndependent: { @@ -646,7 +646,6 @@ export type Attachment = { readonly fields: { readonly attachmentLocation: string | null; readonly attachmentStorageConfig: string | null; - readonly captureDevice: string | null; readonly copyrightDate: string | null; readonly copyrightHolder: string | null; readonly credit: string | null; @@ -663,6 +662,7 @@ export type Attachment = { readonly scopeID: number | null; readonly scopeType: number | null; readonly subjectOrientation: string | null; + readonly captureDevice: string | null; readonly subtype: string | null; readonly tableID: number | null; readonly timestampCreated: string; @@ -929,13 +929,13 @@ export type BorrowMaterial = { readonly tableName: 'BorrowMaterial'; readonly fields: { readonly collectionMemberId: number; + readonly description: string | null; readonly inComments: string | null; readonly materialNumber: string; readonly outComments: string | null; readonly quantity: number | null; readonly quantityResolved: number | null; readonly quantityReturned: number | null; - readonly description: string | null; readonly text1: string | null; readonly text2: string | null; readonly timestampCreated: string; @@ -977,24 +977,26 @@ export type BorrowReturnMaterial = { export type CollectingEvent = { readonly tableName: 'CollectingEvent'; readonly fields: { - readonly startDate: string | null; + readonly stationFieldNumber: string | null; + readonly timestampCreated: string; + readonly remarks: string | null; readonly endDate: string | null; readonly endDatePrecision: number | null; readonly endDateVerbatim: string | null; readonly endTime: number | null; - readonly stationFieldNumber: string | null; - readonly method: string | null; readonly guid: string | null; readonly integer1: number | null; readonly integer2: number | null; - readonly remarks: string | null; + readonly verbatimDate: string | null; + readonly method: string | null; + readonly timestampModified: string | null; readonly reservedInteger3: number | null; readonly reservedInteger4: number | null; readonly reservedText1: string | null; readonly reservedText2: string | null; readonly sgrStatus: number | null; + readonly startDate: string | null; readonly startDatePrecision: number | null; - readonly startDateVerbatim: string | null; readonly startTime: number | null; readonly stationFieldNumberModifier1: string | null; readonly stationFieldNumberModifier2: string | null; @@ -1007,10 +1009,8 @@ export type CollectingEvent = { readonly text6: string | null; readonly text7: string | null; readonly text8: string | null; - readonly timestampCreated: string; - readonly timestampModified: string | null; readonly uniqueIdentifier: string | null; - readonly verbatimDate: string | null; + readonly startDateVerbatim: string | null; readonly verbatimLocality: string | null; readonly version: number | null; readonly visibility: number | null; @@ -1022,8 +1022,8 @@ export type CollectingEvent = { readonly collectingTrip: CollectingTrip | null; readonly createdByAgent: Agent | null; readonly discipline: Discipline; - readonly locality: Locality | null; readonly modifiedByAgent: Agent | null; + readonly locality: Locality | null; readonly paleoContext: PaleoContext | null; readonly visibilitySetBy: SpecifyUser | null; }; @@ -1079,10 +1079,14 @@ export type CollectingEventAttr = { export type CollectingEventAttribute = { readonly tableName: 'CollectingEventAttribute'; readonly fields: { - readonly text8: string | null; - readonly text5: string | null; + readonly number6: number | null; + readonly text6: string | null; + readonly number4: number | null; readonly text4: string | null; + readonly number8: number | null; + readonly text8: string | null; readonly text9: string | null; + readonly text17: string | null; readonly integer1: number | null; readonly integer10: number | null; readonly integer2: number | null; @@ -1093,36 +1097,32 @@ export type CollectingEventAttribute = { readonly integer7: number | null; readonly integer8: number | null; readonly integer9: number | null; - readonly number12: number | null; - readonly number13: number | null; readonly number1: number | null; readonly number10: number | null; readonly number11: number | null; - readonly number2: number | null; - readonly number3: number | null; - readonly number4: number | null; - readonly number5: number | null; - readonly number6: number | null; - readonly number7: number | null; - readonly number8: number | null; + readonly number12: number | null; + readonly number13: number | null; readonly number9: number | null; + readonly number3: number | null; + readonly text3: string | null; readonly remarks: string | null; - readonly text6: string | null; - readonly text1: string | null; + readonly number5: number | null; + readonly text5: string | null; readonly text10: string | null; readonly text11: string | null; - readonly text13: string | null; + readonly text12: string | null; readonly text14: string | null; readonly text15: string | null; readonly text16: string | null; - readonly text17: string | null; - readonly text2: string | null; - readonly text7: string | null; readonly timestampCreated: string; readonly timestampModified: string | null; - readonly text12: string | null; + readonly number7: number | null; + readonly text7: string | null; + readonly text13: string | null; + readonly text1: string | null; readonly version: number | null; - readonly text3: string | null; + readonly number2: number | null; + readonly text2: string | null; readonly yesNo1: boolean | null; readonly yesNo2: boolean | null; readonly yesNo3: boolean | null; @@ -1133,8 +1133,8 @@ export type CollectingEventAttribute = { readonly toOneIndependent: { readonly createdByAgent: Agent | null; readonly discipline: Discipline; - readonly hostTaxon: Taxon | null; readonly modifiedByAgent: Agent | null; + readonly hostTaxon: Taxon | null; }; readonly toManyDependent: RR; readonly toManyIndependent: { @@ -1163,7 +1163,6 @@ export type CollectingTrip = { readonly tableName: 'CollectingTrip'; readonly fields: { readonly cruise: string | null; - readonly text2: string | null; readonly date1: string | null; readonly date1Precision: number | null; readonly date2: string | null; @@ -1181,6 +1180,8 @@ export type CollectingTrip = { readonly startDatePrecision: number | null; readonly startDateVerbatim: string | null; readonly startTime: number | null; + readonly text1: string | null; + readonly text2: string | null; readonly text3: string | null; readonly text4: string | null; readonly text5: string | null; @@ -1192,7 +1193,6 @@ export type CollectingTrip = { readonly timestampModified: string | null; readonly collectingTripName: string | null; readonly version: number | null; - readonly text1: string | null; readonly vessel: string | null; readonly yesNo1: boolean | null; readonly yesNo2: boolean | null; @@ -1370,15 +1370,15 @@ export type CollectionObject = { readonly fields: { readonly actualTotalCountAmt: number | null; readonly age: number | null; + readonly altCatalogNumber: string | null; readonly availability: string | null; - readonly catalogNumber: string | null; readonly catalogedDate: string | null; readonly catalogedDatePrecision: number | null; readonly catalogedDateVerbatim: string | null; + readonly text1: string | null; readonly collectionMemberId: number; readonly countAmt: number | null; - readonly reservedText: string | null; - readonly timestampModified: string | null; + readonly timestampCreated: string; readonly date1: string | null; readonly date1Precision: number | null; readonly deaccessioned: boolean | null; @@ -1387,12 +1387,13 @@ export type CollectionObject = { readonly embargoReleaseDatePrecision: number | null; readonly embargoStartDate: string | null; readonly embargoStartDatePrecision: number | null; + readonly fieldNumber: string | null; readonly guid: string | null; readonly integer1: number | null; readonly integer2: number | null; - readonly text2: string | null; readonly inventoryDate: string | null; readonly inventoryDatePrecision: number | null; + readonly timestampModified: string | null; readonly modifier: string | null; readonly name: string | null; readonly notifications: string | null; @@ -1401,30 +1402,29 @@ export type CollectionObject = { readonly number2: number | null; readonly objectCondition: string | null; readonly ocr: string | null; - readonly altCatalogNumber: string | null; readonly projectNumber: string | null; readonly remarks: string | null; readonly reservedInteger3: number | null; readonly reservedInteger4: number | null; + readonly reservedText: string | null; readonly reservedText2: string | null; readonly reservedText3: string | null; readonly restrictions: string | null; readonly sgrStatus: number | null; - readonly text1: string | null; readonly description: string | null; + readonly catalogNumber: string | null; + readonly text2: string | null; readonly text3: string | null; readonly text4: string | null; readonly text5: string | null; readonly text6: string | null; readonly text7: string | null; readonly text8: string | null; - readonly timestampCreated: string; readonly totalCountAmt: number | null; readonly totalValue: number | null; readonly uniqueIdentifier: string | null; readonly version: number | null; readonly visibility: number | null; - readonly fieldNumber: string | null; readonly yesNo1: boolean | null; readonly yesNo2: boolean | null; readonly yesNo3: boolean | null; @@ -1440,17 +1440,17 @@ export type CollectionObject = { readonly agent1: Agent | null; readonly appraisal: Appraisal | null; readonly cataloger: Agent | null; + readonly collectingEvent: CollectingEvent | null; readonly collection: Collection; readonly collectionObjectType: CollectionObjectType; readonly container: Container | null; readonly containerOwner: Container | null; readonly createdByAgent: Agent | null; readonly currentDetermination: Determination | null; - readonly modifiedByAgent: Agent | null; readonly embargoAuthority: Agent | null; - readonly collectingEvent: CollectingEvent | null; readonly fieldNotebookPage: FieldNotebookPage | null; readonly inventorizedBy: Agent | null; + readonly modifiedByAgent: Agent | null; readonly paleoContext: PaleoContext | null; readonly visibilitySetBy: SpecifyUser | null; }; @@ -1533,11 +1533,12 @@ export type CollectionObjectAttribute = { readonly integer7: number | null; readonly integer8: number | null; readonly integer9: number | null; - readonly number12: number | null; - readonly number13: number | null; + readonly text3: string | null; readonly number1: number | null; readonly number10: number | null; readonly number11: number | null; + readonly number12: number | null; + readonly number13: number | null; readonly number14: number | null; readonly number15: number | null; readonly number16: number | null; @@ -1575,14 +1576,15 @@ export type CollectionObjectAttribute = { readonly number7: number | null; readonly number8: number | null; readonly number9: number | null; - readonly text13: string | null; - readonly text14: string | null; readonly text1: string | null; readonly positionState: string | null; - readonly text10: string | null; readonly remarks: string | null; - readonly text8: string | null; + readonly text10: string | null; + readonly text12: string | null; + readonly text4: string | null; readonly text11: string | null; + readonly text13: string | null; + readonly text14: string | null; readonly text15: string | null; readonly text16: string | null; readonly text17: string | null; @@ -1598,7 +1600,6 @@ export type CollectionObjectAttribute = { readonly text27: string | null; readonly text28: string | null; readonly text29: string | null; - readonly text3: string | null; readonly text30: string | null; readonly text31: string | null; readonly text32: string | null; @@ -1609,15 +1610,14 @@ export type CollectionObjectAttribute = { readonly text37: string | null; readonly text38: string | null; readonly text39: string | null; - readonly text4: string | null; readonly text40: string | null; readonly text5: string | null; readonly text6: string | null; readonly text7: string | null; + readonly text8: string | null; readonly text9: string | null; readonly timestampCreated: string; readonly timestampModified: string | null; - readonly text12: string | null; readonly topDistance: number | null; readonly version: number | null; readonly text2: string | null; @@ -2194,9 +2194,7 @@ export type DNASequence = { readonly compT: number | null; readonly extractionDate: string | null; readonly extractionDatePrecision: number | null; - readonly text2: string | null; readonly genbankAccessionNumber: string | null; - readonly text1: string | null; readonly geneSequence: string | null; readonly moleculeType: string | null; readonly number1: number | null; @@ -2206,6 +2204,8 @@ export type DNASequence = { readonly sequenceDate: string | null; readonly sequenceDatePrecision: number | null; readonly targetMarker: string | null; + readonly text1: string | null; + readonly text2: string | null; readonly text3: string | null; readonly timestampCreated: string; readonly timestampModified: string | null; @@ -2298,8 +2298,8 @@ export type DNASequencingRun = { readonly runByAgent: Agent | null; }; readonly toManyDependent: { - readonly citations: RA; readonly attachments: RA; + readonly citations: RA; }; readonly toManyIndependent: RR; }; @@ -2467,7 +2467,6 @@ export type Determination = { readonly determinedDatePrecision: number | null; readonly featureOrBasis: string | null; readonly guid: string | null; - readonly yesNo1: boolean | null; readonly integer1: number | null; readonly integer2: number | null; readonly integer3: number | null; @@ -2480,11 +2479,10 @@ export type Determination = { readonly number3: number | null; readonly number4: number | null; readonly number5: number | null; + readonly text2: string | null; readonly qualifier: string | null; readonly remarks: string | null; readonly subSpQualifier: string | null; - readonly text1: string | null; - readonly text2: string | null; readonly text3: string | null; readonly text4: string | null; readonly text5: string | null; @@ -2494,8 +2492,10 @@ export type Determination = { readonly timestampCreated: string; readonly timestampModified: string | null; readonly typeStatusName: string | null; + readonly text1: string | null; readonly varQualifier: string | null; readonly version: number | null; + readonly yesNo1: boolean | null; readonly yesNo2: boolean | null; readonly yesNo3: boolean | null; readonly yesNo4: boolean | null; @@ -3105,8 +3105,6 @@ export type GeoCoordDetail = { readonly integer3: number | null; readonly integer4: number | null; readonly integer5: number | null; - readonly maxUncertaintyEst: number | null; - readonly maxUncertaintyEstUnit: string | null; readonly namedPlaceExtent: number | null; readonly noGeoRefBecause: string | null; readonly number1: number | null; @@ -3125,6 +3123,8 @@ export type GeoCoordDetail = { readonly timestampCreated: string; readonly timestampModified: string | null; readonly uncertaintyPolygon: string | null; + readonly maxUncertaintyEst: number | null; + readonly maxUncertaintyEstUnit: string | null; readonly validation: string | null; readonly version: number | null; readonly yesNo1: boolean | null; @@ -3347,8 +3347,8 @@ export type Gift = { readonly srcTaxonomy: string | null; readonly specialConditions: string | null; readonly status: string | null; - readonly text2: string | null; readonly text1: string | null; + readonly text2: string | null; readonly text3: string | null; readonly text4: string | null; readonly text5: string | null; @@ -3717,7 +3717,6 @@ export type Loan = { readonly dateClosed: string | null; readonly dateReceived: string | null; readonly yesNo1: boolean | null; - readonly text2: string | null; readonly integer1: number | null; readonly integer2: number | null; readonly integer3: number | null; @@ -3739,6 +3738,7 @@ export type Loan = { readonly specialConditions: string | null; readonly status: string | null; readonly text1: string | null; + readonly text2: string | null; readonly text3: string | null; readonly text4: string | null; readonly text5: string | null; @@ -3864,8 +3864,10 @@ export type LoanReturnPreparation = { export type Locality = { readonly tableName: 'Locality'; readonly fields: { + readonly timestampCreated: string; readonly datum: string | null; readonly elevationAccuracy: number | null; + readonly elevationMethod: string | null; readonly gml: string | null; readonly guid: string | null; readonly latLongMethod: string | null; @@ -3882,8 +3884,8 @@ export type Locality = { readonly longitude2: number | null; readonly maxElevation: number | null; readonly minElevation: number | null; + readonly timestampModified: string | null; readonly namedPlace: string | null; - readonly originalElevationUnit: string | null; readonly originalLatLongUnit: number | null; readonly relationToNamedPlace: string | null; readonly remarks: string | null; @@ -3895,15 +3897,13 @@ export type Locality = { readonly text3: string | null; readonly text4: string | null; readonly text5: string | null; - readonly timestampCreated: string; - readonly timestampModified: string | null; readonly uniqueIdentifier: string | null; + readonly originalElevationUnit: string | null; readonly verbatimElevation: string | null; readonly verbatimLatitude: string | null; readonly verbatimLongitude: string | null; readonly version: number | null; readonly visibility: number | null; - readonly elevationMethod: string | null; readonly yesNo1: boolean | null; readonly yesNo2: boolean | null; readonly yesNo3: boolean | null; @@ -3917,8 +3917,8 @@ export type Locality = { readonly toOneIndependent: { readonly createdByAgent: Agent | null; readonly discipline: Discipline; - readonly geography: Geography | null; readonly modifiedByAgent: Agent | null; + readonly geography: Geography | null; readonly paleoContext: PaleoContext | null; readonly visibilitySetBy: SpecifyUser | null; }; @@ -4177,7 +4177,6 @@ export type OtherIdentifier = { export type PaleoContext = { readonly tableName: 'PaleoContext'; readonly fields: { - readonly text1: string | null; readonly paleoContextName: string | null; readonly number1: number | null; readonly number2: number | null; @@ -4185,6 +4184,7 @@ export type PaleoContext = { readonly number4: number | null; readonly number5: number | null; readonly remarks: string | null; + readonly text1: string | null; readonly text2: string | null; readonly text3: string | null; readonly text4: string | null; @@ -4398,10 +4398,12 @@ export type Preparation = { readonly sampleNumber: string | null; readonly status: string | null; readonly storageLocation: string | null; + readonly text1: string | null; readonly text10: string | null; readonly text11: string | null; readonly text12: string | null; readonly text13: string | null; + readonly text2: string | null; readonly text3: string | null; readonly text4: string | null; readonly text5: string | null; @@ -4411,10 +4413,8 @@ export type Preparation = { readonly text9: string | null; readonly timestampCreated: string; readonly timestampModified: string | null; - readonly text1: string | null; - readonly yesNo1: boolean | null; readonly version: number | null; - readonly text2: string | null; + readonly yesNo1: boolean | null; readonly yesNo2: boolean | null; readonly yesNo3: boolean | null; }; @@ -4791,10 +4791,7 @@ export type RecordSetItem = { export type ReferenceWork = { readonly tableName: 'ReferenceWork'; readonly fields: { - readonly text1: string | null; - readonly workDate: string | null; readonly doi: string | null; - readonly text2: string | null; readonly guid: string | null; readonly isPublished: boolean | null; readonly isbn: string | null; @@ -4805,6 +4802,8 @@ export type ReferenceWork = { readonly placeOfPublication: string | null; readonly publisher: string | null; readonly remarks: string | null; + readonly text1: string | null; + readonly text2: string | null; readonly timestampCreated: string; readonly timestampModified: string | null; readonly title: string; @@ -4813,6 +4812,7 @@ export type ReferenceWork = { readonly url: string | null; readonly version: number | null; readonly volume: string | null; + readonly workDate: string | null; readonly yesNo1: boolean | null; readonly yesNo2: boolean | null; }; @@ -4910,9 +4910,9 @@ export type RepositoryAgreementAttachment = { export type Shipment = { readonly tableName: 'Shipment'; readonly fields: { - readonly numberOfPackages: number | null; readonly insuredForAmount: string | null; readonly shipmentMethod: string | null; + readonly numberOfPackages: number | null; readonly number1: number | null; readonly number2: number | null; readonly remarks: string | null; @@ -5626,6 +5626,7 @@ export type Taxon = { readonly colStatus: string | null; readonly commonName: string | null; readonly cultivarName: string | null; + readonly environmentalProtectionStatus: string | null; readonly esaStatus: string | null; readonly fullName: string | null; readonly groupNumber: string | null; @@ -5649,7 +5650,6 @@ export type Taxon = { readonly number3: number | null; readonly number4: number | null; readonly number5: number | null; - readonly environmentalProtectionStatus: string | null; readonly rankId: number; readonly remarks: string | null; readonly source: string | null; @@ -6519,7 +6519,9 @@ export type CollectionObjectGroup = { readonly modifiedByAgent: Agent | null; readonly parentCojo: CollectionObjectGroupJoin | null; }; - readonly toManyDependent: { readonly cojo: RA }; + readonly toManyDependent: { + readonly children: RA; + }; readonly toManyIndependent: RR; }; export type CollectionObjectGroupJoin = { diff --git a/specifyweb/specify/datamodel.py b/specifyweb/specify/datamodel.py index 0c1f47690e0..b445e89b28a 100644 --- a/specifyweb/specify/datamodel.py +++ b/specifyweb/specify/datamodel.py @@ -8297,7 +8297,7 @@ Relationship(name='collection', type='many-to-one', required=False, relatedModelName='Collection', column='CollectionID'), Relationship(name='cogType', type='many-to-one', required=True, relatedModelName='CollectionObjectGroupType', column='COGTypeID'), Relationship(name='parentCojo', type='many-to-one', required=False, relatedModelName='CollectionObjectGroupJoin',column='CollectionObjectGroupJoinID', otherSideName='collectionobjectgroup'), - Relationship(name='cojo', type='one-to-many', required=False, relatedModelName='CollectionObjectGroupJoin', otherSideName='childCog', dependent=True), + Relationship(name='children', type='one-to-many', required=False, dependent=True, relatedModelName='CollectionObjectGroupJoin', otherSideName='parentCog'), Relationship(name='createdByAgent', type='many-to-one', required=False, relatedModelName='Agent', column='CreatedByAgentID'), Relationship(name='modifiedByAgent', type='many-to-one', required=False, relatedModelName='Agent', column='ModifiedByAgentID'), ], @@ -8335,7 +8335,7 @@ ], relationships=[ - Relationship(name='parentCog', type='many-to-one', required=True, relatedModelName='CollectionObjectGroup', column='ParentCOGID', otherSideName='parentcojos'), + Relationship(name='parentCog', type='many-to-one', required=True, relatedModelName='CollectionObjectGroup', column='ParentCOGID', otherSideName='children'), Relationship(name='childCog', type='one-to-one', required=False, relatedModelName='CollectionObjectGroup', column='ChildCOGID', otherSideName='cojo'), Relationship(name='childCo', type='one-to-one', required=False, relatedModelName='CollectionObject', column='ChildCOID', otherSideName='cojo'), Relationship(name='collectionobjectgroup', type='one-to-many',required=False, relatedModelName='CollectionObjectGroup', otherSideName='parentCojo'), diff --git a/specifyweb/specify/migrations/0007_schema_config_update.py b/specifyweb/specify/migrations/0007_schema_config_update.py index ed2ff699d12..5d84cdff976 100644 --- a/specifyweb/specify/migrations/0007_schema_config_update.py +++ b/specifyweb/specify/migrations/0007_schema_config_update.py @@ -1,15 +1,20 @@ """ -This migration updates the Schema Config entries for pre-geo tables and creates picklists for COGTypes. +This migration updates the data model for COG and Schema Config entries for pre-geo tables and creates picklists for COGTypes. -Fields added: -StorageTreeDef -> institution +Data model changes: +Removed COG -> cojo +Added COG -> children -Fields removed: -CollectionObject -> collectionObjectType (duplicate) +Schema Config changes: +Added StorageTreeDef -> institution +Added COG -> children +Removed CollectionObject -> collectionObjectType (duplicate) +Removed COG -> cojo Creates a picklist for COGType -> type and updates an existing incorrect picklist for COG -> COGType """ -from django.db import migrations +from django.db import migrations, models +import django.db.models.deletion from specifyweb.specify.update_schema_config import revert_table_field_schema_config, update_table_field_schema_config_with_defaults PICKLIST_NAME = 'COGTypes' @@ -20,10 +25,14 @@ def update_fields(apps): Discipline = apps.get_model('specify', 'Discipline') Splocalecontaineritem = apps.get_model('specify', 'Splocalecontaineritem') Splocaleitemstr = apps.get_model('specify', 'Splocaleitemstr') - - # Add StorageTreeDef -> institution + + # Add StorageTreeDef -> institution and COG -> children for discipline in Discipline.objects.all(): update_table_field_schema_config_with_defaults('StorageTreeDef', discipline.id, 'institution', apps) + update_table_field_schema_config_with_defaults('CollectionObjectGroup', discipline.id, 'children', apps) + + # Remove COG -> cojo + revert_table_field_schema_config('CollectionObjectGroup', 'cojo', apps) # Remove duplicate CollectionObject -> collectionObjectType container_items = Splocalecontaineritem.objects.filter(name='collectionObjectType', picklistname=None, container__name='CollectionObject') @@ -32,10 +41,11 @@ def update_fields(apps): Splocaleitemstr.objects.filter(itemdesc=container_item).delete() container_items.delete() -# NOTE: The reverse function will not re-add the duplicate CO -> coType as its unnecessary +# NOTE: The reverse function will not re-add the duplicate CO -> coType or COG -> cojo as its unnecessary def revert_update_fields(apps): - # Remove StorageTreeDef -> institution + # Remove StorageTreeDef -> institution and COG -> children revert_table_field_schema_config('StorageTreeDef', 'institution', apps) + revert_table_field_schema_config('CollectionObjectGroup', 'children', apps) def create_cogtype_picklist(apps): Collection = apps.get_model('specify', 'Collection') @@ -136,5 +146,10 @@ def revert_migration(apps, schema_editor): revert_cogtype_type_splocalecontaineritem(apps) operations = [ + migrations.AlterField( + model_name='collectionobjectgroupjoin', + name='parentcog', + field=models.ForeignKey(db_column='ParentCOGID', on_delete=django.db.models.deletion.CASCADE, related_name='children', to='specify.collectionobjectgroup'), + ), migrations.RunPython(apply_migration, revert_migration, atomic=True) ] \ No newline at end of file diff --git a/specifyweb/specify/models.py b/specifyweb/specify/models.py index d4830a119a2..cd219404848 100644 --- a/specifyweb/specify/models.py +++ b/specifyweb/specify/models.py @@ -7605,7 +7605,7 @@ class Collectionobjectgroupjoin(models.Model): # aka. CoJo or CogJoin yesno3 = models.BooleanField(blank=True, null=True, unique=False, db_column='YesNo3', db_index=False) # Relationships: Many-to-One - parentcog = models.ForeignKey('CollectionObjectGroup', db_column='ParentCOGID', related_name='parentcojos', null=False, on_delete=models.CASCADE) + parentcog = models.ForeignKey('CollectionObjectGroup', db_column='ParentCOGID', related_name='children', null=False, on_delete=models.CASCADE) # Relationships: One-to-One childcog = models.OneToOneField('CollectionObjectGroup', db_column='ChildCOGID', related_name='cojo', null=True, on_delete=models.CASCADE)