Documentation
¶
Overview ¶
Package postgres implements flexitype's repository ports over PostgreSQL. Every read path runs through request-scoped dataloaders (graph-gophers/dataloader): point lookups batch into ANY() queries, filtered List queries collapse into one UNION ALL statement across the batch's unique JSON filter keys, and per-parent pagination batches into a single windowed query. Queries are built with ? placeholders and rebound to $N via sqlx.
Index ¶
- func KnownSchemaVersion() (int, error)
- func Migrate(ctx context.Context, tx db.Transactor) error
- func MigrateDown(ctx context.Context, tx db.Transactor, target int) error
- func NewActivityEraser() erasure.ResidualEraser
- func NewActivityLog(pool db.QueryExecer) activity.Log
- func NewAdminStore(q db.QueryExecer) admin.Store
- func NewAttributeDefinitionRepository(q db.QueryExecer) domainattribute.Repository
- func NewAttributeValueRepository(q db.QueryExecer) domainvalue.Repository
- func NewChangeSetEraser() erasure.ResidualEraser
- func NewChangeSetStore(q db.QueryExecer) changeset.Store
- func NewCursorStore(q db.QueryExecer) feed.CursorStore
- func NewDeliveryStats(q db.QueryExecer) deliverystats.Source
- func NewDeliveryStore(q db.QueryExecer) webhook.DeliveryStore
- func NewDependencyRepository(q db.QueryExecer) domaindependency.Repository
- func NewFeedStore(q db.QueryExecer) feed.Store
- func NewMatchStore(q db.QueryExecer) dedup.Store
- func NewOutboxEraser() erasure.ResidualEraser
- func NewOutboxStore(tx db.Transactor, opts ...OutboxStoreOption) outbox.Store
- func NewQueryRepository(q db.QueryExecer) query.Repository
- func NewRelationshipDefinitionRepository(q db.QueryExecer) domainrelationship.DefinitionRepository
- func NewRelationshipRepository(q db.QueryExecer) domainrelationship.Repository
- func NewRepositories(pool db.QueryExecer) application.Repositories
- func NewRevisionStore(q db.QueryExecer) revision.Store
- func NewSavedViewStore(q db.QueryExecer) savedview.Store
- func NewSchemaVersionReader(q db.QueryExecer) application.SchemaVersionReader
- func NewSearchStore(q db.QueryExecer) search.DocumentStore
- func NewSubscriptionStore(q db.QueryExecer) webhook.SubscriptionStore
- func NewTypeDefinitionRepository(q db.QueryExecer) domaintypedef.Repository
- func NewUnitFamilyStore(q db.QueryExecer) unit.Store
- func UnknownSchemaVersions(ctx context.Context, q db.QueryExecer) ([]int, error)
- type AccountLookup
- type OutboxStoreOption
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func KnownSchemaVersion ¶ added in v1.3.0
KnownSchemaVersion is the highest migration version this binary carries. Compare it against the database to detect a mixed-version fleet.
func Migrate ¶
func Migrate(ctx context.Context, tx db.Transactor) error
Migrate applies embedded up-migrations in order, tracking progress in flexitype_schema_migrations, then runs any pending data backfills. It is safe to call on every startup and from embedded deployments: concurrent runners serialize on an advisory lock. Runtime is forward-only — down-migrations exist for local development and reversibility testing via MigrateDown, and are never applied at startup.
Each migration is applied in its own transaction, not all of them in one. The all-or-nothing form cannot coexist with the statements a large deployment needs: CREATE INDEX CONCURRENTLY is rejected inside a transaction block, and a data backfill held inside the schema transaction keeps its DDL locks for the whole scan — which is how a whole-table backfill came to block every value write in the fleet for the duration of the upgrade.
A migration file may carry directives in its header:
-- +flexitype:no-transaction
which runs its statements one at a time outside any transaction. Statements in such a file must be idempotent, because a failure part-way leaves the earlier ones applied and the file unrecorded.
See docs/upgrades.md for the rolling-upgrade contract and the rules for writing a migration that is safe against a live fleet.
func MigrateDown ¶
MigrateDown reverts applied migrations whose version is greater than target, newest first, running each .down.sql and removing its schema-migrations row. It is NOT called at startup; use it in local development and reversibility tests. target=0 reverts everything.
Like Migrate, each migration is reverted in its own transaction unless its down-file declares -- +flexitype:no-transaction, which a file dropping an index CONCURRENTLY must.
Rollback of a deployed release is redeploying the previous binary, not running this: see docs/upgrades.md.
func NewActivityEraser ¶ added in v1.3.0
func NewActivityEraser() erasure.ResidualEraser
NewActivityEraser builds the audit-log residual eraser.
func NewActivityLog ¶
func NewActivityLog(pool db.QueryExecer) activity.Log
NewActivityLog builds the activity-log adapter.
func NewAdminStore ¶
func NewAdminStore(q db.QueryExecer) admin.Store
NewAdminStore builds the tenant/service-account store.
func NewAttributeDefinitionRepository ¶
func NewAttributeDefinitionRepository(q db.QueryExecer) domainattribute.Repository
NewAttributeDefinitionRepository builds a dataloader-backed repository over the pool.
func NewAttributeValueRepository ¶
func NewAttributeValueRepository(q db.QueryExecer) domainvalue.Repository
NewAttributeValueRepository builds a dataloader-backed repository over the pool.
func NewChangeSetEraser ¶ added in v1.3.0
func NewChangeSetEraser() erasure.ResidualEraser
NewChangeSetEraser builds the change-set residual eraser.
func NewChangeSetStore ¶
func NewChangeSetStore(q db.QueryExecer) changeset.Store
NewChangeSetStore builds the change-set store over the pool.
func NewCursorStore ¶
func NewCursorStore(q db.QueryExecer) feed.CursorStore
NewCursorStore builds the feed-cursor adapter.
func NewDeliveryStats ¶
func NewDeliveryStats(q db.QueryExecer) deliverystats.Source
NewDeliveryStats builds the delivery-depth stats source.
func NewDeliveryStore ¶
func NewDeliveryStore(q db.QueryExecer) webhook.DeliveryStore
NewDeliveryStore builds the webhook-delivery adapter.
func NewDependencyRepository ¶
func NewDependencyRepository(q db.QueryExecer) domaindependency.Repository
NewDependencyRepository builds a dataloader-backed repository over the pool.
func NewFeedStore ¶
func NewFeedStore(q db.QueryExecer) feed.Store
NewFeedStore builds the events-feed adapter.
func NewMatchStore ¶
func NewMatchStore(q db.QueryExecer) dedup.Store
NewMatchStore builds the duplicate-detection store over the pool.
func NewOutboxEraser ¶ added in v1.3.0
func NewOutboxEraser() erasure.ResidualEraser
NewOutboxEraser builds the event-log residual eraser. It takes no executor: every redaction runs inside the erasure transaction it is handed.
func NewOutboxStore ¶
func NewOutboxStore(tx db.Transactor, opts ...OutboxStoreOption) outbox.Store
NewOutboxStore builds the outbox adapter over the pool transactor.
func NewQueryRepository ¶
func NewQueryRepository(q db.QueryExecer) query.Repository
NewQueryRepository builds the FQL execution adapter.
func NewRelationshipDefinitionRepository ¶
func NewRelationshipDefinitionRepository(q db.QueryExecer) domainrelationship.DefinitionRepository
NewRelationshipDefinitionRepository builds a dataloader-backed repository over the pool.
func NewRelationshipRepository ¶
func NewRelationshipRepository(q db.QueryExecer) domainrelationship.Repository
NewRelationshipRepository builds a dataloader-backed repository over the pool.
func NewRepositories ¶
func NewRepositories(pool db.QueryExecer) application.Repositories
NewRepositories builds one request-scoped repository set over the pool. Call once per request so dataloader caches die with the request.
func NewRevisionStore ¶
func NewRevisionStore(q db.QueryExecer) revision.Store
NewRevisionStore builds the entity-revision store over the pool.
func NewSavedViewStore ¶
func NewSavedViewStore(q db.QueryExecer) savedview.Store
NewSavedViewStore builds the saved-view store over the pool.
func NewSchemaVersionReader ¶ added in v1.1.0
func NewSchemaVersionReader(q db.QueryExecer) application.SchemaVersionReader
NewSchemaVersionReader builds the persisted schema-version reader over the pool.
func NewSearchStore ¶
func NewSearchStore(q db.QueryExecer) search.DocumentStore
NewSearchStore builds the search projection adapter.
func NewSubscriptionStore ¶
func NewSubscriptionStore(q db.QueryExecer) webhook.SubscriptionStore
NewSubscriptionStore builds the webhook-subscription adapter.
func NewTypeDefinitionRepository ¶
func NewTypeDefinitionRepository(q db.QueryExecer) domaintypedef.Repository
NewTypeDefinitionRepository builds a dataloader-backed repository over the pool.
func NewUnitFamilyStore ¶
func NewUnitFamilyStore(q db.QueryExecer) unit.Store
NewUnitFamilyStore builds the unit-family store over the pool.
func UnknownSchemaVersions ¶ added in v1.3.0
UnknownSchemaVersions returns the applied versions the binary does not carry — the schema is newer than this build. It is how a rolling deploy makes a mixed-version fleet visible: the previous generation keeps serving against a schema the next generation migrated, which flexitype supports (each release's migrations stay compatible with the previous binary), but an operator should still be able to see that it is happening.
It returns nothing when the migrations table does not exist yet.
Types ¶
type AccountLookup ¶
type AccountLookup struct {
// contains filtered or unexported fields
}
AccountLookup resolves bearer tokens against the service-account table. It satisfies serviceaccount.Authenticator so the auth middleware works over the database exactly as over the file store.
func NewAccountLookup ¶
func NewAccountLookup(q db.QueryExecer) *AccountLookup
NewAccountLookup builds the DB-backed authenticator.
func (*AccountLookup) Authenticate ¶
func (l *AccountLookup) Authenticate(token string) (serviceaccount.Account, error)
Authenticate resolves a token with a background context. The auth middleware prefers AuthenticateCtx (via the AuthenticatorCtx assertion) so the request context — cancellation, deadline, trace — reaches this per-request query.
func (*AccountLookup) AuthenticateCtx ¶ added in v1.1.0
func (l *AccountLookup) AuthenticateCtx(ctx context.Context, token string) (serviceaccount.Account, error)
AuthenticateCtx resolves a token to an account, verifying the secret hash in constant time and rejecting inactive accounts, under the caller's context.
type OutboxStoreOption ¶ added in v1.3.0
type OutboxStoreOption func(*outboxStore)
OutboxStoreOption customises the outbox adapter's retry scheduling.
func WithOutboxMaxAttempts ¶ added in v1.3.0
func WithOutboxMaxAttempts(n int) OutboxStoreOption
WithOutboxMaxAttempts sets how many failures park a row. Non-positive values are ignored.
func WithOutboxRetryCeiling ¶ added in v1.3.0
func WithOutboxRetryCeiling(d time.Duration) OutboxStoreOption
WithOutboxRetryCeiling caps the backoff between attempts. Non-positive values are ignored.
Source Files
¶
- activity_log.go
- admin_store.go
- attribute_definition.go
- attribute_value.go
- changeset_store.go
- delivery_stats.go
- dependency.go
- feed_store.go
- loaders.go
- match_store.go
- migrate.go
- migrate_backfill.go
- migrate_statements.go
- outbox.go
- postgres.go
- query.go
- relationship.go
- residual_eraser.go
- revision_store.go
- saved_view_store.go
- schema_version.go
- search_store.go
- type_definition.go
- unit_store.go
- value_columns.go
- webhook_store.go