postgres

package
v1.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 3, 2026 License: MIT Imports: 11 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package postgres provides a Postgres Store implementation and schema migration for Canopy.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type SchemaMigration added in v1.0.0

type SchemaMigration struct {
	Version int64
	Name    string
	SQL     string
}

SchemaMigration is one ordered Canopy database migration.

func Migrations added in v1.0.0

func Migrations() []SchemaMigration

Migrations returns the ordered schema migrations for deployments that use an external migration runner.

type Store

type Store struct {
	// contains filtered or unexported fields
}

func New

func New(db *sql.DB) *Store

func (*Store) AcceptInvitation added in v1.0.0

func (s *Store) AcceptInvitation(
	ctx context.Context,
	invitationID string,
	email string,
	now time.Time,
	member *canopy.Member,
) error

func (*Store) AddTeamMember added in v1.0.0

func (s *Store) AddTeamMember(ctx context.Context, member *canopy.TeamMember) error

func (*Store) ApplyPasswordReset added in v1.0.0

func (s *Store) ApplyPasswordReset(
	ctx context.Context,
	identifier string,
	value string,
	now time.Time,
	account *canopy.Account,
) error

ApplyPasswordReset atomically consumes one reset token, updates the account, revokes sessions, and removes every other reset token for the identifier.

func (*Store) CleanupExpired added in v1.0.0

func (s *Store) CleanupExpired(ctx context.Context, now time.Time) error

CleanupExpired removes expired session and verification records atomically.

func (*Store) ClearActiveOrganization added in v1.0.0

func (s *Store) ClearActiveOrganization(ctx context.Context, orgID, userID string) error

func (*Store) ConsumeBackupCode added in v1.0.0

func (s *Store) ConsumeBackupCode(ctx context.Context, userID, codeHash string) (bool, error)

func (*Store) ConsumeTOTPStep added in v1.0.0

func (s *Store) ConsumeTOTPStep(ctx context.Context, userID string, counter int64) (bool, error)

func (*Store) ConsumeVerification

func (s *Store) ConsumeVerification(ctx context.Context, identifier, value string, now time.Time) (*canopy.Verification, error)

func (*Store) CreateAccount

func (s *Store) CreateAccount(ctx context.Context, a *canopy.Account) error

func (*Store) CreateInvitation added in v1.0.0

func (s *Store) CreateInvitation(ctx context.Context, invitation *canopy.Invitation) error

func (*Store) CreateLinkedAccount added in v1.0.0

func (s *Store) CreateLinkedAccount(
	ctx context.Context,
	identifier string,
	value string,
	now time.Time,
	account *canopy.Account,
) error

CreateLinkedAccount atomically consumes the one-time link-confirmation verification and creates the provider account in one transaction. It reuses the existing verification and account tables, so it needs no schema migration.

func (*Store) CreateMember added in v1.0.0

func (s *Store) CreateMember(ctx context.Context, member *canopy.Member) error

func (*Store) CreateOrganization added in v1.0.0

func (s *Store) CreateOrganization(ctx context.Context, org *canopy.Organization) error

func (*Store) CreateOrganizationWithOwner added in v1.0.0

func (s *Store) CreateOrganizationWithOwner(ctx context.Context, org *canopy.Organization, owner *canopy.Member) error

func (*Store) CreateSession

func (s *Store) CreateSession(ctx context.Context, ses *canopy.Session) error

func (*Store) CreateTeam added in v1.0.0

func (s *Store) CreateTeam(ctx context.Context, team *canopy.Team) error

func (*Store) CreateUser

func (s *Store) CreateUser(ctx context.Context, u *canopy.User) error

func (*Store) CreateUserAccount added in v0.1.1

func (s *Store) CreateUserAccount(ctx context.Context, u *canopy.User, a *canopy.Account) error

func (*Store) CreateVerification

func (s *Store) CreateVerification(ctx context.Context, v *canopy.Verification) error

func (*Store) DeleteExpiredSessions added in v1.0.0

func (s *Store) DeleteExpiredSessions(ctx context.Context, now time.Time) error

func (*Store) DeleteExpiredVerifications

func (s *Store) DeleteExpiredVerifications(ctx context.Context, now time.Time) error

func (*Store) DeleteMember added in v1.0.0

func (s *Store) DeleteMember(ctx context.Context, orgID, userID string) error

func (*Store) DeleteOrganization added in v1.0.0

func (s *Store) DeleteOrganization(ctx context.Context, id string) error

func (*Store) DeleteSessionByToken

func (s *Store) DeleteSessionByToken(ctx context.Context, token string) error

func (*Store) DeleteTeam added in v1.0.0

func (s *Store) DeleteTeam(ctx context.Context, orgID, teamID string) error

DeleteTeam removes the team and its team memberships atomically.

func (*Store) DeleteTwoFactor added in v1.0.0

func (s *Store) DeleteTwoFactor(ctx context.Context, userID string) error

func (*Store) DeleteUserSessions

func (s *Store) DeleteUserSessions(ctx context.Context, userID string) error

func (*Store) DeleteVerificationsByIdentifier added in v1.0.0

func (s *Store) DeleteVerificationsByIdentifier(ctx context.Context, identifier string) error

