{"modulePath":"github.com/GoCodeAlone/workflow-plugin-data-engineering","version":"v0.3.3","isLatest":true,"isStandardLibrary":false,"goos":"all","goarch":"all","docs":"# package tenancy\n\nPackage tenancy implements multi-tenant data isolation modules and steps.\n\n## Constants\n\n```go\nconst (\n\tTierRowLevel        = \"row_level\"\n\tTierSchemaPerTenant = \"schema_per_tenant\"\n\tTierDBPerTenant     = \"db_per_tenant\"\n)\n```\nTier constants for the three supported isolation levels.\n\n## Functions\n\n```go\nfunc NewDemoteStep(name string, _ map[string]any) (sdk.StepInstance, error)\n```\nNewDemoteStep creates a step.tenant\\_demote instance.\n\n```go\nfunc NewDeprovisionStep(name string, config map[string]any) (sdk.StepInstance, error)\n```\nNewDeprovisionStep creates a step.tenant\\_deprovision instance.\n\n```go\nfunc NewEvaluatePromotionStep(name string, _ map[string]any) (sdk.StepInstance, error)\n```\nNewEvaluatePromotionStep creates a step.tenant\\_evaluate\\_promotion instance.\n\n```go\nfunc NewMigrateStep(name string, config map[string]any) (sdk.StepInstance, error)\n```\nNewMigrateStep creates a step.tenant\\_migrate instance.\n\n```go\nfunc NewPromoteStep(name string, _ map[string]any) (sdk.StepInstance, error)\n```\nNewPromoteStep creates a step.tenant\\_promote instance.\n\n```go\nfunc NewProvisionStep(name string, config map[string]any) (sdk.StepInstance, error)\n```\nNewProvisionStep creates a step.tenant\\_provision instance. Config must include \"strategy\" and any strategy-specific fields.\n\n```go\nfunc NewTenancyModule(name string, config map[string]any) (sdk.ModuleInstance, error)\n```\nNewTenancyModule creates a new data.tenancy module instance.\n\n```go\nfunc TenancyModuleSchema() sdk.ModuleSchemaData\n```\nTenancyModuleSchema returns the UI schema definition for the data.tenancy module.\n\n## Types\n\n```go\ntype DBPerTenant struct {\n\t// contains filtered or unexported fields\n}\n```\nDBPerTenant isolates each tenant in its own database. A connection template uses \"{{tenant}}\" as a placeholder for the tenant ID.\n\n```go\nfunc NewDBPerTenant(exec SQLExecutor) *DBPerTenant\n```\nNewDBPerTenant creates a DBPerTenant strategy.\n\n```go\nfunc (d *DBPerTenant) DeprovisionTenant(ctx context.Context, tenantID string, mode string) error\n```\nDeprovisionTenant archives or drops the tenant's database. mode \"archive\" renames the database; mode \"delete\" drops it.\n\n```go\nfunc (d *DBPerTenant) ProvisionTenant(ctx context.Context, tenantID string) error\n```\nProvisionTenant executes CREATE DATABASE for the tenant.\n\n```go\nfunc (d *DBPerTenant) ResolveConnection(tenantID, baseConnection string) string\n```\nResolveConnection replaces \"{{tenant}}\" in the connection template with the tenant ID.\n\n```go\nfunc (d *DBPerTenant) ResolveTable(tenantID, table string) string\n```\nResolveTable returns the table unchanged — tenant is isolated at the DB level.\n\n```go\nfunc (d *DBPerTenant) TenantFilter(tenantID string) (string, string)\n```\nTenantFilter returns empty strings — isolation is via database, not row filtering.\n\n```go\ntype PromotionDB interface {\n\tExecContext(ctx context.Context, query string, args ...any) (sql.Result, error)\n\tQueryRowContext(ctx context.Context, query string, args ...any) *sql.Row\n}\n```\nPromotionDB is the minimal database interface required by promotion steps. \\*sql.DB satisfies this interface, enabling sqlmock injection in tests.\n\n```go\ntype PromotionEvaluator struct {\n\tThresholds map[string]float64\n}\n```\nPromotionEvaluator compares tenant metrics against configured thresholds and recommends the next isolation tier when any threshold is exceeded.\n\n```go\nfunc (e *PromotionEvaluator) Evaluate(tenantID, currentTier string, metrics map[string]float64) PromotionResult\n```\nEvaluate returns a promotion recommendation for the tenant. It iterates over metrics and returns as soon as a threshold is exceeded.\n\n```go\ntype PromotionResult struct {\n\tTenantID        string             `json:\"tenant_id\"`\n\tCurrentTier     string             `json:\"current_tier\"`\n\tRecommendedTier string             `json:\"recommended_tier\"`\n\tShouldPromote   bool               `json:\"should_promote\"`\n\tReason          string             `json:\"reason\"`\n\tMetrics         map[string]float64 `json:\"metrics\"`\n}\n```\nPromotionResult holds the outcome of a promotion evaluation.\n\n```go\ntype RowLevel struct {\n\t// contains filtered or unexported fields\n}\n```\nRowLevel isolates tenants via a tenant ID column in shared tables. All tables are shared; queries must include a WHERE clause filtering by tenant.\n\n```go\nfunc NewRowLevel(tenantColumn string, tables []string, exec SQLExecutor) *RowLevel\n```\nNewRowLevel creates a RowLevel strategy. tenantColumn is the column used for tenant filtering. tables is the list of tenant-scoped tables (used only in DeprovisionTenant delete mode).\n\n```go\nfunc (r *RowLevel) DeprovisionTenant(ctx context.Context, tenantID string, mode string) error\n```\nDeprovisionTenant deletes all rows belonging to the tenant (mode \"delete\"). mode \"archive\" is a no-op for row-level isolation — caller must handle archiving.\n\n```go\nfunc (r *RowLevel) ProvisionTenant(_ context.Context, _ string) error\n```\nProvisionTenant is a no-op for row-level isolation (shared tables need no setup).\n\n```go\nfunc (r *RowLevel) ResolveConnection(tenantID, baseConnection string) string\n```\nResolveConnection returns the base connection unchanged — shared database.\n\n```go\nfunc (r *RowLevel) ResolveTable(tenantID, table string) string\n```\nResolveTable returns the table unchanged — shared tables, no schema prefix.\n\n```go\nfunc (r *RowLevel) TenantFilter(tenantID string) (string, string)\n```\nTenantFilter returns the tenant column and tenant ID for WHERE clause injection.\n\n```go\ntype SQLExecutor func(ctx context.Context, sql string, args ...any) error\n```\nSQLExecutor runs a SQL statement against an admin database connection. args holds query parameters for parameterized statements (e.g. $1, $2).\n\n```go\ntype SchemaPerTenant struct {\n\t// contains filtered or unexported fields\n}\n```\nSchemaPerTenant isolates each tenant in its own database schema. Tables are prefixed with \"{prefix}{tenantID}.\" and the shared admin connection is used for all tenants.\n\n```go\nfunc NewSchemaPerTenant(prefix string, exec SQLExecutor) *SchemaPerTenant\n```\nNewSchemaPerTenant creates a SchemaPerTenant strategy. prefix is prepended to the tenant ID to form the schema name (e.g. \"t\\_\" → \"t\\_acme\").\n\n```go\nfunc (s *SchemaPerTenant) DeprovisionTenant(ctx context.Context, tenantID string, mode string) error\n```\nDeprovisionTenant archives or drops the tenant's schema. mode \"archive\" renames the schema; mode \"delete\" drops it with CASCADE.\n\n```go\nfunc (s *SchemaPerTenant) ProvisionTenant(ctx context.Context, tenantID string) error\n```\nProvisionTenant executes CREATE SCHEMA IF NOT EXISTS for the tenant.\n\n```go\nfunc (s *SchemaPerTenant) ResolveConnection(tenantID, baseConnection string) string\n```\nResolveConnection returns the base connection unchanged (shared DB, schema-based isolation).\n\n```go\nfunc (s *SchemaPerTenant) ResolveTable(tenantID, table string) string\n```\nResolveTable returns \"{prefix}{tenantID}.{table}\".\n\n```go\nfunc (s *SchemaPerTenant) TenantFilter(tenantID string) (string, string)\n```\nTenantFilter returns empty strings — isolation is via schema, not row filtering.\n\n```go\ntype TenancyConfig struct {\n\tStrategy           string   `json:\"strategy\"            yaml:\"strategy\"`\n\tTenantKeyPath      string   `json:\"tenant_key\"          yaml:\"tenant_key\"`\n\tSchemaPrefix       string   `json:\"schema_prefix\"       yaml:\"schema_prefix\"`\n\tConnectionTemplate string   `json:\"connection_template\" yaml:\"connection_template\"`\n\tTenantColumn       string   `json:\"tenant_column\"       yaml:\"tenant_column\"`\n\tTables             []string `json:\"tables\"              yaml:\"tables\"`\n}\n```\nTenancyConfig holds configuration for the data.tenancy module.\n\n```go\ntype TenancyModule struct {\n\t// contains filtered or unexported fields\n}\n```\nTenancyModule is a data.tenancy module that manages tenant isolation via a pluggable strategy.\n\n```go\nfunc (m *TenancyModule) Init() error\n```\nInit validates the tenancy module configuration.\n\n```go\nfunc (m *TenancyModule) Start(_ context.Context) error\n```\nStart activates the module (no-op: strategies use injected executors).\n\n```go\nfunc (m *TenancyModule) Stop(_ context.Context) error\n```\nStop deactivates the module.\n\n```go\nfunc (m *TenancyModule) Strategy() TenancyStrategy\n```\nStrategy returns the active TenancyStrategy.\n\n```go\nfunc (m *TenancyModule) TenantKey() string\n```\nTenantKey returns the dot-path used to resolve the tenant ID from pipeline context.\n\n```go\ntype TenancyStrategy interface {\n\t// ResolveTable returns the fully-qualified table reference for a given tenant.\n\tResolveTable(tenantID, table string) string\n\n\t// ResolveConnection returns the connection string for a given tenant,\n\t// potentially replacing a template placeholder with the tenant ID.\n\tResolveConnection(tenantID, baseConnection string) string\n\n\t// TenantFilter returns the column and value to filter by for row-level isolation.\n\t// Returns empty strings when the strategy uses schema or DB isolation.\n\tTenantFilter(tenantID string) (column, value string)\n\n\t// ProvisionTenant creates the tenant's namespace (schema, database, etc.).\n\tProvisionTenant(ctx context.Context, tenantID string) error\n\n\t// DeprovisionTenant removes or archives the tenant's namespace.\n\t// mode is \"archive\" (rename/retain data) or \"delete\" (destroy data).\n\tDeprovisionTenant(ctx context.Context, tenantID string, mode string) error\n}\n```\nTenancyStrategy defines how multi-tenant isolation is implemented. Each strategy controls table resolution, connection routing, tenant filtering, and tenant lifecycle SQL for a specific isolation model.\n\n","path":"github.com/GoCodeAlone/workflow-plugin-data-engineering/internal/tenancy","name":"tenancy","synopsis":"Package tenancy implements multi-tenant data isolation modules and steps.","isRedistributable":true}
