changes on agent

This commit is contained in:
2026-08-31 12:33:10 +05:30
parent 76554d26e5
commit ffc66462fc
9 changed files with 715 additions and 25 deletions

55
main.go
View File

@@ -102,6 +102,61 @@ func main() {
log.Fatal("could not backfill productlocations.publishedat:", err)
}
// Receipts for spreadsheets sent to the catalogue ingest service.
//
// The ingest service holds a drop on its own terms: an unreviewed one is
// deleted after seven days, the list of a sender's drops needs a credential
// production does not issue, and the batch id — which is the ONLY
// credential for reading a result back — is handed out once, to a browser.
// Lose it and the upload becomes unfindable even to the person who sent it.
// This table is where we keep it.
//
// Raw SQL rather than AutoMigrate, matching the two ALTERs above: GORM
// reconciling a model against a live table has rewritten more than was
// asked for here before, and `IF NOT EXISTS` makes this a no-op after the
// first boot.
if err := db.DB.Exec(`
CREATE TABLE IF NOT EXISTS catalogueuploads (
uploadid SERIAL PRIMARY KEY,
tenantid INT NOT NULL,
locationid INT NOT NULL DEFAULT 0,
categoryid INT NOT NULL DEFAULT 0,
batchid VARCHAR(64) NOT NULL,
runid VARCHAR(64),
filename TEXT,
sender TEXT,
uploadedby INT NOT NULL DEFAULT 0,
uploadedname TEXT,
rowcount INT NOT NULL DEFAULT 0,
laststatus VARCHAR(32) NOT NULL DEFAULT 'pending',
inserted INT NOT NULL DEFAULT 0,
backfilled INT NOT NULL DEFAULT 0,
skipped INT NOT NULL DEFAULT 0,
rejected INT NOT NULL DEFAULT 0,
shelvedcount INT NOT NULL DEFAULT 0,
skippedcount INT NOT NULL DEFAULT 0,
shelvedat TIMESTAMP,
created TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
updated TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP
)`).Error; err != nil {
log.Fatal("could not create catalogueuploads:", err)
}
// The upload is recorded the instant the drop is accepted and then polled,
// so a refresh, a retried request or a second tab would each insert the same
// receipt again. The constraint is what makes `Record` idempotent — without
// it one upload shows up three times and none of them is wrong.
if err := db.DB.Exec(
`CREATE UNIQUE INDEX IF NOT EXISTS catalogueuploads_batchid_key
ON catalogueuploads (batchid)`).Error; err != nil {
log.Fatal("could not add catalogueuploads.batchid unique index:", err)
}
// Every read is "this shop's uploads, newest first".
if err := db.DB.Exec(
`CREATE INDEX IF NOT EXISTS catalogueuploads_scope_idx
ON catalogueuploads (tenantid, locationid, created DESC)`).Error; err != nil {
log.Println("⚠️ could not add catalogueuploads scope index:", err)
}
f := facade.NewFacade(db.DB, db.CatalogueDB)
routes.RegisterRoutes(app, f)