Skip to content

feat: flatten tenant_configs table with type column#304

Open
niazkhansap wants to merge 1 commit into
mainfrom
improvement/flatten-tenant-configs
Open

feat: flatten tenant_configs table with type column#304
niazkhansap wants to merge 1 commit into
mainfrom
improvement/flatten-tenant-configs

Conversation

@niazkhansap

@niazkhansap niazkhansap commented Jul 1, 2026

Copy link
Copy Markdown
Contributor

Related cleanup PR needs to be rolled out after this.

@coderabbitai

coderabbitai Bot commented Jul 1, 2026

Copy link
Copy Markdown

Review Change Stack

Important

Review skipped

Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: b4b71ae1-3a6d-43e8-97b4-73986405a060

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

Walkthrough

The PR restructures TenantConfig storage from a single legacy JSON blob to typed flat rows keyed by (Key, Type), introducing LegacyTenantConfig for backward-compatible reads. TenantConfigManager gains flat-row read/write logic with legacy fallback, a TenantConfigStore interface wires into CryptoAccessDataSyncer/CryptoReconciler, authz policies grant List access, mock repo indexing is updated, and schema/data migrations backfill flat rows.

Changes

TenantConfig flat-row storage and dependent wiring

Layer / File(s) Summary
TenantConfig model schema change
internal/model/tenantconfigs.go
TenantConfig gains a Type primary-key field, Value changes from json.RawMessage/jsonb to string/text, and a new LegacyTenantConfig model is added for legacy JSONB reads.
TenantConfigManager flat-row read/write implementation
internal/manager/tenantconfigs.go, internal/manager/export_test.go, internal/manager/tenantconfigs_test.go
Adds flat-row constants/keys, rewrites workflow/keystore config get/set to prefer flat rows with legacy blob fallback, adds reconstruction/parsing/writing helpers and transactional row upsert/replace helpers, removes obsolete legacy converters, and adds dual-read/round-trip/edge-case tests.
Mock repo composite-key indexing
internal/repo/mock/db.go, internal/repo/mock/db_test.go, internal/repo/mock/constant.go
In-memory repo now indexes TenantConfig/LegacyTenantConfig by composite (key, type); Create, Get, Delete, Update are updated accordingly, and tests switch Value to plain strings.
TenantConfigStore interface and reconciler/syncer wiring
internal/event-processor/access_data.go, internal/event-processor/reconciler.go, cmd/event-reconciler/main.go, test/integration/event-processor/reconciliation_test.go
Adds a TenantConfigStore interface used by CryptoAccessDataSyncer, extends NewCryptoReconciler with a tenantConfigStore parameter, and wires a constructed TenantConfigManager through the CLI entrypoint and integration test setup.
Test/authz-policy wiring and repo authorization updates
internal/authz/policy_tests/event_reconciler_test.go, internal/event-processor/access_data_test.go, internal/event-processor/reconciler_test.go, internal/authz/repo_internal_policies.go, internal/authz/repo_internal_policies_test_coverage.md
Tests construct and pass TenantConfigManager into reconciler/syncer constructors, seed LegacyTenantConfig rows with string values, and internal roles gain RepoActionList on TenantConfig (documented in the coverage markdown).
Controller and testutils TenantConfig.Value string conversions
internal/controllers/cmk/key_controller_test.go, internal/controllers/cmk/tenantconfigs_controller_test.go, internal/testutils/model.go, internal/manager/workflow_test.go
Test setups switch to model.LegacyTenantConfig and persist marshaled JSON as strings via a consistent unmarshal/marshal round-trip pattern.
Schema and data migrations for flattened tenant configs
migrations/tenant/data/00002_repair_keystore_config_shape.go, migrations/tenant/data/00003_flatten_tenant_configs.go, migrations/tenant/data/main.go, migrations/tenant/schema/00014_flatten_tenant_configs.sql, test/db-migration/migration_test.go
Adds migrations to repair the DEFAULT_KEYSTORE JSON shape and add type/value_text columns with composite key/indexes, backfills flat rows from legacy blobs, registers both migrations, and adds schema/data migration tests validating up/down behavior.

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@niazkhansap

Copy link
Copy Markdown
Contributor Author

@coderabbitai summary

@coderabbitai

coderabbitai Bot commented Jul 1, 2026

Copy link
Copy Markdown
✅ Action performed

Summary regeneration triggered.

minh-nghia
minh-nghia previously approved these changes Jul 6, 2026
@niazkhansap
niazkhansap force-pushed the improvement/flatten-tenant-configs branch from bb8f912 to cf29c9d Compare July 7, 2026 11:43
@niazkhansap
niazkhansap requested a review from minh-nghia July 7, 2026 14:44
Comment thread migrations/tenant/schema/00014_repair_keystore_config_shape.sql Outdated
Comment thread migrations/tenant/schema/00015_flatten_tenant_configs.sql Outdated
Comment thread migrations/tenant/data/00003_flatten_tenant_configs.go
@niazkhansap
niazkhansap force-pushed the improvement/flatten-tenant-configs branch 2 times, most recently from 78a6ea9 to 7b1bed4 Compare July 9, 2026 18:09
@niazkhansap

Copy link
Copy Markdown
Contributor Author

@coderabbitai summary

@coderabbitai

coderabbitai Bot commented Jul 9, 2026

Copy link
Copy Markdown
✅ Action performed

Summary regeneration triggered.

@niazkhansap
niazkhansap force-pushed the improvement/flatten-tenant-configs branch from 7b1bed4 to 3808e84 Compare July 14, 2026 11:33
@niazkhansap
niazkhansap force-pushed the improvement/flatten-tenant-configs branch 3 times, most recently from b904cbd to 6999733 Compare July 23, 2026 19:26
Signed-off-by: Niaz Khan <niazkhansap@gmail.com>
@niazkhansap
niazkhansap force-pushed the improvement/flatten-tenant-configs branch from 6999733 to b8676b4 Compare July 27, 2026 16:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants