Skip to content

Fix org creation crash on Postgres - #4436

Merged
shomix merged 3 commits into
mainfrom
shomix-p-fix-table-types
Sep 7, 2026
Merged

Fix org creation crash on Postgres#4436
shomix merged 3 commits into
mainfrom
shomix-p-fix-table-types

Conversation

@shomix

@shomix shomix commented Sep 6, 2026

Copy link
Copy Markdown
Contributor

Org creation and SSO login were crashing because a few timestamp columns were too small to hold the values written into them. This fixes those columns and a couple of related spots with the same problem.

This is only for new database creations, the existing hosted db's are okay and have valid types

Summary

Fixes a bug that made org creation (and SSO login) crash on a fresh database, cleans up a few related timestamp columns that had the same problem waiting to happen, and ignores some local dev files that shouldn't be tracked by git.

The bug

Creating a new organization was failing with an error like value "1788715962713" is out of range for type integer. The root cause: several database columns that store timestamps were declared as INTEGER, but the code writes millisecond timestamps into them (e.g. Date.now()), and those numbers are too big to fit in a regular integer. This affected every app, not just one template, since organization creation is shared framework code.

The same problem existed in the SSO login tables, and in a background cleanup job in the Clips app.

What changed

  • Widened the affected columns from INTEGER to BIGINT in: organizations, org members, org invitations, app member roles, workspace apps, SSO flow state, and SSO one-time tokens.
  • Updated the matching data model definitions so they now match the database columns. Previously a few of them (chat threads, email log, app secrets) already had BIGINT columns but were still described as smaller integers in code, which could have caused silent data bugs the next time someone read from them.
  • Fixed the same undersized column in Clips' backfill lease table.
  • Added a changeset so this fix gets published with the next release.

Also included

Added data/*.lock to the .gitignore file in every template. Running an app locally creates a lock file for its local database, and that file was not being ignored, so it showed up as an untracked file in git status.

@github-actions

github-actions Bot commented Sep 6, 2026

Copy link
Copy Markdown
Contributor

Here's a visual recap of what changed:

Visual recap

Open the full interactive recap

builder-io-integration[bot]

This comment was marked as outdated.

@netlify

This comment has been minimized.

@builder-io-integration builder-io-integration 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.

Builder reviewed your changes and found 1 potential issue 🟡

Review Details

Incremental Code Review Summary

The latest commit addresses both findings from the previous review: Clips now has migration v70 to widen existing lease tables, and the email log bootstrap now widens legacy created_at columns after ensuring the table. The org and SSO migrations remain additive and correctly separate fresh-database definitions from upgrades. The updated BIGINT Drizzle mappings also use numeric mode consistently with millisecond Date.now() values.

New Finding

🟡 MEDIUM: Existing app_secrets tables are still not widened. The schema and fresh-table path now use BIGINT, but the secrets storage bootstrap has no migration or widenIntColumnsToBigInt call, so upgraded deployments can still fail credential/OAuth writes when Date.now() exceeds PostgreSQL int4 range.

The two previous review threads were resolved after verifying their fixes. No other new confirmed issues were identified.

Risk assessment: Standard risk (database schema and migration behavior).

🧪 Browser testing: Skipped — this PR only modifies backend/schema/config/template ignore files, with no user-facing UI impact.

Comment thread packages/core/src/secrets/schema.ts
@shomix
shomix merged commit 324b27e into main Sep 7, 2026
48 checks passed
@shomix
shomix deleted the shomix-p-fix-table-types branch September 7, 2026 18:21
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.

2 participants