make "schema.log"."target_id" column optional#8091
Conversation
008e155 to
d53f206
Compare
There was a problem hiding this comment.
Code Review
This pull request removes the targetId / target_id field from schema log entities, including proposals, push logs, delete logs, and base schema definitions. However, two critical issues were identified: first, targetId is still being passed to insertPushSchemaLog at its call site in createSchemaVersion, leading to a TypeScript compilation error; second, in deleteSubgraphFromTarget, target_id was removed from the INSERT columns but remains in the RETURNING clause and the subsequent Zod parser, which will cause a runtime validation failure.
🚀 Snapshot Release (
|
| Package | Version | Info |
|---|---|---|
@graphql-hive/cli |
0.59.3-alpha-20260529123937-4ccbe160054a20fd649e11ac7235caf549d4af67 |
npm ↗︎ unpkg ↗︎ |
hive |
11.2.0-alpha-20260529123937-4ccbe160054a20fd649e11ac7235caf549d4af67 |
npm ↗︎ unpkg ↗︎ |
|
🐋 This PR was built and pushed to the following Docker images: Targets: Platforms: Image Tag: |
Background
Prerequisite for #8031; Continuation of efforts from #8082
Description
#8031 will introduce that a
schema_logcan be associated with ANY schema version within the same project.With the current database schema, deleting a target triggers a cascade delete of its associated schema versions and schema_logs. Since schema logs can be shared across multiple schema versions, this may unintentionally remove references that are still required by other versions (which will be introduced in #8031), leaving the remaining schema version relationships inconsistent.
To prevent this, this PR introduces the following changes:
target_idonschema_log, as it is no longer used by any relevant business logic.schema_log.target_idnullable and remove its foreign key constraint to prevent cascade deletions when a target is deletedDrawback / Consideration
This change introduces a minor concern.
A target can have multiple schema versions, and each schema version can reference multiple schema log entries through the schema_version_to_log relation. In addition, a project directly owns many schema log entries.
When a target is deleted, all associated schema versions are removed via cascade deletion. However, the related schema_log records are not automatically deleted, since they may also be referenced independently at the project level.
As a result, this can lead to orphaned schema_log entries that are no longer associated with any schema version.
To mitigate this, we could introduce a periodic cleanup process (for example, a cron job) in the future to identify and remove unreferenced schema log records.
I added this to a follow up issue #8052