Skip to content

Add idempotent seed-data command - #236

Merged
Subhransu-De merged 13 commits into
mainfrom
add-seed-data-command
Oct 3, 2026
Merged

Subhransu-De merged 13 commits into
mainfrom
add-seed-data-command

Conversation

@Subhransu-De

@Subhransu-De Subhransu-De commented Oct 2, 2026 •

Copy link
Copy Markdown
Owner

Closes #215

Problem

There was no way to load reference or demo data. Migrations run from their own image, and seeds that insert explicit integer IDs also have to move the identity sequence, or the next insert collides.

Behavior

  • New seed/ package next to alembic/. It reflects the fixture tables from the database's default schema, so it runs in the migration image without the application code. Tables in other schemas are never seeded.
  • Contract: every fixture row sets its primary key. Rows are inserted in fixture order with ON CONFLICT (primary key) DO NOTHING in one transaction, tables in foreign-key order. A row whose key exists is left as it is, so a second run inserts nothing. A row without its primary key fails before anything is written.
  • Each seeded table is locked in SHARE ROW EXCLUSIVE mode for the seed transaction, so concurrent writers and concurrent seed runs wait; readers do not.
  • For an integer identity primary key, the sequence is restarted after the highest stored ID with ALTER SEQUENCE ... RESTART only when it has not already passed that ID, so it never moves backwards. The restart rolls back with the transaction. This assumes the ascending, step-1 sequence that SQLAlchemy's Identity() creates. The template's own tables use UUID keys and have no sequence.
  • make seed runs it against .env. In Compose, docker compose run --rm seed runs it from the migration image after migrate. The service is behind the seed profile, so docker compose up does not start it, and nothing in the app lifespan calls it.
  • seed is added to the ruff and ty lint paths.

Validation

  • make check: 153 passed, all lint gates green.
  • make test-integration: 73 passed, including tests/integration/test_seed.py: a second run changes nothing, the next insert after explicit IDs gets a new ID, a sequence that is already ahead is kept, rows without a primary key are rejected, rows with different columns keep their values, fixture order is kept, a same-named table in another schema is not seeded, a rolled-back seed leaves the sequence alone, a concurrent insert waits until seeding commits, and startup does not seed.
  • Removing the sequence restart, its advance-only condition, the table lock, the default-schema filter, or the primary-key check each makes a test fail.
  • docker compose run --rm seed twice on a fresh stack: entities: 2 new rows, then entities: 0 new rows.

Note

From claude-opus-5-5

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 2, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-03T05:17:51.166426Z 662555e Manual request
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@greptile-apps

greptile-apps Bot commented Oct 2, 2026 •

Copy link
Copy Markdown

RetriggerConfidence Score: 4/5

[Medium risk] Adds a new database seeding command and fixtures.

The PR is not yet safe to merge because a cached step-1 identity sequence can still produce an ID explicitly inserted by the seed.

Fix All in CodexFindings

  1. P1 Cached IDs can collide ▶
Fix with agent prompt
### Issue 1
seed/__init__.py:73
If a step-1 identity sequence uses `CACHE 10`, a writer can still hold unused IDs after the sequence reports `last_value = 10`. If seeding inserts one of those IDs, this check treats 11 as the next value and skips the restart. The writer can later receive the seeded ID from its cache, causing a duplicate-key error. The documented step-1 assumption does not rule out caching.

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.
Summary

The PR adds a standalone, transactional fixture seeder, Make and Compose entry points, documentation, and integration coverage. The latest change avoids restarting an identity sequence when its stored state appears to be ahead of the seeded IDs.

Reviews (12) · Last reviewed commit: "Only advance identity sequences when see..."

Comment thread seed/__init__.py Outdated

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: b225fb350b

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread seed/__init__.py Outdated
Comment thread seed/__init__.py Outdated
@Subhransu-De

Copy link
Copy Markdown
Owner Author

@codex review

Note

From claude-opus-5-5

Comment thread seed/__init__.py Outdated

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: bf67368340

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread seed/__init__.py Outdated
Comment thread seed/__init__.py Outdated
@Subhransu-De

Copy link
Copy Markdown
Owner Author

@codex review

Note

From claude-opus-5-5

Comment thread seed/__init__.py Outdated

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 24b73fa533

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread seed/__init__.py Outdated
Comment thread seed/__init__.py Outdated
@Subhransu-De

Copy link
Copy Markdown
Owner Author

@codex review

Note

From claude-opus-5-5

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: d95c5dcec3

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread seed/__init__.py Outdated
Comment thread seed/__init__.py Outdated
Comment thread seed/__init__.py Outdated
@Subhransu-De

Copy link
Copy Markdown
Owner Author

@codex review

Note

From claude-opus-5-5

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 85de8d0f0f

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread seed/__init__.py Outdated
Comment thread seed/__init__.py
Comment thread seed/__init__.py Outdated
@Subhransu-De

Copy link
Copy Markdown
Owner Author

@codex review

Note

From claude-opus-5-5

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 8339d6ff23

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread seed/__init__.py Outdated
Comment thread seed/__init__.py Outdated
@Subhransu-De

Copy link
Copy Markdown
Owner Author

@codex review

Note

From claude-opus-5-5

Comment thread seed/__init__.py Outdated

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 4f1c65b5bf

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread seed/__init__.py Outdated
Comment thread seed/__init__.py Outdated
@Subhransu-De

Copy link
Copy Markdown
Owner Author

@codex review

Note

From claude-opus-5-5

Comment thread seed/__init__.py Outdated

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: bf48606c97

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread seed/__init__.py Outdated
Comment thread seed/__init__.py Outdated
@Subhransu-De

Copy link
Copy Markdown
Owner Author

@codex review

Note

From claude-opus-5-5

Comment thread seed/__init__.py Outdated

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 8459dead60

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread seed/__init__.py Outdated
@Subhransu-De

Copy link
Copy Markdown
Owner Author

@codex review

Note

From claude-opus-5-5

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: bb050d7365

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread seed/__init__.py
@Subhransu-De

Copy link
Copy Markdown
Owner Author

@codex review

Note

From claude-opus-5-5

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: bad4f9532f

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread seed/__init__.py Outdated
@Subhransu-De

Copy link
Copy Markdown
Owner Author

@codex review

Note

From claude-opus-5-5

@sonarqubecloud

sonarqubecloud Bot commented Oct 3, 2026

Copy link
Copy Markdown

Comment thread seed/__init__.py
@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. What shall we delve into next?

Reviewed commit: 662555e54b

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@Subhransu-De
Subhransu-De merged commit 91ca332 into main Oct 3, 2026
40 checks passed
@Subhransu-De
Subhransu-De deleted the add-seed-data-command branch October 3, 2026 05:20
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.

Add an idempotent seed-data command

1 participant