Database / Crops & portfolio

portfolio

Portfolio container: one per farmer. Holds the farmer's crop plan line items.

Table factsheetagri_db
Written by
  • Legacy setup (PortfolioDTO)
  • Data down-sync (DataSetupViewModel, UnitDataSetupViewModel, SetupForUser, SetupForUnitInChargeLogin)
  • OptionViewModel refresh
  • Create portfolio (Repo.createIEPortfolio)
  • IePortfolioRepositoryImpl
Read by
  • Portfolio screens
  • IEPortfolioMapper (copies into legacy ie_portfolio)
Filled from
POST api/setupdata/v2 (PortfolioDTO)
GET /gateway/portfolio-service/api/v1/portfolios/ownerEntities
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_PORTFOLIO.
Source
data/src/main/java/org/mindtree/app/agricultor/data/entity/Portfolio.kt

Columns

ColumnTypeNullKeyMeaning
owningEntityIdTEXTYesFK → ie_flat_entity.iEOLTPIdFarmer server id (= ie_flat_entity.iEOLTPId), stored as text. Link by convention only, no FK constraint.
idINTEGERYesServer id. Null or 0 until the row is synced.
uuidTEXTYesIndexStable business UUID, also sent to the server. Index: unique.
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).
ownerentitytype_codeTEXTYesReference data code.
ownerentitytype_refclass_codeTEXTYesReference class of the code (flattened embedded DTO).
appmill_metadata_ie_appIdTEXTYesFK → ie.appIdLocal appId of the owning farmer (ie.appId). Used to link rows before the farmer has a server id. Link by convention only, no FK constraint.

Notes

  • getIEPortfolioByIEAliasId finds portfolios of unsynced farmers by appmill_metadata_ie_appId.
  • Possible bug · unverified several queries use appId LIKE :appId (case-insensitive, skips the PK index). Use =.
  • Missing index on owningEntityId.