func (*Store) EnableTwoFactor added in v1.0.0

func (s *Store) EnableTwoFactor(ctx context.Context, tf *canopy.TwoFactor, codeHashes []string) error

func (*Store) FindAccount

func (s *Store) FindAccount(ctx context.Context, providerID, accountID string) (*canopy.Account, error)

func (*Store) FindAccountByUserProvider

func (s *Store) FindAccountByUserProvider(ctx context.Context, userID, providerID string) (*canopy.Account, error)

func (*Store) FindInvitation added in v1.0.0

func (s *Store) FindInvitation(ctx context.Context, id string) (*canopy.Invitation, error)

func (*Store) FindMember added in v1.0.0

func (s *Store) FindMember(ctx context.Context, orgID, userID string) (*canopy.Member, error)

func (*Store) FindOrganizationByID added in v1.0.0

func (s *Store) FindOrganizationByID(ctx context.Context, id string) (*canopy.Organization, error)

func (*Store) FindOrganizationBySlug added in v1.0.0

func (s *Store) FindOrganizationBySlug(ctx context.Context, slug string) (*canopy.Organization, error)

func (*Store) FindSessionByToken

func (s *Store) FindSessionByToken(ctx context.Context, token string) (*canopy.SessionData, error)

func (*Store) FindTeamByID added in v1.0.0

func (s *Store) FindTeamByID(ctx context.Context, id string) (*canopy.Team, error)

func (*Store) FindTeamMember added in v1.0.0

func (s *Store) FindTeamMember(ctx context.Context, teamID, userID string) (*canopy.TeamMember, error)

func (*Store) FindUserByEmail

func (s *Store) FindUserByEmail(ctx context.Context, email string) (*canopy.User, error)

func (*Store) FindUserByID

func (s *Store) FindUserByID(ctx context.Context, id string) (*canopy.User, error)

func (*Store) GetTwoFactor added in v1.0.0

func (s *Store) GetTwoFactor(ctx context.Context, userID string) (*canopy.TwoFactor, error)

func (*Store) ListInvitationsForOrg added in v1.0.0

func (s *Store) ListInvitationsForOrg(ctx context.Context, orgID string) ([]canopy.Invitation, error)

func (*Store) ListMembers added in v1.0.0

func (s *Store) ListMembers(ctx context.Context, orgID string) ([]canopy.Member, error)

func (*Store) ListOrganizationsForUser added in v1.0.0

func (s *Store) ListOrganizationsForUser(ctx context.Context, userID string) ([]canopy.Organization, error)

func (*Store) ListTeamMembers added in v1.0.0

func (s *Store) ListTeamMembers(ctx context.Context, teamID string) ([]canopy.TeamMember, error)

func (*Store) ListTeamsForOrg added in v1.0.0

func (s *Store) ListTeamsForOrg(ctx context.Context, orgID string) ([]canopy.Team, error)

func (*Store) ListUserSessions added in v1.0.0

func (s *Store) ListUserSessions(ctx context.Context, userID string) ([]canopy.Session, error)

func (*Store) ListUsers added in v1.0.0

func (s *Store) ListUsers(ctx context.Context, q canopy.UserQuery) ([]canopy.User, int, error)

func (*Store) Migrate

func (s *Store) Migrate(ctx context.Context) error

func (*Store) RemoveMemberAndClearSessions added in v1.0.0

func (s *Store) RemoveMemberAndClearSessions(ctx context.Context, orgID, userID string, now time.Time) error

func (*Store) RemoveTeamMember added in v1.0.0

func (s *Store) RemoveTeamMember(ctx context.Context, teamID, userID string) error

func (*Store) ReplaceBackupCodes added in v1.0.0

func (s *Store) ReplaceBackupCodes(ctx context.Context, userID string, codeHashes []string) error

func (*Store) ReplaceVerification added in v1.0.0

func (s *Store) ReplaceVerification(ctx context.Context, v *canopy.Verification) error

func (*Store) UpdateAccount

func (s *Store) UpdateAccount(ctx context.Context, a *canopy.Account) error

func (*Store) UpdateInvitation added in v1.0.0

func (s *Store) UpdateInvitation(ctx context.Context, invitation *canopy.Invitation) error

func (*Store) UpdateMember added in v1.0.0

func (s *Store) UpdateMember(ctx context.Context, member *canopy.Member) error

func (*Store) UpdateMemberRole added in v1.0.0

func (s *Store) UpdateMemberRole(ctx context.Context, member *canopy.Member, protectedRole string) error

func (*Store) UpdateOrganization added in v1.0.0

func (s *Store) UpdateOrganization(ctx context.Context, org *canopy.Organization) error

func (*Store) UpdateSession

func (s *Store) UpdateSession(ctx context.Context, ses *canopy.Session) error

func (*Store) UpdateTeam added in v1.0.0

func (s *Store) UpdateTeam(ctx context.Context, team *canopy.Team) error

func (*Store) UpdateUser

func (s *Store) UpdateUser(ctx context.Context, u *canopy.User) error

func (*Store) UpsertTwoFactor added in v1.0.0

func (s *Store) UpsertTwoFactor(ctx context.Context, tf *canopy.TwoFactor) error

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL