supa-seed
Version:
A constraint-aware, framework-agnostic database seeding framework with deep PostgreSQL business logic discovery and MakerKit integration support
142 lines • 3.97 kB
TypeScript
/**
* Relationship Analyzer
* Analyzes foreign key relationships and builds dependency graphs for seeding order
*/
import type { createClient } from '@supabase/supabase-js';
import { DependencyGraph, TableDependency, ForeignKeyRelationship, SeedingOrderResult } from '../../schema/dependency-graph';
type SupabaseClient = ReturnType<typeof createClient>;
export interface RelationshipAnalysisOptions {
schemas: string[];
includeTables: string[];
excludeTables: string[];
detectJunctionTables: boolean;
analyzeTenantScoping: boolean;
includeOptionalRelationships: boolean;
detectSelfReferences: boolean;
enableCaching: boolean;
cacheTimeout: number;
maxConcurrentQueries: number;
queryTimeout: number;
generateRecommendations: boolean;
includeMetadata: boolean;
verboseLogging: boolean;
}
export interface RelationshipAnalysisResult {
success: boolean;
dependencyGraph: DependencyGraph;
foreignKeyRelationships: ForeignKeyRelationship[];
tableDependencies: TableDependency[];
analysisMetadata: AnalysisMetadata;
seedingOrder: SeedingOrderResult;
recommendations: string[];
warnings: string[];
errors: string[];
executionTime: number;
}
export interface AnalysisMetadata {
tablesAnalyzed: number;
relationshipsFound: number;
junctionTablesDetected: string[];
tenantScopedTables: string[];
circularDependencies: number;
maxDependencyDepth: number;
analysisTimestamp: string;
confidence: number;
cacheHit: boolean;
}
export declare class RelationshipAnalyzer {
private client;
private options;
private analysisCache;
constructor(client: SupabaseClient, options?: Partial<RelationshipAnalysisOptions>);
/**
* Analyze relationships and build dependency graph
*/
analyzeRelationships(): Promise<RelationshipAnalysisResult>;
/**
* Get all tables from specified schemas
*/
private getTables;
/**
* Get foreign key relationships
*/
private getForeignKeyRelationships;
/**
* Fallback method to get foreign keys using basic information_schema queries
*/
private getForeignKeysBasic;
/**
* Transform raw foreign key data to our format
*/
private transformForeignKeys;
/**
* Get column information for metadata analysis
*/
private getColumnInformation;
/**
* Check if a column is part of primary key
*/
private isColumnPrimaryKey;
/**
* Build dependency graph from relationships
*/
private buildDependencyGraph;
/**
* Generate metadata for a table
*/
private generateTableMetadata;
/**
* Check if table is a junction table
*/
private isJunctionTable;
/**
* Check if table is tenant-scoped
*/
private isTenantScoped;
/**
* Check if table has timestamp columns
*/
private hasTimestampColumns;
/**
* Estimate table size category
*/
private estimateTableSize;
/**
* Estimate seeding complexity
*/
private estimateSeedingComplexity;
/**
* Convert foreign keys to table dependencies
*/
private convertToTableDependencies;
/**
* Generate analysis metadata
*/
private generateAnalysisMetadata;
/**
* Generate recommendations based on analysis
*/
private generateRecommendations;
/**
* Normalize referential action strings
*/
private normalizeReferentialAction;
/**
* Create empty dependency graph for error cases
*/
private createEmptyGraph;
/**
* Generate cache key for results
*/
private generateCacheKey;
/**
* Clear analysis cache
*/
clearCache(): void;
/**
* Get dependency graph for specific tables
*/
getDependencyGraphForTables(tableNames: string[]): Promise<DependencyGraph>;
}
export {};
//# sourceMappingURL=relationship-analyzer.d.ts.map