update_reset_password.go
024_update_reset_password.go - Overview
This file defines a SQL migration to update the schema for reset password requests and personal access tokens. It moves data from old tables (reset_password_request
, personal_access_tokens
) to new tables (reset_password_request_new
, personal_access_token
) with UUID primary keys, and includes functions for copying data between the old and new table structures.
Detailed Documentation
updateResetPassword
- Purpose: Represents the SQL migration for updating reset password and personal access token schemas.
- Parameters:
- store: sqlstore.SQLStore - An SQLStore instance for database interactions.
existingResetPasswordRequest
- Purpose: Represents the structure of an existing reset password request in the
reset_password_request
table. - Parameters:
- bun.BaseModel: Embeds the base model for bun ORM.
- ID: int - The primary key ID of the request.
- Token: string - The reset token.
- UserID: string - The ID of the user requesting the reset.
newResetPasswordRequest
- Purpose: Represents the structure of a new reset password request in the
reset_password_request_new
table. - Parameters:
- bun.BaseModel: Embeds the base model for bun ORM.
- types.Identifiable: Embeds a struct containing the
ID
field. - Token: string - The reset token.
- UserID: string - The ID of the user requesting the reset.
existingPersonalAccessToken
- Purpose: Represents the structure of an existing personal access token in the
personal_access_tokens
table. - Parameters:
- bun.BaseModel: Embeds the base model for bun ORM.
- types.TimeAuditable: Embeds a struct containing
CreatedAt
andUpdatedAt
timestamps. - OrgID: string - The ID of the organization the token belongs to.
- ID: int - The primary key ID of the token.
- Role: string - The role associated with the token (default: 'ADMIN').
- UserID: string - The ID of the user who owns the token.
- Token: string - The actual access token.
- Name: string - The name of the token.
- ExpiresAt: int64 - The expiration timestamp of the token.
- LastUsed: int64 - The last used timestamp of the token.
- Revoked: bool - Indicates if the token has been revoked.
- UpdatedByUserID: string - The ID of the user who last updated the token.
newPersonalAccessToken
- Purpose: Represents the structure of a new personal access token in the
personal_access_token
table. - Parameters:
- bun.BaseModel: Embeds the base model for bun ORM.
- types.Identifiable: Embeds a struct containing the
ID
field. - types.TimeAuditable: Embeds a struct containing
CreatedAt
andUpdatedAt
timestamps. - OrgID: string - The ID of the organization the token belongs to.
- Role: string - The role associated with the token (default: 'ADMIN').
- UserID: string - The ID of the user who owns the token.
- Token: string - The actual access token.
- Name: string - The name of the token.
- ExpiresAt: int64 - The expiration timestamp of the token.
- LastUsed: int64 - The last used timestamp of the token.
- Revoked: bool - Indicates if the token has been revoked.
- UpdatedByUserID: string - The ID of the user who last updated the token.
NewUpdateResetPasswordFactory
- Purpose: Creates a factory for the
updateResetPassword
migration. - Parameters:
- sqlstore: sqlstore.SQLStore - An SQLStore instance.
- Returns: factory.ProviderFactory[SQLMigration, Config] - A factory for creating
SQLMigration
instances.
newUpdateResetPassword
- Purpose: Creates a new
updateResetPassword
instance. - Parameters:
- _ context.Context: Context.
- _ factory.ProviderSettings: Provider settings.
- _ Config: Configuration.
- store: sqlstore.SQLStore - The SQL store.
- Returns: SQLMigration, error - The new migration instance, or an error if creation fails.
Register
- Purpose: Registers the up and down migrations.
- Parameters:
- migrations: *migrate.Migrations - The migrations to register with.
- Returns: error - An error if registration fails.
Up
- Purpose: Implements the "up" migration logic, moving data from old tables to new tables.
- Parameters:
- ctx: context.Context - The context for the operation.
- db: *bun.DB - The database connection.
- Returns: error - An error if the migration fails.
Down
- Purpose: Implements the "down" migration logic (currently a no-op).
- Parameters:
- ctx: context.Context - The context for the operation.
- db: *bun.DB - The database connection.
- Returns: error - Always returns nil.
CopyExistingResetPasswordRequestsToNewResetPasswordRequests
- Purpose: Copies existing reset password requests from the old format to the new format.
- Parameters:
- existingPasswordRequests: []*existingResetPasswordRequest - A slice of existing reset password requests.
- Returns: []*newResetPasswordRequest - A slice of new reset password requests.
CopyExistingPATsToNewPATs
- Purpose: Copies existing personal access tokens from the old format to the new format.
- Parameters:
- existingPATs: []*existingPersonalAccessToken - A slice of existing personal access tokens.
- Returns: []*newPersonalAccessToken - A slice of new personal access tokens.
Include in Getting Started: NO