Skip to content

feat: update apikey schema and relationships#4028

Merged
Siumauricio merged 2 commits intocanaryfrom
4024-api-keys-not-working-and-unbale-to-generate-new-ones-after-upgrade-to-0287
Mar 18, 2026
Merged

feat: update apikey schema and relationships#4028
Siumauricio merged 2 commits intocanaryfrom
4024-api-keys-not-working-and-unbale-to-generate-new-ones-after-upgrade-to-0287

Conversation

@Siumauricio
Copy link
Copy Markdown
Contributor

@Siumauricio Siumauricio commented Mar 18, 2026

  • Modified the apikey table to drop the user_id column and replace it with reference_id, establishing a foreign key relationship with the user table.
  • Added config_id column with a default value to the apikey table.
  • Updated related code in the account schema and user service to reflect these changes.
  • Enhanced the journal and snapshot files to include the latest schema updates.

What is this PR about?

Please describe in a short paragraph what this PR is about.

Checklist

Before submitting this PR, please make sure that:

Issues related (if applicable)

closes #4024

Screenshots (if applicable)

Greptile Summary

This PR migrates the apikey table from a user_id column to reference_id, making it compatible with the @better-auth/api-key plugin's expected schema, and adds a config_id column with a default value of "default". The change is split across two sequential migrations (0150 and 0151) following the safe rename pattern: add the new column, backfill data, enforce NOT NULL, then drop the old column in the next migration.

  • The two-migration approach is sound and correctly preserves all existing API key → user relationships via the UPDATE … SET reference_id = user_id step.
  • The Drizzle schema (account.ts), auth plugin configuration (references: "user" in auth.ts), and service layer (user.ts) are all correctly updated to reflect the new column name.
  • The apikeyRelations relation now correctly joins through referenceId, and validateRequest continues to work as expected.
  • Minor style issue: 0151_modern_sunfire.sql is missing a trailing newline at EOF.

Confidence Score: 4/5

  • This PR is safe to merge; the migration correctly preserves all data and the code changes are consistent throughout.
  • The schema change is well-structured (two-step rename pattern), data migration is correct, and all consuming code (auth plugin, relations, service layer) has been updated consistently. One trivial style issue (missing EOF newline) prevents a perfect score.
  • No files require special attention beyond the missing trailing newline in apps/dokploy/drizzle/0151_modern_sunfire.sql.

Last reviewed commit: "chore: bump version ..."

Greptile also left 1 inline comment on this PR.

- Modified the apikey table to drop the user_id column and replace it with reference_id, establishing a foreign key relationship with the user table.
- Added config_id column with a default value to the apikey table.
- Updated related code in the account schema and user service to reflect these changes.
- Enhanced the journal and snapshot files to include the latest schema updates.
@dosubot dosubot Bot added the size:M This PR changes 30-99 lines, ignoring generated files. label Mar 18, 2026
@Siumauricio Siumauricio merged commit 72974e0 into canary Mar 18, 2026
1 of 4 checks passed
@Siumauricio Siumauricio deleted the 4024-api-keys-not-working-and-unbale-to-generate-new-ones-after-upgrade-to-0287 branch March 18, 2026 22:29
@dosubot dosubot Bot added the enhancement New feature or request label Mar 18, 2026
ALTER TABLE "apikey" DROP CONSTRAINT "apikey_user_id_user_id_fk";
--> statement-breakpoint
ALTER TABLE "apikey" ADD CONSTRAINT "apikey_reference_id_user_id_fk" FOREIGN KEY ("reference_id") REFERENCES "public"."user"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "apikey" DROP COLUMN "user_id"; No newline at end of file
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.

P2 Missing newline at end of file

The file is missing a trailing newline. While this doesn't affect SQL execution, it's a widely followed convention (POSIX standard) to end text files with a newline. All other migration files in the project follow this convention.

Suggested change
ALTER TABLE "apikey" DROP COLUMN "user_id";
ALTER TABLE "apikey" ADD CONSTRAINT "apikey_reference_id_user_id_fk" FOREIGN KEY ("reference_id") REFERENCES "public"."user"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "apikey" DROP COLUMN "user_id";

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request size:M This PR changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

API Keys not working and unbale to generate new ones after Upgrade to 0.28.7

1 participant