Database / Farming models

farming_model

Farming model on a land: ATM (Anytime Money) or 365 DKG. Holds crops, practices, size, photo and geofence; crops and harvests live in a JSON column.

Table factsheetagri_db
Written by
  • Data down-sync (DataSetupViewModel) and OptionViewModel (Repo.insertFarmingModelList, also sets ie_flat_entity.hasATM)
  • ATMRepositoryImp (saveATM)
  • ATM create/edit (ATMViewModel: createATM, updateFarmingModel = delete + insert)
  • Response handlers FarmingModelPostRH, FarmingModelPatch, FarmingModelGeofencingPostRH, FarmingModelHarvestPostRH, ATMPicRH
Read by
  • ATM and DKG screens
  • Land delete guard (getATMBYAsset)
Filled from
GET /gateway/portfolio-service/api/v1/farming-model/ownerEntities
GET /gateway/portfolio-service/api/v1/farming-model/attachment/bulk
Sync
appId is a client UUID primary key. syncStatus starts at SYNC_DONE for downloaded rows, becomes SYNC_NOT_INITIALIZED when the row is created or edited on the device, and goes back to SYNC_DONE when the response handler writes the server id. opId holds the id of the last queued library operation. Sync entity IE_ATM. hasSyncError/syncErrorId record the last failure.
Source
data/src/main/java/org/mindtree/app/agricultor/data/entity/FarmingModel.kt

Columns

ColumnTypeNullKeyMeaning
uuidTEXTYesIndexStable business UUID, also sent to the server. Index: unique.
appCreatedAtINTEGERYesCreated on device. Stored as INTEGER here.
idINTEGERYesServer id. Null or 0 until the row is synced.
raisedBedsINTEGERYes1 if raised beds used.
vegetableCropsTEXTYesJSON list of vegetable crops.
maizeCultivationINTEGERYes1 if maize grown.
pulseCropsTEXTYesJSON list of pulse crops.
practicesTEXTYesJSON list of practices.
relayCroppingINTEGERYes1 if relay cropping.
relayCroppingDetailsTEXTYesFree text describing relay cropping, entered when relayCropping is yes.
incomeGenerationINTEGERYes1 if income generation activity.
incomeGenerationDetailsTEXTYesFree text describing the income generation activity, entered when incomeGeneration is yes.
titleIdTEXTYesStable business key shared by all versions of the record.
owningEntityIdTEXTYesFK → ie_flat_entity.iEOLTPIdFarmer server id (= ie_flat_entity.iEOLTPId), stored as text. Link by convention only, no FK constraint.
owningEntityTypeTEXTYesOwner type, normally the farmer (IE) entity type.
aliasIdTEXTYesFK → ie.aliasIdFarmer alias, used for unsynced farmers. Link by convention only, no FK constraint.
landSizeREALYesLand size used by the model.
isDKGINTEGERYes1 for 365 DKG (renamed from dkg365).
modelTypeTEXTYesMODEL_TYPE.ATM | MODEL_TYPE.365_DKG.
assetIdINTEGERYesFK → farmerassets.idLand server id as INTEGER. Link by convention only, no FK constraint.
assetTEXTYesFK → farmerassets.idLand server id as TEXT. Link by convention only, no FK constraint.
assetCheckSumTEXTYesContent hash of a land asset. Links this row to the land before the land has a server id.
hasSyncErrorINTEGERYes1 when the last sync of this row failed.
syncErrorIdINTEGERYesFK → sync_error_logs.idPoints to sync_error_logs.id for the last failure. Link by convention only, no FK constraint.
lastModifiedAtINTEGERYesLast modified time from the server.
geoFencingFileIdINTEGERYesServer attachment id of the geofence file.
geoFencingFileNameTEXTYesFile name of the geofence polygon (KML/GeoJSON).
geoFencingCreatedOnTEXTYesWhen the geofence was captured.
geoFencingFilePathTEXTYesLocal path of the polygon file under filesDir/geofencing/.
geotaggingFileNameTEXTYesGeotag photo/file pointer for the farming model.
geotaggingCreatedOnTEXTYesGeotag photo/file pointer for the farming model.
geotaggingFilePathTEXTYesGeotag photo/file pointer for the farming model.
farmingModelLineItemDTOsTEXTYesJSON list of crops including harvest details.
imageUrlTEXTYesLocal file path of the farming model photo, or the server attachment URL after download.
imageAttachmentIdINTEGERYesServer attachment id of the photo.
imageCreatedAtTEXTYesWhen the photo was taken (epoch millis as text), or the attachment's appCreatedAt from the server.
appIdTEXTNoPKClient-side UUID. Defaults to a random UUID when the object is built, including when server JSON is parsed.
opIdTEXTYesId of the last queued operation in the library queue (SYNC_QUEUE_DB).
syncStatusTEXTNoSYNC_NOT_INITIALIZED | IN_SYNC_QUEUE | SYNC_DONE (default).

Notes

  • Renamed from portfolio_service in migration 34 to 35.
  • ATMs: owningEntityId or aliasId with modelType = MODEL_TYPE.ATM. DKG: (owningEntityId = id OR aliasId = id) AND modelType = MODEL_TYPE.365_DKG.
  • getATMBYAsset blocks deleting a land that has an ATM.
  • Possible bug · unverified harvest data lives in a JSON blob, so it cannot be queried.
  • Missing indexes on owningEntityId, aliasId, titleId and asset.