supa-seed
Version:
A constraint-aware, framework-agnostic database seeding framework with deep PostgreSQL business logic discovery and MakerKit integration support
178 lines • 5.21 kB
TypeScript
/**
* Multi-Tenant Architecture Types
* Types and interfaces for tenant-aware seeding
*/
export interface TenantInfo {
id: string;
type: 'personal' | 'team' | 'organization';
isPersonalAccount: boolean;
slug: string | null;
name: string;
email?: string;
ownerId?: string;
createdAt: string;
metadata: TenantMetadata;
}
export interface TenantMetadata {
memberCount: number;
plan: 'free' | 'pro' | 'enterprise';
features: string[];
settings: Record<string, any>;
limits: TenantLimits;
}
export interface TenantLimits {
maxUsers: number;
maxProjects: number;
maxStorage: number;
maxApiCalls: number;
}
export interface TenantScopeInfo {
tableName: string;
schema: string;
tenantColumn: string;
isTenantScoped: boolean;
confidence: number;
scopeType: 'strict' | 'optional' | 'shared';
metadata: TenantScopeMetadata;
}
export interface TenantScopeMetadata {
hasRLS: boolean;
rlsPolicies: string[];
foreignKeys: TenantForeignKey[];
constraints: string[];
triggers: string[];
isMultiTenant: boolean;
}
export interface TenantForeignKey {
constraintName: string;
fromColumn: string;
toTable: string;
toColumn: string;
onDelete: string;
onUpdate: string;
isTenantReference: boolean;
}
export interface TenantBoundaryValidation {
isValid: boolean;
violations: TenantViolation[];
warnings: string[];
recommendations: string[];
isolationScore: number;
}
export interface TenantViolation {
type: 'cross_tenant_reference' | 'missing_tenant_id' | 'invalid_tenant_scope' | 'rls_bypass';
severity: 'error' | 'warning' | 'info';
tableName: string;
recordId?: string;
description: string;
suggestedFix: string;
affectedFields: string[];
}
export interface TenantDataGenerationOptions {
generatePersonalAccounts: boolean;
generateTeamAccounts: boolean;
personalAccountRatio: number;
dataDistributionStrategy: 'even' | 'realistic' | 'skewed';
crossTenantDataAllowed: boolean;
sharedResourcesEnabled: boolean;
accountTypes: AccountTypeConfig[];
minUsersPerTenant: number;
maxUsersPerTenant: number;
minProjectsPerTenant: number;
maxProjectsPerTenant: number;
allowCrossTenantRelationships: boolean;
sharedTables: string[];
respectTenantPlans: boolean;
enforceTenantLimits: boolean;
}
export interface AccountTypeConfig {
type: 'personal' | 'team' | 'organization';
weight: number;
settings: {
minMembers?: number;
maxMembers?: number;
defaultPlan: 'free' | 'pro' | 'enterprise';
features: string[];
};
}
export interface TenantSeedingResult {
success: boolean;
tenantsCreated: number;
personalAccounts: number;
teamAccounts: number;
totalRecords: number;
tenantScopedRecords: number;
crossTenantReferences: number;
validationResult: TenantBoundaryValidation;
executionTime: number;
errors: string[];
warnings: string[];
tenantDetails: TenantSeedingDetails[];
}
export interface TenantSeedingDetails {
tenantId: string;
tenantType: 'personal' | 'team' | 'organization';
recordsCreated: number;
tablesSeeded: string[];
relationships: number;
isolationScore: number;
errors: string[];
warnings: string[];
}
export interface TenantDiscoveryResult {
success: boolean;
tenantScopedTables: TenantScopeInfo[];
sharedTables: string[];
tenantColumn: string;
confidence: number;
recommendations: string[];
errors: string[];
warnings: string[];
metadata: {
totalTables: number;
tenantScopedCount: number;
sharedCount: number;
averageConfidence: number;
detectionMethod: 'column_analysis' | 'rls_analysis' | 'constraint_analysis' | 'hybrid';
};
}
export interface TenantIsolationReport {
tenantId: string;
tenantType: 'personal' | 'team' | 'organization';
isolationScore: number;
violations: TenantViolation[];
recommendations: string[];
dataBreakdown: {
totalRecords: number;
ownedRecords: number;
accessibleRecords: number;
crossTenantRecords: number;
};
tableBreakdown: Record<string, {
totalRecords: number;
ownedRecords: number;
violations: number;
}>;
}
export interface MakerKitTenantPattern {
accountsTable: string;
profilesTable: string;
accountIdColumn: string;
personalAccountConstraint: string;
slugConstraint: string;
setupFunction: string;
}
export interface TenantSeederConfig {
enableMultiTenant: boolean;
tenantColumn: string;
tenantScopeDetection: 'auto' | 'manual';
manualTenantScopes: Record<string, TenantScopeInfo>;
validationEnabled: boolean;
strictIsolation: boolean;
allowSharedResources: boolean;
dataGenerationOptions: TenantDataGenerationOptions;
}
export declare const COMMON_TENANT_COLUMNS: string[];
export declare const MAKERKIT_TENANT_PATTERN: MakerKitTenantPattern;
export declare const DEFAULT_TENANT_GENERATION_OPTIONS: TenantDataGenerationOptions;
//# sourceMappingURL=tenant-types.d.ts.map