update_invites.go
019_update_invites.go - Overview
This file defines a SQL migration to update the invites table by renaming it, modifying its model, and copying data from the old table to the new one. It also includes the necessary structures and functions to perform this migration.
Detailed Documentation
updateInvites
struct
- Purpose: Represents the SQL migration for updating invites.
- Fields:
store
: Ansqlstore.SQLStore
instance, used for database interactions.
existingInvite
struct
- Purpose: Represents the structure of the existing
invites
table. - Fields:
bun.BaseModel
: Embedded struct for Bun ORM.OrgID
: Organization ID (string).ID
: Invite ID (int, primary key, autoincrement).Name
: Name associated with the invite (string).Email
: Email address of the invitee (string, unique).Token
: Invite token (string).CreatedAt
: Creation timestamp (time.Time).Role
: Role assigned to the invitee (string).
newInvite
struct
- Purpose: Represents the structure of the new
user_invite
table. - Fields:
bun.BaseModel
: Embedded struct for Bun ORM.types.Identifiable
: Embedded struct for identifiable entities (includes ID).types.TimeAuditable
: Embedded struct for time-auditable entities (includes CreatedAt and UpdatedAt).Name
: Name associated with the invite (string).Email
: Email address of the invitee (string, unique).Token
: Invite token (string).Role
: Role assigned to the invitee (string).OrgID
: Organization ID (string).
NewUpdateInvitesFactory
function
- Purpose: Creates a new factory for the
updateInvites
SQL migration. - Parameters:
sqlstore
: Ansqlstore.SQLStore
instance.
- Returns: A
factory.ProviderFactory[SQLMigration, Config]
instance.
newUpdateInvites
function
- Purpose: Creates a new
updateInvites
instance. - Parameters:
_
: Acontext.Context
(not used)._
: Afactory.ProviderSettings
(not used)._
: AConfig
(not used).store
: Ansqlstore.SQLStore
instance.
- Returns: An
SQLMigration
interface and an error.
(migration *updateInvites) Register
function
- Purpose: Registers the up and down migration functions with the
migrate.Migrations
instance. - Parameters:
migrations
: A pointer to amigrate.Migrations
instance.
- Returns: An error, if any.
(migration *updateInvites) Up
function
- Purpose: Implements the "up" migration logic, renaming the table, modifying the model, and copying existing invites.
- Parameters:
ctx
: Acontext.Context
.db
: A pointer to abun.DB
instance.
- Returns: An error, if any.
(migration *updateInvites) Down
function
- Purpose: Implements the "down" migration logic (currently a no-op).
- Parameters:
ctx
: Acontext.Context
.db
: A pointer to abun.DB
instance.
- Returns: An error, if any.
(migration *updateInvites) CopyOldInvitesToNewInvites
function
- Purpose: Copies data from
existingInvite
structs tonewInvite
structs. - Parameters:
existingInvites
: A slice of*existingInvite
structs.
- Returns: A slice of
*newInvite
structs.
Code Examples
None.
Include in Getting Started: NO