supa-seed
Version:
A constraint-aware, framework-agnostic database seeding framework with deep PostgreSQL business logic discovery and MakerKit integration support
185 lines • 5.88 kB
TypeScript
import type { createClient } from '@supabase/supabase-js';
type SupabaseClient = ReturnType<typeof createClient>;
export interface SchemaInfo {
hasAccounts: boolean;
hasUsers: boolean;
hasProfiles: boolean;
hasSetups: boolean;
hasCategories: boolean;
hasTeams: boolean;
hasOrganizations: boolean;
accountsTableStructure: 'simple' | 'makerkit' | 'custom';
primaryUserTable: 'accounts' | 'profiles' | 'users';
makerkitVersion: 'v1' | 'v2' | 'v3' | 'custom' | 'none';
customTables: string[];
detectedRelationships: TableRelationship[];
assetCompatibility: AssetCompatibilityInfo;
frameworkType: 'makerkit' | 'simple' | 'wildernest' | 'custom';
}
export interface TableRelationship {
fromTable: string;
fromColumn: string;
toTable: string;
toColumn: string;
relationshipType: 'one_to_one' | 'one_to_many' | 'many_to_many';
cascadeDelete: boolean;
}
export interface AssetCompatibilityInfo {
supportsImages: boolean;
supportsMarkdown: boolean;
supportsJson: boolean;
contentTables: string[];
userContentRelationships: TableRelationship[];
mediaStoragePattern: 'supabase_storage' | 'url_only' | 'base64' | 'custom';
}
export declare class SchemaAdapter {
private client;
private supabaseKey?;
private schemaInfo;
private configOverride?;
private supabaseUrl;
constructor(client: SupabaseClient, configOverride?: any, supabaseUrl?: string, supabaseKey?: string | undefined);
/**
* Check if this is a local Supabase environment
*/
private isLocalSupabaseEnvironment;
/**
* Detect the database schema and return comprehensive compatibility info
*/
detectSchema(): Promise<SchemaInfo>;
/**
* Get the appropriate user creation strategy based on detected schema
*/
getUserCreationStrategy(): 'simple-accounts' | 'makerkit-profiles' | 'custom-profiles';
/**
* Create a user using the appropriate strategy for the detected schema
*/
createUserForSchema(userData: {
id?: string;
email: string;
name: string;
username?: string;
bio?: string;
picture_url?: string;
}): Promise<{
id: string;
success: boolean;
error?: string;
}>;
/**
* Get the correct column name for a field, checking config first then what actually exists
*/
private getColumnMapping;
/**
* Get column mapping from configuration
*/
private getConfigColumnMapping;
tableExists(tableName: string): Promise<boolean>;
private checkAuthUsers;
private detectAccountsStructure;
private determinePrimaryUserTable;
private createSimpleAccountUser;
private createMakerkitUser;
private createProfilesUser;
/**
* Check if we can create additional personal accounts based on MakerKit constraints
*/
private checkPersonalAccountConstraints;
/**
* Detect if the unique_personal_account constraint exists
*/
private detectUniquePersonalAccountConstraint;
/**
* Get the appropriate table name for setups/content based on schema
*/
getSetupsTableName(): string;
/**
* Get the appropriate foreign key for user relationships
*/
getUserForeignKey(): string;
/**
* Detect if this is a MakerKit schema pattern
*/
private hasMakerKitPattern;
/**
* Detect MakerKit version based on table patterns and schema structure
*/
private detectMakerKitVersion;
/**
* Check if specific fields exist in the accounts table
*/
private checkAccountFields;
/**
* Detect custom tables beyond standard MakerKit schema
*/
private detectCustomTables;
/**
* Detect table relationships for better association intelligence
*/
private detectTableRelationships;
/**
* Check if a column exists in a table
*/
columnExists(tableName: string, columnName: string): Promise<boolean>;
/**
* Get actual column names from database schema
*/
private getTableColumns;
/**
* Validate that required columns exist for a table and provide helpful error messages
*/
validateTableSchema(tableName: string, requiredFields: Record<string, string[]>): Promise<{
valid: boolean;
missingFields: string[];
availableColumns: string[];
suggestions: string[];
}>;
/**
* Detect framework type based on comprehensive analysis
*/
private detectFrameworkTypeEnhanced;
/**
* Analyze asset compatibility for hybrid seeding
*/
private analyzeAssetCompatibility;
/**
* Check if a table supports markdown content
*/
private checkMarkdownSupport;
/**
* Check if a table has content-related columns
*/
private checkContentColumns;
/**
* Get comprehensive schema information for hybrid seeding
*/
getHybridSeedingInfo(): {
compatibilityLevel: 'basic' | 'intermediate' | 'advanced';
recommendedAssetTypes: string[];
suggestedAssociations: string[];
frameworkSpecificTips: string[];
};
/**
* Detect enum types in a table column
*/
detectEnumValues(tableName: string, columnName: string): Promise<string[] | null>;
/**
* Check if a table uses enum-based categories vs FK-based categories
*/
detectCategoryStrategy(tableName: string): Promise<{
strategy: 'enum' | 'fk' | 'none';
categoryColumn?: string;
enumValues?: string[];
categoryTableName?: string;
}>;
/**
* Infer category table name from FK column name
*/
private inferCategoryTableName;
/**
* Determine the framework type based on detected schema
*/
private getFrameworkType;
}
export {};
//# sourceMappingURL=schema-adapter.d.ts.map