CROSSLINK-291 Add migration endpoints - #739
Open
JanisSaldabols wants to merge 1 commit into
Open
Conversation
JanisSaldabols
requested review from
adamdickmeiss and
jakub-id
as code owners
August 28, 2026 05:40
JanisSaldabols
force-pushed
the
CROSSLINK-291
branch
from
August 28, 2026 05:41
1b79b6a to
6b710cf
Compare
Contributor
There was a problem hiding this comment.
Pull request overview
Adds NDJSON migration imports for patron requests, templates, and scheduled batch actions.
Changes:
- Adds
/importwith 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.
| }) | ||
| 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 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)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.