feat: 添加 DrugInfo 模型,包含状态常量及表映射 #2

Merged
YingmoY merged 1 commit from feat/drug/model into main 2026-03-23 02:25:14 +08:00
YingmoY commented 2026-03-23 02:18:11 +08:00 (Migrated from github.com)
No description provided.
copilot-pull-request-reviewer[bot] (Migrated from github.com) reviewed 2026-03-23 02:20:52 +08:00
copilot-pull-request-reviewer[bot] (Migrated from github.com) left a comment

Pull request overview

This PR introduces a new GORM model for representing drug master data in the drug module, including status constants and explicit table mapping.

Changes:

  • Added DrugInfo model embedding core.BaseModel with GORM/JSON tags for drug attributes.
  • Added status constants (DrugStatusDisabled, DrugStatusEnabled) for representing drug availability.
  • Implemented TableName() to map the model to the drug_info table.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

## Pull request overview This PR introduces a new GORM model for representing drug master data in the drug module, including status constants and explicit table mapping. **Changes:** - Added `DrugInfo` model embedding `core.BaseModel` with GORM/JSON tags for drug attributes. - Added status constants (`DrugStatusDisabled`, `DrugStatusEnabled`) for representing drug availability. - Implemented `TableName()` to map the model to the `drug_info` table. --- 💡 <a href="/YingmoY/PharmacyERP/new/main?filename=.github/instructions/*.instructions.md" class="Link--inTextBlock" target="_blank" rel="noopener noreferrer">Add Copilot custom instructions</a> for smarter, more guided reviews. <a href="https://docs.github.com/en/copilot/customizing-copilot/adding-repository-custom-instructions-for-github-copilot" class="Link--inTextBlock" target="_blank" rel="noopener noreferrer">Learn how to get started</a>.
@ -0,0 +18,4 @@
Specification string `gorm:"column:specification;size:50;not null" json:"specification"`
DosageForm string `gorm:"column:dosage_form;size:50" json:"dosage_form"`
Manufacturer string `gorm:"column:manufacturer;size:100;not null" json:"manufacturer"`
ApprovalNumber string `gorm:"column:approval_number;size:50" json:"approval_number"`
copilot-pull-request-reviewer[bot] (Migrated from github.com) commented 2026-03-23 02:20:52 +08:00

TradeName/DosageForm/ApprovalNumber are defined as non-pointer strings but do not declare not null. In Postgres, a nullable VARCHAR column that ever contains NULL will fail to scan into a Go string (database/sql can’t convert NULL to string). Either mark these columns not null (optionally with a default empty string) or change the Go fields to *string/sql.NullString to match nullable semantics.

	TradeName      string `gorm:"column:trade_name;size:100;not null;default:''" json:"trade_name"`
	Specification  string `gorm:"column:specification;size:50;not null" json:"specification"`
	DosageForm     string `gorm:"column:dosage_form;size:50;not null;default:''" json:"dosage_form"`
	Manufacturer   string `gorm:"column:manufacturer;size:100;not null" json:"manufacturer"`
	ApprovalNumber string `gorm:"column:approval_number;size:50;not null;default:''" json:"approval_number"`
TradeName/DosageForm/ApprovalNumber are defined as non-pointer strings but do not declare `not null`. In Postgres, a nullable VARCHAR column that ever contains NULL will fail to scan into a Go `string` (database/sql can’t convert NULL to string). Either mark these columns `not null` (optionally with a default empty string) or change the Go fields to `*string`/`sql.NullString` to match nullable semantics. ```suggestion TradeName string `gorm:"column:trade_name;size:100;not null;default:''" json:"trade_name"` Specification string `gorm:"column:specification;size:50;not null" json:"specification"` DosageForm string `gorm:"column:dosage_form;size:50;not null;default:''" json:"dosage_form"` Manufacturer string `gorm:"column:manufacturer;size:100;not null" json:"manufacturer"` ApprovalNumber string `gorm:"column:approval_number;size:50;not null;default:''" json:"approval_number"` ```
@ -0,0 +21,4 @@
ApprovalNumber string `gorm:"column:approval_number;size:50" json:"approval_number"`
IsPrescription bool `gorm:"column:is_prescription;default:false" json:"is_prescription"`
IsMedicare bool `gorm:"column:is_medicare;default:false" json:"is_medicare"`
Status int8 `gorm:"column:status;default:1" json:"status"`
copilot-pull-request-reviewer[bot] (Migrated from github.com) commented 2026-03-23 02:20:52 +08:00

IsPrescription/IsMedicare/Status are non-pointer scalar types but the GORM tags don’t specify not null. If the DB schema allows NULL (e.g., via manual SQL, partial updates, or migrations), queries can fail scanning NULL into bool/int8. Consider adding not null alongside the defaults to enforce data integrity at the schema level.

	IsPrescription bool   `gorm:"column:is_prescription;default:false;not null" json:"is_prescription"`
	IsMedicare     bool   `gorm:"column:is_medicare;default:false;not null" json:"is_medicare"`
	Status         int8   `gorm:"column:status;default:1;not null" json:"status"`
IsPrescription/IsMedicare/Status are non-pointer scalar types but the GORM tags don’t specify `not null`. If the DB schema allows NULL (e.g., via manual SQL, partial updates, or migrations), queries can fail scanning NULL into `bool`/`int8`. Consider adding `not null` alongside the defaults to enforce data integrity at the schema level. ```suggestion IsPrescription bool `gorm:"column:is_prescription;default:false;not null" json:"is_prescription"` IsMedicare bool `gorm:"column:is_medicare;default:false;not null" json:"is_medicare"` Status int8 `gorm:"column:status;default:1;not null" json:"status"` ```
Sign in to join this conversation.
No description provided.