sql

package
v0.11.0-alpha.0.pre.1 Latest Latest
Warning

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

Go to latest
Published: Nov 21, 2022 License: Apache-2.0 Imports: 43 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 {
	// contains filtered or unexported fields
}

func NewPersister

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

func (*Persister) Add

func (p *Persister) Add(ctx context.Context, csrfToken string, errs error) (uuid.UUID, 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) Clear

func (p *Persister) Clear(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) CountIdentities

func (p *Persister) CountIdentities(ctx context.Context) (int64, error)

func (*Persister) CreateIdentity

func (p *Persister) CreateIdentity(ctx context.Context, i *identity.Identity) error

func (*Persister) CreateLoginFlow

func (p *Persister) CreateLoginFlow(ctx context.Context, r *login.Flow) 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) 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) 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) DeleteIdentity

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

func (*Persister) DeleteSessionByToken

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

func (*Persister) DeleteSessionsByIdentity

func (p *Persister) DeleteSessionsByIdentity(ctx context.Context, identityID 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) FindByCredentialsIdentifier

func (p *Persister) FindByCredentialsIdentifier(ctx context.Context, ct identity.CredentialsType, match string) (*identity.Identity, *identity.Credentials, error)

func (*Persister) FindRecoveryAddressByValue

func (p *Persister) FindRecoveryAddressByValue(ctx context.Context, via identity.RecoveryAddressType, value string) (*identity.RecoveryAddress, error)

func (*Persister) FindVerifiableAddressByValue

func (p *Persister) FindVerifiableAddressByValue(ctx context.Context, via identity.VerifiableAddressType, value string) (*identity.VerifiableAddress, 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) GetIdentity

func (p *Persister) GetIdentity(ctx context.Context, id uuid.UUID) (*identity.Identity, error)

func (*Persister) GetIdentityConfidential

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

func (*Persister) GetSessionByToken

func (p *Persister) GetSessionByToken(ctx context.Context, token string, expandables session.Expandables) (*session.Session, 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) ListIdentities

func (p *Persister) ListIdentities(ctx context.Context, page, perPage int) ([]identity.Identity, error)

func (*Persister) ListMessages added in v0.11.0

func (p *Persister) ListMessages(ctx context.Context, filter courier.MessagesFilter) ([]courier.Message, int64, error)

func (*Persister) ListRecoveryAddresses

func (p *Persister) ListRecoveryAddresses(ctx context.Context, page, itemsPerPage int) (a []identity.RecoveryAddress, 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, error)

ListSessionsByIdentity retrieves sessions for an identity from the store.

func (*Persister) ListVerifiableAddresses

func (p *Persister) ListVerifiableAddresses(ctx context.Context, page, itemsPerPage int) (a []identity.VerifiableAddress, err error)

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

func (*Persister) RevokeSession

func (p *Persister) RevokeSession(ctx context.Context, iID, sID uuid.UUID) 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) RevokeSessionByToken

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

func (*Persister) RevokeSessionsIdentityExcept

func (p *Persister) RevokeSessionsIdentityExcept(ctx context.Context, iID, sID uuid.UUID) (int, 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) UpdateIdentity

func (p *Persister) UpdateIdentity(ctx context.Context, i *identity.Identity) 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) UpdateVerifiableAddress

func (p *Persister) UpdateVerifiableAddress(ctx context.Context, address *identity.VerifiableAddress) 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) 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) UseRecoveryToken

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

func (*Persister) UseVerificationToken

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

func (*Persister) VerifyAddress

func (p *Persister) VerifyAddress(ctx context.Context, code string) error

func (Persister) WithNetworkID

func (p Persister) WithNetworkID(sid 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