sql

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Feb 20, 2024 License: Apache-2.0 Imports: 52 Imported by: 0

README

SQL Migrations

Migrations consist of one up and one down file. To create these SQL migrations, copy the last migration in ./persistence/sql/migrations/sql and change the timestamp to the current timestamp and the name to the desired name.

If some logic is different for one of the database systems, add the id after the name to the file name. The content of that file will override the content of the "general" file for that particular DB system.

Example:

20220802103909000000_courier_send_count.up.sql and 20220802103909000000_courier_send_count.down.sql

With for example cockroach specific behavior:

20220802103909000000_courier_send_count.cockroach.up.sql and 20220802103909000000_courier_send_count.cockroach.down.sql

Replace cockroach with mysql, postgres or sqlite if applicable.

Old Way

To create SQL migrations, target each database individually and run

$ dialect=mysql  # or postgres|cockroach|sqlite
$ name=
$ ory dev pop migration create -d=$dialect ./persistence/sql/migrations/templates $name
$ soda generate sql -e mysql -c ./persistence/sql/.soda.yml -p ./persistence/sql/migrations/templates [name]
$ soda generate sql -e sqlite -c ./persistence/sql/.soda.yml -p ./persistence/sql/migrations/templates [name]
$ soda generate sql -e postgres -c ./persistence/sql/.soda.yml -p ./persistence/sql/migrations/templates [name]
$ soda generate sql -e cockroach -c ./persistence/sql/.soda.yml -p ./persistence/sql/migrations/templates [name]

and remove the sqlite part from the newly generated file to create a SQL migrations that works with all aforementioned databases.

Rendering Migrations

Because migrations needs to be backwards compatible, and because fizz migrations might change, we render fizz migrations to raw SQL statements using make migrations-render.

The concrete migrations being applied can be found in ./migrations/sql.

Documentation

Index

Constants

View Source
const (
	SessionDeviceUserAgentMaxLength = 512
	SessionDeviceLocationMaxLength  = 512
)

Variables

This section is empty.

Functions

func WithDisabledLogging added in v1.1.0

func WithDisabledLogging(v bool) persisterOption

func WithExtraMigrations added in v1.1.0

func WithExtraMigrations(fss ...fs.FS) persisterOption

func WithTransaction

func WithTransaction(ctx context.Context, tx *pop.Connection) context.Context

Types

type Persister

type Persister struct {
	identity.PrivilegedPool
	session.DevicePersister
	// contains filtered or unexported fields
}

func NewPersister

func NewPersister(ctx context.Context, r persisterDependencies, c *pop.Connection, opts ...persisterOption) (*Persister, error)

func (*Persister) AddMessage

func (p *Persister) AddMessage(ctx context.Context, m *courier.Message) (err error)

func (*Persister) CleanupDatabase added in v0.11.0

func (p *Persister) CleanupDatabase(ctx context.Context, wait time.Duration, older time.Duration, batchSize int) error

func (*Persister) ClearErrorContainers added in v0.13.0

func (p *Persister) ClearErrorContainers(ctx context.Context, olderThan time.Duration, force bool) (err error)

func (*Persister) Close

func (p *Persister) Close(ctx context.Context) error

func (*Persister) CodeForFlow added in v1.0.0

func (p *Persister) CodeForFlow(ctx context.Context, flowID uuid.UUID) (codes *sessiontokenexchange.Codes, found bool, err error)

func (*Persister) Connection

func (p *Persister) Connection(ctx context.Context) *pop.Connection

func (*Persister) CreateErrorContainer added in v0.13.0

func (p *Persister) CreateErrorContainer(ctx context.Context, csrfToken string, errs error) (containerID uuid.UUID, err error)

func (*Persister) CreateLoginCode added in v1.1.0

func (p *Persister) CreateLoginCode(ctx context.Context, params *code.CreateLoginCodeParams) (_ *code.LoginCode, err error)

func (*Persister) CreateLoginFlow

func (p *Persister) CreateLoginFlow(ctx context.Context, r *login.Flow) (err error)

func (*Persister) CreateRecoveryCode added in v0.11.0

func (p *Persister) CreateRecoveryCode(ctx context.Context, params *code.CreateRecoveryCodeParams) (_ *code.RecoveryCode, err error)

func (*Persister) CreateRecoveryFlow

func (p *Persister) CreateRecoveryFlow(ctx context.Context, r *recovery.Flow) (err error)

func (*Persister) CreateRecoveryToken

func (p *Persister) CreateRecoveryToken(ctx context.Context, token *link.RecoveryToken) (err error)

func (*Persister) CreateRegistrationCode added in v1.1.0

func (p *Persister) CreateRegistrationCode(ctx context.Context, params *code.CreateRegistrationCodeParams) (_ *code.RegistrationCode, err error)

func (*Persister) CreateRegistrationFlow

func (p *Persister) CreateRegistrationFlow(ctx context.Context, r *registration.Flow) (err error)

func (*Persister) CreateSessionTokenExchanger added in v1.0.0

func (p *Persister) CreateSessionTokenExchanger(ctx context.Context, flowID uuid.UUID) (e *sessiontokenexchange.Exchanger, err error)

func (*Persister) CreateSettingsFlow

func (p *Persister) CreateSettingsFlow(ctx context.Context, r *settings.Flow) (err error)

func (*Persister) CreateVerificationCode added in v0.11.0

func (p *Persister) CreateVerificationCode(ctx context.Context, params *code.CreateVerificationCodeParams) (_ *code.VerificationCode, err error)

func (*Persister) CreateVerificationFlow

func (p *Persister) CreateVerificationFlow(ctx context.Context, r *verification.Flow) (err error)

func (*Persister) CreateVerificationToken

func (p *Persister) CreateVerificationToken(ctx context.Context, token *link.VerificationToken) (err error)

func (*Persister) DeleteContinuitySession

func (p *Persister) DeleteContinuitySession(ctx context.Context, id uuid.UUID) (err error)

func (*Persister) DeleteExpiredContinuitySessions added in v0.11.0

func (p *Persister) DeleteExpiredContinuitySessions(ctx context.Context, expiresAt time.Time, limit int) (err error)

func (*Persister) DeleteExpiredExchangers added in v1.0.0

func (p *Persister) DeleteExpiredExchangers(ctx context.Context, at time.Time, limit int) error

func (*Persister) DeleteExpiredLoginFlows added in v0.11.0

func (p *Persister) DeleteExpiredLoginFlows(ctx context.Context, expiresAt time.Time, limit int) (err error)

func (*Persister) DeleteExpiredRecoveryFlows added in v0.11.0

func (p *Persister) DeleteExpiredRecoveryFlows(ctx context.Context, expiresAt time.Time, limit int) (err error)

func (*Persister) DeleteExpiredRegistrationFlows added in v0.11.0

func (p *Persister) DeleteExpiredRegistrationFlows(ctx context.Context, expiresAt time.Time, limit int) (err error)

func (*Persister) DeleteExpiredSessions added in v0.11.0

func (p *Persister) DeleteExpiredSessions(ctx context.Context, expiresAt time.Time, limit int) (err error)

func (*Persister) DeleteExpiredSettingsFlows added in v0.11.0

func (p *Persister) DeleteExpiredSettingsFlows(ctx context.Context, expiresAt time.Time, limit int) (err error)

func (*Persister) DeleteExpiredVerificationFlows added in v0.11.0

func (p *Persister) DeleteExpiredVerificationFlows(ctx context.Context, expiresAt time.Time, limit int) (err error)

func (*Persister) DeleteLoginCodesOfFlow added in v1.1.0

func (p *Persister) DeleteLoginCodesOfFlow(ctx context.Context, flowID uuid.UUID) (err error)

func (*Persister) DeleteRecoveryCodesOfFlow added in v0.11.0

func (p *Persister) DeleteRecoveryCodesOfFlow(ctx context.Context, flowID uuid.UUID) (err error)

func (*Persister) DeleteRecoveryToken

func (p *Persister) DeleteRecoveryToken(ctx context.Context, token string) (err error)

func (*Persister) DeleteRegistrationCodesOfFlow added in v1.1.0

func (p *Persister) DeleteRegistrationCodesOfFlow(ctx context.Context, flowID uuid.UUID) (err error)

func (*Persister) DeleteSession

func (p *Persister) DeleteSession(ctx context.Context, sid uuid.UUID) (err error)

func (*Persister) DeleteSessionByToken

func (p *Persister) DeleteSessionByToken(ctx context.Context, token string) (err error)

func (*Persister) DeleteSessionsByIdentity

func (p *Persister) DeleteSessionsByIdentity(ctx context.Context, identityID uuid.UUID) (err error)

func (*Persister) DeleteVerificationCodesOfFlow added in v0.11.0

func (p *Persister) DeleteVerificationCodesOfFlow(ctx context.Context, fID uuid.UUID) (err error)

func (*Persister) DeleteVerificationToken

func (p *Persister) DeleteVerificationToken(ctx context.Context, token string) (err error)

func (*Persister) DetermineNetwork

func (p *Persister) DetermineNetwork(ctx context.Context) (*networkx.Network, error)

func (*Persister) FetchMessage added in v0.11.1

func (p *Persister) FetchMessage(ctx context.Context, msgID uuid.UUID) (_ *courier.Message, err error)

func (*Persister) ForceLoginFlow

func (p *Persister) ForceLoginFlow(ctx context.Context, id uuid.UUID) (err error)

func (*Persister) GetConnection

func (p *Persister) GetConnection(ctx context.Context) *pop.Connection

func (*Persister) GetContinuitySession

func (p *Persister) GetContinuitySession(ctx context.Context, id uuid.UUID) (_ *continuity.Container, err error)

func (*Persister) GetExchangerFromCode added in v1.0.0

func (p *Persister) GetExchangerFromCode(ctx context.Context, initCode string, returnToCode string) (e *sessiontokenexchange.Exchanger, err error)

func (*Persister) GetLoginFlow

func (p *Persister) GetLoginFlow(ctx context.Context, id uuid.UUID) (_ *login.Flow, err error)

func (*Persister) GetRecoveryFlow

func (p *Persister) GetRecoveryFlow(ctx context.Context, id uuid.UUID) (_ *recovery.Flow, err error)

func (*Persister) GetRegistrationFlow

func (p *Persister) GetRegistrationFlow(ctx context.Context, id uuid.UUID) (_ *registration.Flow, err error)

func (*Persister) GetSession

func (p *Persister) GetSession(ctx context.Context, sid uuid.UUID, expandables session.Expandables) (_ *session.Session, err error)

func (*Persister) GetSessionByToken

func (p *Persister) GetSessionByToken(ctx context.Context, token string, expand session.Expandables, identityExpand identity.Expandables) (res *session.Session, err error)

func (*Persister) GetSettingsFlow

func (p *Persister) GetSettingsFlow(ctx context.Context, id uuid.UUID) (_ *settings.Flow, err error)

func (*Persister) GetUsedLoginCode added in v1.1.0

func (p *Persister) GetUsedLoginCode(ctx context.Context, flowID uuid.UUID) (_ *code.LoginCode, err error)

func (*Persister) GetUsedRegistrationCode added in v1.1.0

func (p *Persister) GetUsedRegistrationCode(ctx context.Context, flowID uuid.UUID) (_ *code.RegistrationCode, err error)

func (*Persister) GetVerificationFlow

func (p *Persister) GetVerificationFlow(ctx context.Context, id uuid.UUID) (_ *verification.Flow, err error)

func (*Persister) IncrementMessageSendCount added in v0.11.0

func (p *Persister) IncrementMessageSendCount(ctx context.Context, id uuid.UUID) (err error)

func (*Persister) LatestQueuedMessage

func (p *Persister) LatestQueuedMessage(ctx context.Context) (_ *courier.Message, err error)

func (*Persister) ListMessages added in v0.11.0

func (*Persister) ListSessions added in v0.11.0

func (p *Persister) ListSessions(ctx context.Context, active *bool, paginatorOpts []keysetpagination.Option, expandables session.Expandables) (_ []session.Session, _ int64, _ *keysetpagination.Paginator, err error)

func (*Persister) ListSessionsByIdentity

func (p *Persister) ListSessionsByIdentity(
	ctx context.Context,
	iID uuid.UUID,
	active *bool,
	page, perPage int,
	except uuid.UUID,
	expandables session.Expandables,
) (_ []session.Session, _ int64, err error)

ListSessionsByIdentity retrieves sessions for an identity from the store.

func (*Persister) MigrateDown

func (p *Persister) MigrateDown(ctx context.Context, steps int) error

func (*Persister) MigrateUp

func (p *Persister) MigrateUp(ctx context.Context) error

func (*Persister) MigrationBox added in v0.13.0

func (p *Persister) MigrationBox() *popx.MigrationBox

func (*Persister) MigrationStatus

func (p *Persister) MigrationStatus(ctx context.Context) (_ popx.MigrationStatuses, err error)

func (*Persister) Migrator

func (p *Persister) Migrator() *popx.Migrator

func (*Persister) MoveToNewFlow added in v1.0.0

func (p *Persister) MoveToNewFlow(ctx context.Context, oldFlow, newFlow uuid.UUID) (err error)

func (*Persister) NetworkID

func (p *Persister) NetworkID(ctx context.Context) uuid.UUID

func (*Persister) NextMessages

func (p *Persister) NextMessages(ctx context.Context, limit uint8) (messages []courier.Message, err error)

func (*Persister) Ping

func (p *Persister) Ping() error

func (*Persister) ReadErrorContainer added in v0.13.0

func (p *Persister) ReadErrorContainer(ctx context.Context, id uuid.UUID) (_ *errorx.ErrorContainer, err error)

func (*Persister) RecordDispatch added in v0.11.1

func (p *Persister) RecordDispatch(ctx context.Context, msgID uuid.UUID, status courier.CourierMessageDispatchStatus, err error) error

func (*Persister) RevokeSession

func (p *Persister) RevokeSession(ctx context.Context, iID, sID uuid.UUID) (err error)

RevokeSession revokes a given session. If the session does not exist or was not modified, it effectively has been revoked already, and therefore that case does not return an error.

func (*Persister) RevokeSessionById added in v0.11.0

func (p *Persister) RevokeSessionById(ctx context.Context, sID uuid.UUID) (err error)

RevokeSessionById revokes a given session

func (*Persister) RevokeSessionByToken

func (p *Persister) RevokeSessionByToken(ctx context.Context, token string) (err error)

func (*Persister) RevokeSessionsIdentityExcept

func (p *Persister) RevokeSessionsIdentityExcept(ctx context.Context, iID, sID uuid.UUID) (res int, err error)

RevokeSessionsIdentityExcept marks all except the given session of an identity inactive.

func (*Persister) SaveContinuitySession

func (p *Persister) SaveContinuitySession(ctx context.Context, c *continuity.Container) (err error)

func (*Persister) SetMessageStatus

func (p *Persister) SetMessageStatus(ctx context.Context, id uuid.UUID, ms courier.MessageStatus) (err error)

func (*Persister) Transaction

func (p *Persister) Transaction(ctx context.Context, callback func(ctx context.Context, connection *pop.Connection) error) error

func (*Persister) UpdateLoginFlow

func (p *Persister) UpdateLoginFlow(ctx context.Context, r *login.Flow) (err error)

func (*Persister) UpdateRecoveryFlow

func (p *Persister) UpdateRecoveryFlow(ctx context.Context, r *recovery.Flow) (err error)

func (*Persister) UpdateRegistrationFlow

func (p *Persister) UpdateRegistrationFlow(ctx context.Context, r *registration.Flow) (err error)

func (*Persister) UpdateSessionOnExchanger added in v1.0.0

func (p *Persister) UpdateSessionOnExchanger(ctx context.Context, flowID uuid.UUID, sessionID uuid.UUID) (err error)

func (*Persister) UpdateSettingsFlow

func (p *Persister) UpdateSettingsFlow(ctx context.Context, r *settings.Flow) (err error)

func (*Persister) UpdateVerificationFlow

func (p *Persister) UpdateVerificationFlow(ctx context.Context, r *verification.Flow) (err error)

func (*Persister) UpsertSession

func (p *Persister) UpsertSession(ctx context.Context, s *session.Session) (err error)

UpsertSession creates a session if not found else updates. This operation also inserts Session device records when a session is being created. The update operation skips updating Session device records since only one record would need to be updated in this case.

func (*Persister) UseLoginCode added in v1.1.0

func (p *Persister) UseLoginCode(ctx context.Context, flowID uuid.UUID, identityID uuid.UUID, userProvidedCode string) (_ *code.LoginCode, err error)

func (*Persister) UseRecoveryCode added in v0.11.0

func (p *Persister) UseRecoveryCode(ctx context.Context, flowID uuid.UUID, userProvidedCode string) (_ *code.RecoveryCode, err error)

UseRecoveryCode attempts to "use" the supplied code in the flow

If the supplied code matched a code from the flow, no error is returned If an invalid code was submitted with this flow more than 5 times, an error is returned

func (*Persister) UseRecoveryToken

func (p *Persister) UseRecoveryToken(ctx context.Context, fID uuid.UUID, token string) (_ *link.RecoveryToken, err error)

func (*Persister) UseRegistrationCode added in v1.1.0

func (p *Persister) UseRegistrationCode(ctx context.Context, flowID uuid.UUID, userProvidedCode string, addresses ...string) (_ *code.RegistrationCode, err error)

func (*Persister) UseVerificationCode added in v0.11.0

func (p *Persister) UseVerificationCode(ctx context.Context, flowID uuid.UUID, userProvidedCode string) (_ *code.VerificationCode, err error)

func (*Persister) UseVerificationToken

func (p *Persister) UseVerificationToken(ctx context.Context, fID uuid.UUID, token string) (_ *link.VerificationToken, err error)

func (Persister) WithNetworkID

func (p Persister) WithNetworkID(nid uuid.UUID) persistence.Persister

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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