사용자 인증 토큰 스키마 안정화 - #1
Merged
Merged
Conversation
There was a problem hiding this comment.
Pull request overview
This PR stabilizes the authentication token schema by aligning Flyway-managed database tables with the current JPA token entities, and hardens password-reset behavior to avoid leaking account existence.
Changes:
- Add Flyway migrations (V3/V4) to reconcile legacy token columns (
token,expires_at,used) with current entity columns (token_value,expiry_date,is_*), preserving data where possible. - Update
PasswordResetServicebehavior for unknown emails and wrap password reset operations in transactions; add unit tests for reset flows. - Add stabilization documentation and link it from the README.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| src/main/java/com/honeyrest/honeyrest_user/service/PasswordResetService.java | Makes password-reset requests non-enumerable and adds transactional boundaries around reset flows. |
| src/test/java/com/honeyrest/honeyrest_user/service/PasswordResetServiceTest.java | Adds unit coverage for reset request, token expiry handling, and password update/token consumption. |
| src/main/resources/db/migration/V3__align_email_verification_token.sql | Introduces schema alignment migration for email verification tokens. |
| src/main/resources/db/migration/V4__align_auth_token_tables.sql | Introduces schema alignment migration for refresh/password-reset token tables. |
| README.md | Adds a link to the stabilization notes. |
| docs/STABILIZATION.md | Documents stabilization steps and verification results for the token schema changes. |
Suppressed comments (3)
src/main/resources/db/migration/V3__align_email_verification_token.sql:33
- When
expiry_datealready exists, the migration drops legacyexpires_atwithout backfilling. If existing rows only haveexpires_atpopulated (common when Hibernate added new columns), dropping it can wipe token expiry data and later cause NPEs in token validation. Backfillexpiry_datefromexpires_atbefore dropping, and then enforce NOT NULL.
SET @sql = IF(
@has_expiry_date = 0,
'ALTER TABLE `email_verification_token` CHANGE COLUMN `expires_at` `expiry_date` DATETIME(6) NOT NULL',
'ALTER TABLE `email_verification_token` DROP COLUMN `expires_at`'
);
src/main/resources/db/migration/V3__align_email_verification_token.sql:48
- When
is_verifiedalready exists, the migration drops legacyusedwithout backfilling. If existing rows still only have data inused, dropping it can lose verification state. Backfillis_verifiedfromusedfirst, then drop, and ensure the column is NOT NULL with a default.
SET @sql = IF(
@has_is_verified = 0,
'ALTER TABLE `email_verification_token` CHANGE COLUMN `used` `is_verified` BIT(1) NOT NULL DEFAULT 0',
'ALTER TABLE `email_verification_token` DROP COLUMN `used`'
);
src/main/resources/db/migration/V4__align_auth_token_tables.sql:102
password_reset_token.expiry_dateandis_usedare left nullable.PasswordResetService.resetPassword()callstoken.getExpiryDate().isBefore(...), so a NULLexpiry_datewill throw at runtime. After backfilling from legacy columns, enforceexpiry_dateas NOT NULL and makeis_usedNOT NULL DEFAULT 0 (and normalize any remaining NULLs).
ALTER TABLE `password_reset_token`
MODIFY COLUMN `expires_at` DATETIME(6) NULL,
MODIFY COLUMN `used` BIT(1) NULL;
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Comment on lines
+27
to
28
| @Transactional | ||
| public void requestReset(String email) { |
Comment on lines
+8
to
+21
| SET @has_token_value = ( | ||
| SELECT COUNT(*) FROM information_schema.columns | ||
| WHERE table_schema = DATABASE() | ||
| AND table_name = 'email_verification_token' | ||
| AND column_name = 'token_value' | ||
| ); | ||
| SET @sql = IF( | ||
| @has_token_value = 0, | ||
| 'ALTER TABLE `email_verification_token` CHANGE COLUMN `token` `token_value` VARCHAR(255) NOT NULL', | ||
| 'ALTER TABLE `email_verification_token` DROP COLUMN `token`' | ||
| ); | ||
| PREPARE stmt FROM @sql; | ||
| EXECUTE stmt; | ||
| DEALLOCATE PREPARE stmt; |
| EXECUTE stmt; | ||
| DEALLOCATE PREPARE stmt; | ||
| UPDATE `refresh_token` SET `expiry_date` = `expires_at` WHERE `expiry_date` IS NULL; | ||
| ALTER TABLE `refresh_token` MODIFY COLUMN `expires_at` DATETIME(6) NULL; |
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.
No description provided.