postgres

package
v1.97.5 Latest Latest
Warning

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

Go to latest
Published: May 21, 2026 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Overview

Package postgres provides the Postgres concrete tenancy.Provider. It installs Row-Level Security policies at migration time and binds per-request tenancy state via pgxpool BeforeAcquire / AfterRelease hooks. Combined, application code never references tenant_id or partition_id directly.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Provider

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

Provider is the Postgres concrete tenancy.Provider. It installs RLS policies during Migrate and binds per-request tenancy state via pgxpool acquire/release hooks (no transactions required).

func New

func New() *Provider

New returns a fresh Postgres tenancy provider.

func (*Provider) Capabilities

func (*Provider) Capabilities() tenancy.Capabilities

Capabilities implements tenancy.Provider.

func (*Provider) Install

func (p *Provider) Install(_ context.Context, db *gorm.DB, models []tenancy.ModelInfo) error

Install implements tenancy.Provider. Idempotent:

  • CREATE OR REPLACE for the SQL function
  • DROP POLICY IF EXISTS / CREATE POLICY pair per table
  • ALTER TABLE … ENABLE / FORCE ROW LEVEL SECURITY (Postgres no-ops if already enabled).

func (*Provider) Name

func (*Provider) Name() string

Name implements tenancy.Provider.

func (*Provider) WireAdapter

func (p *Provider) WireAdapter(adapter dialect.DialectAdapter) error

WireAdapter implements tenancy.Provider. Stashes the adapter (for identifier quoting in Install), then registers a BeforeAcquire hook that pushes Claims-derived session vars onto the connection and an AfterRelease hook that resets them so connections are returned to the pool clean.

func (*Provider) WireGorm

func (*Provider) WireGorm(_ *gorm.DB) error

WireGorm implements tenancy.Provider. Postgres-RLS is enforced at the connection-acquire level, so no per-query GORM plugin is needed.

Jump to

Keyboard shortcuts

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