Skip to content

feat: migrate metadata columns to JSONB and add JSONPath filtering#378

Merged
haritzsaiz merged 9 commits intomainfrom
feat/meta-filter
Jan 14, 2026
Merged

feat: migrate metadata columns to JSONB and add JSONPath filtering#378
haritzsaiz merged 9 commits intomainfrom
feat/meta-filter

Conversation

@haritzsaiz
Copy link
Collaborator

This pull request introduces support for storing and querying metadata columns as JSONB in several tables, enabling more flexible and efficient JSON queries. It includes database migrations to convert existing metadata columns from text to JSONB, updates to the filtering/query logic to support JSONPath expressions, and comprehensive migration tests to ensure correctness.

Database migrations:

  • Added migrations to convert the metadata column from text to jsonb in the ca_certificates, certificates, devices, and dms tables, with support for both upgrade and downgrade paths. [1] [2] [3]

Query and filter enhancements:

  • Introduced a new JsonFilterFieldType and JsonPathExpression filter operation to support JSONPath-based filtering on JSONB columns. [1] [2] [3] [4]
  • Added metadata as a filterable field of type JsonFilterFieldType in the relevant resource definitions.

Testing and validation:

  • Implemented and extended migration tests for all affected tables to validate correct conversion of metadata values (including handling of empty and null values) and to verify that JSONB operators can be used in queries post-migration. [1] [2] [3]

Dependency updates:

  • Updated imports to include net/url for query unescaping in filter logic.

@codecov
Copy link

codecov bot commented Jan 9, 2026

Codecov Report

❌ Patch coverage is 55.55556% with 4 lines in your changes missing coverage. Please review.
✅ Project coverage is 46.78%. Comparing base (80e2e51) to head (bd15061).
⚠️ Report is 6 commits behind head on main.

Files with missing lines Patch % Lines
backend/pkg/controllers/utils.go 55.55% 3 Missing and 1 partial ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main     #378   +/-   ##
=======================================
  Coverage   46.77%   46.78%           
=======================================
  Files         146      146           
  Lines        8616     8625    +9     
=======================================
+ Hits         4030     4035    +5     
- Misses       4157     4160    +3     
- Partials      429      430    +1     
Flag Coverage Δ
backend-rest 19.00% <55.55%> (+0.06%) ⬆️
connector-awsiot 5.55% <ø> (ø)
core 63.65% <ø> (ø)
monolithic 0.00% <ø> (ø)
sdk 0.00% <ø> (ø)
shared-http 5.99% <ø> (ø)
storage-postgres 51.32% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This pull request migrates metadata columns from text to JSONB format across four database tables (ca_certificates, certificates, devices, and dms) and introduces JSONPath filtering capabilities. The changes enable more flexible and efficient JSON queries on metadata fields.

Changes:

  • Added database migrations to convert metadata columns from text to JSONB in ca_certificates, certificates, devices, and dms tables with bidirectional migration support
  • Introduced JsonFilterFieldType and JsonPathExpression filter operation to enable JSONPath-based filtering
  • Added comprehensive migration tests validating correct data conversion and JSONB functionality

Reviewed changes

Copilot reviewed 10 out of 10 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
engines/storage/postgres/utils.go Added JsonPathExpression case to support JSONB @@ operator in SQL WHERE clauses
engines/storage/postgres/migrations_test/dms_test.go Added comprehensive migration tests for dms table metadata conversion
engines/storage/postgres/migrations_test/devicemanager_test.go Added comprehensive migration tests for devices table metadata conversion
engines/storage/postgres/migrations_test/ca_test.go Added comprehensive migration tests for ca_certificates and certificates table metadata conversion
engines/storage/postgres/migrations/dmsmanager/20251217120000_metadata_text_to_jsonb.sql Migration script to convert dms metadata column to JSONB
engines/storage/postgres/migrations/devicemanager/20251217120000_metadata_text_to_jsonb.sql Migration script to convert devices metadata column to JSONB
engines/storage/postgres/migrations/ca/20251217120000_metadata_text_to_jsonb.sql Migration script to convert ca_certificates and certificates metadata columns to JSONB
core/pkg/resources/query.go Added JsonFilterFieldType and JsonPathExpression constants
core/pkg/resources/careq.go Added metadata as JsonFilterFieldType to KMSFilterableFields
backend/pkg/controllers/utils.go Added JSONPath filter handling with URL unescaping and net/url import

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

haritzsaiz and others added 8 commits January 12, 2026 11:21
- Implemented unit tests for filtering devices by metadata using JSONPath expressions in `device_filter_tests.go`.
- Added comprehensive filtering tests for DMS entities based on metadata and settings in `dms_filter_test.go`.
- Created key filtering tests that utilize JSON metadata in `key_filter_test.go`.
- Updated filterable fields in `fields.go` to include metadata and settings for DMS and devices.
- Migrated DMS settings column from text to JSONB format in the database for better querying capabilities.
- Enhanced SDK query parameter encoding to support JSONPath expressions.

Signed-off-by: Juanjo Rodriguez <[email protected]>
@sonarqubecloud
Copy link

@haritzsaiz haritzsaiz merged commit 0f8ba0f into main Jan 14, 2026
42 checks passed
@haritzsaiz haritzsaiz deleted the feat/meta-filter branch January 14, 2026 15:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants