sql

package
v0.13.0 Latest Latest
Warning

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

Go to latest
Published: Apr 18, 2023 License: Apache-2.0 Imports: 45 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 SessionDeviceLocationMaxLength = 512
View Source
const SessionDeviceUserAgentMaxLength = 512

Variables

This section is empty.

Functions

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) (*Persister, error)

func (*Persister) AddMessage

func (p *Persister) AddMessage(ctx context.Context, m *courier.Message) 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) 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) CreateLoginFlow

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

func (*Persister) CreateRecoveryCode added in v0.11.0

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

func (*Persister) CreateRecoveryFlow

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

func (*Persister) CreateRecoveryToken

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

func (*Persister) CreateRegistrationFlow

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

func (*Persister) CreateSettingsFlow

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

func (*Persister) CreateVerificationCode added in v0.11.0

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

func (*Persister) CreateVerificationFlow

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

func (*Persister) CreateVerificationToken

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

func (*Persister) DeleteContinuitySession

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

func (*Persister) DeleteExpiredContinuitySessions added in v0.11.0

func (p *Persister) DeleteExpiredContinuitySessions(ctx context.Context, expiresAt 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) error

func (*Persister) DeleteExpiredRecoveryFlows added in v0.11.0

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

func (*Persister) DeleteExpiredRegistrationFlows added in v0.11.0

func (p *Persister) DeleteExpiredRegistrationFlows(ctx context.Context, expiresAt time.Time, limit int) 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) error

func (*Persister) DeleteExpiredVerificationFlows added in v0.11.0

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

func (*Persister) DeleteRecoveryCodesOfFlow added in v0.11.0

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

func (*Persister) DeleteRecoveryToken

func (p *Persister) DeleteRecoveryToken(ctx context.Context, token string) 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) error

func (*Persister) DeleteVerificationToken

func (p *Persister) DeleteVerificationToken(ctx context.Context, token string) 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, error)

func (*Persister) ForceLoginFlow

func (p *Persister) ForceLoginFlow(ctx context.Context, id uuid.UUID) 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, error)

func (*Persister) GetLoginFlow

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

func (*Persister) GetRecoveryFlow

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

func (*Persister) GetRegistrationFlow

func (p *Persister) GetRegistrationFlow(ctx context.Context, id uuid.UUID) (*registration.Flow, 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, error)

func (*Persister) GetVerificationFlow

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

func (*Persister) IncrementMessageSendCount added in v0.11.0

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

func (*Persister) LatestQueuedMessage

func (p *Persister) LatestQueuedMessage(ctx context.Context) (*courier.Message, 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, error)

func (*Persister) Migrator

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

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) error

func (*Persister) SetMessageStatus

func (p *Persister) SetMessageStatus(ctx context.Context, id uuid.UUID, ms courier.MessageStatus) 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) error

func (*Persister) UpdateRecoveryFlow

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

func (*Persister) UpdateRegistrationFlow

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

func (*Persister) UpdateSettingsFlow

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

func (*Persister) UpdateVerificationFlow

func (p *Persister) UpdateVerificationFlow(ctx context.Context, r *verification.Flow) 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) UseRecoveryCode added in v0.11.0

func (p *Persister) UseRecoveryCode(ctx context.Context, fID uuid.UUID, codeVal string) (*code.RecoveryCode, 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 TODO: Extract the business logic to a new service/manager (https://github.com/ory/kratos/issues/2785)

func (*Persister) UseRecoveryToken

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

func (*Persister) UseVerificationCode added in v0.11.0

func (p *Persister) UseVerificationCode(ctx context.Context, fID uuid.UUID, codeVal string) (*code.VerificationCode, error)

func (*Persister) UseVerificationToken

func (p *Persister) UseVerificationToken(ctx context.Context, fID uuid.UUID, token string) (*link.VerificationToken, 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