chore(introspect,core): Harden schema export/diff and introspect connection lifecycle#88
Merged
Merged
Conversation
Add ViewExport and EnumExport entries to SchemaExport so that view and enum metadata survives a JSON round trip. Without this, downstream diff workflows that go through schema-json saw every view and enum as removed because import_schema rebuilt an empty Schema.views / .enums. The new payloads validate that each id is non-empty, mirroring the existing table contract, and keep the format field-additive via serde defaults.
diff_schemas previously matched views and enums on their opaque id field, which the parser composes from normalized identifiers and the introspector composes from raw catalog identifiers. Any drift between the two producers showed up as a phantom add+remove pair instead of a modification. Switch the match key to the lowercased (schema_name, name) pair so the contract is anchored to the data model rather than the producer's id encoding, and add regression tests that diff a view and an enum across mismatched id values.
Previously close_pool_when_done discarded the outcome of pool.close() entirely, so a hung drain (e.g. a connection that never finishes draining or has lost connectivity) silently returned the operation result and left the caller unaware that cleanup did not complete. Wrap the close in a 30-second timeout: if the operation succeeded but the drain timed out, surface IntrospectError::Timeout; if the operation already failed, that error wins so the original cause is not masked. Narrow the function's error type to IntrospectError to let it construct the timeout error directly without burdening callers.
Read RELUNE_DB_POOL_MAX_CONNECTIONS to override the per-dialect pool cap (PostgreSQL/MySQL default to 6, SQLite to 1). Constrained CI runners or unusual workloads can tune the cap without code changes; non-positive or non-numeric values fall back to the default.
…ys, enums, and cross-schema FKs Adds integration tests for previously uncovered shapes: - empty PostgreSQL and SQLite databases - PostgreSQL reserved-word table and column names with composite primary key, composite foreign key, and composite unique index - PostgreSQL enum types and cross-schema foreign keys - MySQL ENUM and SET column types
Code Metrics Report
Details | | main (0c5b241) | #88 (a397dc4) | +/- |
|---------------------|----------------|---------------|-------|
+ | Coverage | 94.7% | 94.7% | +0.0% |
| Files | 77 | 77 | 0 |
| Lines | 34255 | 34529 | +274 |
+ | Covered | 32442 | 32726 | +284 |
| Test Execution Time | 1m24s | 1m24s | 0s |Code coverage of files in pull request scope (92.8% → 93.9%)
Reported by octocov |
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.
Summary
relune-coreschema export/import so JSON round-trips stop dropping them.diff_schemasview/enum matching so id-encoding drift between producers no longer manifests as phantom add+remove pairs.close_pool_when_doneinstead of silently masking them under a successful operation result.RELUNE_DB_POOL_MAX_CONNECTIONS, with a CLI reference note.Changes
ViewExport/EnumExportand extendSchemaExportwith serde-defaultviews/enumsfields so older JSON keeps deserializing.export_schema/import_schemaand reject emptyidvalues during import.(schema, name)lookups normalized to lowercase, eliminating false add+remove churn when producers disagree on id encoding.pool.close()withtokio::time::timeoutso a hung drain emitsIntrospectError::Timeoutinstead of disappearing into a successful return.RELUNE_DB_POOL_MAX_CONNECTIONSto override the per-dialect pool cap; non-positive or non-numeric values fall back to the existing defaults (PostgreSQL/MySQL fan out to 6, SQLite to 1)."order"/"select"reserved-word identifiers with composite PK/FK/UNIQUE INDEX, PostgreSQL CREATE TYPE enums plus cross-schema FKs, and MySQL ENUM/SET column extraction.