Skip to content

CROSSLINK-291 Add migration endpoints - #739

Open
JanisSaldabols wants to merge 1 commit into
mainfrom
CROSSLINK-291
Open

CROSSLINK-291 Add migration endpoints#739
JanisSaldabols wants to merge 1 commit into
mainfrom
CROSSLINK-291

Conversation

@JanisSaldabols

Copy link
Copy Markdown
Collaborator

No description provided.

Copilot AI balanced review requested due to automatic review settings August 28, 2026 05:40

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds NDJSON migration imports for patron requests, templates, and scheduled batch actions.

Changes:

  • Adds /import with conflict policies and per-record results.
  • Adds transactional persistence, validation, and state normalization.
  • Adds schema constraints, code generation, and tests.

Reviewed changes

Copilot reviewed 21 out of 26 changed files in this pull request and generated 9 comments.

Show a summary per file
File Description
.gitignore Ignores worktrees.
broker/Makefile Integrates generators.
broker/app/app.go Wires import API.
broker/import/api/api_handler.go Handles import requests.
broker/import/api/api_handler_test.go Tests HTTP behavior.
broker/import/db/import_db_gen.go Generated DB interface.
broker/import/db/import_models_gen.go Generated DB models.
broker/import/db/import_query.sql_gen.go Generated import queries.
broker/import/db/models.go Defines import contracts.
broker/import/db/patron_request_test.go Tests aggregate imports.
broker/import/db/policy_test.go Tests conflict policies.
broker/import/db/repo.go Implements transactional imports.
broker/import/db/repo_test.go Tests repository helpers.
broker/import/oapi/import_openapi_gen.go Generated import API.
broker/import/service/importer.go Decodes and normalizes records.
broker/import/service/importer_test.go Tests import processing.
broker/migrations/059_add_uniq_template_and_task.down.sql Reverts constraints.
broker/migrations/059_add_uniq_template_and_task.up.sql Adds uniqueness enforcement.
broker/oapi/cfg.yaml Excludes import from main generation.
broker/oapi/import-cfg.yaml Configures import generation.
broker/oapi/open-api.yaml Defines import schemas and endpoint.
broker/oapi/overlay.yaml Adds generated Go type overrides.
broker/patron_request/service/statemodel.go Validates imported states.
broker/patron_request/service/statemodel_test.go Tests state validation.
broker/sqlc/import_query.sql Defines import SQL operations.
broker/sqlc/sqlc.yaml Configures import SQL generation.
Files not reviewed (4)
  • broker/import/db/import_db_gen.go: Generated file
  • broker/import/db/import_models_gen.go: Generated file
  • broker/import/db/import_query.sql_gen.go: Generated file
  • broker/import/oapi/import_openapi_gen.go: Generated file

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread broker/app/app.go
})
psoapi.HandlerFromMux(&ctx.PsApiHandler, ServeMux)
schedoapi.HandlerFromMux(&ctx.SchedApiHandler, ServeMux)
importoapi.HandlerFromMux(&ctx.ImportApiHandler, ServeMux)
if owner == "" {
return errors.New("owner is required")
}
peers, _, err := i.peerCache.GetCachedPeersBySymbols(ctx, []string{owner}, i.directoryAdapter)
Comment on lines +373 to +375
if create.Title == "" || create.Body == "" || create.Purpose == "" || create.ContentType == "" || create.Audience == nil {
return &labels, importdb.Result{}, errors.New("title, body, purpose, contentType, and audience are required")
}
Comment on lines +213 to +218
if request.IllRequest.ServiceInfo == nil || request.IllRequest.ServiceInfo.ServiceType == "" {
return importdb.PatronRequestBundle{}, nil, errors.New("patronRequest.illRequest.serviceInfo.serviceType is required")
}
serviceType := proapi.StateModelServiceType(request.IllRequest.ServiceInfo.ServiceType)
if !serviceType.Valid() {
return importdb.PatronRequestBundle{}, nil, fmt.Errorf("unsupported service type %q", serviceType)
Comment on lines +35 to +39
UPDATE scheduled_task st
SET title = st.title || '_' || d.rn
FROM duplicates d
WHERE st.id = d.id
AND d.rn > 1;
Comment on lines +5 to +9
SELECT 1
FROM template t
WHERE t.owner = NEW.owner
AND t.labels && NEW.labels
AND (TG_OP = 'INSERT' OR t.id <> NEW.id)
Comment thread broker/oapi/open-api.yaml
Comment on lines +1777 to +1783
examples:
resources:
summary: Three import records
value: |
{"type":"patronRequest","owner":"ISIL:SYM","data":{"patronRequest":{"id":"pr-1","createdAt":"2026-08-26T08:00:00Z","updatedAt":"2026-08-26T09:00:00Z","illRequest":{"header":{"requestingAgencyRequestId":"request-1"},"serviceInfo":{"serviceType":"Loan"}},"state":"SENT","stateModel":"default","side":"borrowing","requesterSymbol":"ISIL:REQ","requesterRequestId":"request-1","needsAttention":false},"items":[],"notifications":[],"locatedSuppliers":[]}}
{"type":"batchAction","owner":"ISIL:SYM","data":{"schedule":"FREQ=DAILY;BYHOUR=6;BYMINUTE=0","actionName":"request-aging","title":"Daily aging","batchQuery":"state==NEW","actionParams":{"interval":"24h"}}}
{"type":"template","owner":"ISIL:SYM","data":{"title":"Request reminder","purpose":"email","subject":"Reminder","body":"Your request is ready","contentType":"text","labels":["request-reminder"],"audience":"patron"}}
Comment on lines +495 to +496
importType := importItemType(itemType)
result.Errors = append(result.Errors, importoapi.ImportItemError{Line: line, Type: &importType, Error: err.Error(), Owner: owner, Identifier: identifier})
return
}

result := a.importer.Import(ctx, policy, json.NewDecoder(r.Body))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants