<!-- Provide a brief summary of your changes -->
This PR serves as a placeholder and brings together all of the changes
related to supporting vendor extensions passed through the API. The idea
is to have a single place to track and review the work as it comes
together (even if it’s still a bit of a work in progress).
**The changes in this PR cover:**
* Updates on the data model
* Updates on both databases (in-memory and postgresql), added a new
table to PSQL for tracking the extensions leaving the server table only
for the clean server.json properties
* Updates the seed.json file (thus the big line change)
* Adds a seed-migrate tool to help migrating an existing seed file to
the new format
* Updates the seed import mechanism to support this
* Updates the existing tests - unit, integration and validation tests
* Adds the publish handler to the OpenAPI spec (it was missing)
* Fixes linting errors
* Updates on the API side on (publish, list, get) to support the new
format of `ServerResponse` -
```
{
"server": {},
"x-io.modelcontextprotocol.registry": {}, /*not available for publish since this gets populated by the registry*/
"x-publisher": {}
}
```
## Motivation and Context
<!-- Why is this change needed? What problem does it solve? -->
Motivated by the discussions in:
https://github.com/modelcontextprotocol/registry/discussions/284
## How Has This Been Tested?
<!-- Have you tested this in a real application? Which scenarios were
tested? -->
Locally and by running all of the tests
## Breaking Changes
<!-- Will users need to update their code or configurations? -->
Yes, it changes both the API and the format of the seed file
## Types of changes
<!-- What types of changes does your code introduce? Put an `x` in all
the boxes that apply: -->
- [ ] Bug fix (non-breaking change which fixes an issue)
- [ ] New feature (non-breaking change which adds functionality)
- [x] Breaking change (fix or feature that would cause existing
functionality to change)
- [ ] Documentation update
---
Signed-off-by: Radoslav Dimitrov <radoslav@stacklok.com>
Co-authored-by: adam jones <domdomegg+git@gmail.com>
62 lines
No EOL
2.4 KiB
PL/PgSQL
62 lines
No EOL
2.4 KiB
PL/PgSQL
-- Add server_extensions table for registry metadata and publisher extensions
|
|
-- This migration implements the extension wrapper architecture
|
|
|
|
-- Create server_extensions table for registry/publisher metadata
|
|
CREATE TABLE server_extensions (
|
|
id UUID PRIMARY KEY DEFAULT uuid_generate_v4(),
|
|
server_id UUID NOT NULL REFERENCES servers(id) ON DELETE CASCADE,
|
|
|
|
-- Registry metadata as structured columns
|
|
published_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT NOW(),
|
|
updated_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT NOW(),
|
|
is_latest BOOLEAN NOT NULL DEFAULT true,
|
|
release_date TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT NOW(),
|
|
|
|
-- Publisher extensions as flexible JSONB
|
|
publisher_extensions JSONB DEFAULT '{}'::jsonb,
|
|
|
|
-- Ensure one extension record per server
|
|
UNIQUE(server_id)
|
|
);
|
|
|
|
-- Indexes for performance
|
|
CREATE UNIQUE INDEX idx_server_extensions_server_id ON server_extensions(server_id);
|
|
CREATE INDEX idx_server_extensions_latest ON server_extensions(is_latest) WHERE is_latest = true;
|
|
CREATE INDEX idx_server_extensions_published_at ON server_extensions(published_at);
|
|
|
|
-- GIN index for publisher extensions JSONB field
|
|
CREATE INDEX idx_server_extensions_publisher_gin ON server_extensions USING GIN(publisher_extensions);
|
|
|
|
-- Migrate existing data from servers table to server_extensions table
|
|
INSERT INTO server_extensions (server_id, published_at, updated_at, is_latest, release_date, publisher_extensions)
|
|
SELECT
|
|
id,
|
|
created_at, -- Use created_at as published_at
|
|
updated_at,
|
|
is_latest,
|
|
release_date,
|
|
'{}'::jsonb -- Empty publisher extensions
|
|
FROM servers;
|
|
|
|
-- Remove registry metadata columns from servers table (they now live in server_extensions)
|
|
ALTER TABLE servers DROP COLUMN release_date;
|
|
ALTER TABLE servers DROP COLUMN is_latest;
|
|
|
|
-- Update trigger to also update server_extensions updated_at when servers are updated
|
|
CREATE OR REPLACE FUNCTION update_server_extensions_updated_at()
|
|
RETURNS TRIGGER AS $$
|
|
BEGIN
|
|
-- Update the corresponding server_extensions record
|
|
UPDATE server_extensions
|
|
SET updated_at = NOW()
|
|
WHERE server_id = NEW.id;
|
|
|
|
RETURN NEW;
|
|
END;
|
|
$$ language 'plpgsql';
|
|
|
|
-- Trigger to automatically update server_extensions updated_at when servers change
|
|
CREATE TRIGGER update_server_extensions_on_server_update
|
|
AFTER UPDATE ON servers
|
|
FOR EACH ROW
|
|
EXECUTE FUNCTION update_server_extensions_updated_at(); |