Skip to content

make "schema.log"."target_id" column optional#8091

Merged
n1ru4l merged 6 commits into
mainfrom
feat-schema-log-nullable-target-id-column
May 29, 2026
Merged

make "schema.log"."target_id" column optional#8091
n1ru4l merged 6 commits into
mainfrom
feat-schema-log-nullable-target-id-column

Conversation

@n1ru4l

@n1ru4l n1ru4l commented May 29, 2026

Copy link
Copy Markdown
Contributor

Background

Prerequisite for #8031; Continuation of efforts from #8082

Description

#8031 will introduce that a schema_log can 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:

  • Update the insert logic to stop persisting target_id on schema_log, as it is no longer used by any relevant business logic.
  • Make schema_log.target_id nullable and remove its foreign key constraint to prevent cascade deletions when a target is deleted

Drawback / 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

@n1ru4l n1ru4l force-pushed the feat-schema-log-nullable-target-id-column branch from 008e155 to d53f206 Compare May 29, 2026 12:18

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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.

@github-actions

github-actions Bot commented May 29, 2026

Copy link
Copy Markdown
Contributor

🚀 Snapshot Release (alpha)

The latest changes of this PR are available as alpha on npm (based on the declared changesets):

Package Version Info
@graphql-hive/cli 0.59.3-alpha-20260529123937-4ccbe160054a20fd649e11ac7235caf549d4af67 npm ↗︎ unpkg ↗︎
hive 11.2.0-alpha-20260529123937-4ccbe160054a20fd649e11ac7235caf549d4af67 npm ↗︎ unpkg ↗︎

@github-actions

github-actions Bot commented May 29, 2026

Copy link
Copy Markdown
Contributor

🐋 This PR was built and pushed to the following Docker images:

Targets: build

Platforms: linux/arm64

Image Tag: 4ccbe160054a20fd649e11ac7235caf549d4af67

n1ru4l added a commit that referenced this pull request May 29, 2026
@n1ru4l n1ru4l marked this pull request as ready for review May 29, 2026 12:59
@n1ru4l n1ru4l requested review from jdolle and jonathanawesome May 29, 2026 13:01
@n1ru4l n1ru4l merged commit aecbae2 into main May 29, 2026
24 checks passed
@n1ru4l n1ru4l deleted the feat-schema-log-nullable-target-id-column branch May 29, 2026 13:55
n1ru4l added a commit that referenced this pull request May 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants