feat: update apikey schema and relationships#4028
Merged
Siumauricio merged 2 commits intocanaryfrom Mar 18, 2026
Merged
Conversation
- 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.
| 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 |
Contributor
There was a problem hiding this comment.
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!
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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:
canarybranch.Issues related (if applicable)
closes #4024
Screenshots (if applicable)
Greptile Summary
This PR migrates the
apikeytable from auser_idcolumn toreference_id, making it compatible with the@better-auth/api-keyplugin's expected schema, and adds aconfig_idcolumn 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.UPDATE … SET reference_id = user_idstep.account.ts), auth plugin configuration (references: "user"inauth.ts), and service layer (user.ts) are all correctly updated to reflect the new column name.apikeyRelationsrelation now correctly joins throughreferenceId, andvalidateRequestcontinues to work as expected.0151_modern_sunfire.sqlis missing a trailing newline at EOF.Confidence Score: 4/5
apps/dokploy/drizzle/0151_modern_sunfire.sql.Last reviewed commit: "chore: bump version ..."