/** * Schema management type definitions */ import { ColumnType, IndexType, AlterationType, ConstraintType, ReferentialAction, SortOrder } from './enums'; import { IConnectionConfig } from './connection.interface'; /** * Table definition for creating tables */ export interface ITableDefinition { /** Table name */ name: string; /** Column definitions */ columns: IColumnDefinition[]; /** Index definitions */ indexes?: IIndexDefinition[]; /** Table constraints */ constraints?: IConstraintDefinition[]; /** Table comment/description */ comment?: string; } /** * Column definition */ export interface IColumnDefinition { /** Column name */ name: string; /** Column data type */ type: ColumnType | string; /** Maximum length (for STRING/VARCHAR) */ length?: number; /** Precision (for DECIMAL) */ precision?: number; /** Scale (for DECIMAL) */ scale?: number; /** Allow null values */ nullable?: boolean; /** Primary key */ primaryKey?: boolean; /** Auto increment (for INTEGER primary keys) */ autoIncrement?: boolean; /** Unique constraint */ unique?: boolean; /** Default value */ defaultValue?: any; /** Foreign key reference */ references?: IForeignKeyReference; /** Enum values (for ENUM type) */ enumValues?: string[]; /** Array element type (for ARRAY type) */ arrayType?: ColumnType | string; /** Column comment */ comment?: string; /** Check constraint expression */ check?: string; } /** * Foreign key reference */ export interface IForeignKeyReference { /** Referenced table */ table: string; /** Referenced column */ column: string; /** On delete action */ onDelete?: ReferentialAction | string; /** On update action */ onUpdate?: ReferentialAction | string; } /** * Index definition */ export interface IIndexDefinition { /** Index name */ name: string; /** Table name */ table: string; /** Columns in the index */ columns: IIndexColumn[]; /** Unique index */ unique?: boolean; /** Index type/method (BTREE, HASH, GIN, etc.) */ method?: IndexType | string; /** Partial index condition (PostgreSQL) */ where?: string; /** Include columns (PostgreSQL covering index) */ include?: string[]; /** Index comment */ comment?: string; } /** * Index column configuration */ export interface IIndexColumn { /** Column name */ name: string; /** Sort order */ order?: SortOrder | 'ASC' | 'DESC'; /** Nulls position */ nulls?: 'FIRST' | 'LAST'; /** Operator class (PostgreSQL) */ opclass?: string; } /** * Table constraint definition */ export interface IConstraintDefinition { /** Constraint name */ name: string; /** Constraint type */ type: ConstraintType; /** Columns involved */ columns: string[]; /** Foreign key reference (for FOREIGN_KEY) */ references?: IForeignKeyReference; /** Check expression (for CHECK) */ expression?: string; } /** * Options for creating a table */ export interface ICreateTableOptions { /** Only create if table doesn't exist */ ifNotExists?: boolean; /** Create as temporary table */ temporary?: boolean; /** Create as unlogged table (PostgreSQL) */ unlogged?: boolean; /** Inherit from parent table (PostgreSQL) */ inherits?: string; /** Tablespace */ tablespace?: string; } /** * Alter table operation */ export interface IAlterTableOperation { /** Type of alteration */ type: AlterationType | 'ADD' | 'MODIFY' | 'DROP' | 'RENAME'; /** Column definition (for ADD/MODIFY) */ column?: IColumnDefinition; /** Column name to drop (for DROP) */ columnName?: string; /** Old column name (for RENAME) */ oldName?: string; /** New column name (for RENAME) */ newName?: string; /** Constraint to add */ constraint?: IConstraintDefinition; /** Constraint name to drop */ constraintName?: string; } /** * Options for creating an index */ export interface ICreateIndexOptions extends IConnectionConfig { /** Table name */ table: string; /** Index definition */ index: IIndexDefinition; /** Only create if index doesn't exist */ ifNotExists?: boolean; /** Create index concurrently (PostgreSQL - no table lock) */ concurrent?: boolean; } /** * Options for dropping an index */ export interface IDropIndexOptions extends IConnectionConfig { /** Table name */ table: string; /** Index name to drop */ indexName: string; /** Only drop if index exists */ ifExists?: boolean; /** Drop concurrently (PostgreSQL) */ concurrent?: boolean; /** Cascade to dependent objects */ cascade?: boolean; } /** * Options for listing indexes */ export interface IListIndexesOptions extends IConnectionConfig { /** Table name */ table: string; /** Include system-generated indexes */ includeSystem?: boolean; } /** * Basic table information (lightweight) * Used by listTablesWithInfo() for efficient table listing with row counts */ export interface ITableInfo { /** Table name */ name: string; /** Schema/database name */ schema?: string; /** Estimated row count */ estimatedRowCount?: number; /** Table comment/description */ comment?: string; } /** * Table schema information (detailed) */ export interface ITableSchema { /** Table name */ name: string; /** Schema/database name */ schema?: string; /** Column information */ columns: IColumnInfo[]; /** Index information */ indexes: IIndexInfo[]; /** Constraint information */ constraints: IConstraintInfo[]; /** Primary key columns */ primaryKey?: string[]; /** Table comment */ comment?: string; /** Estimated row count */ estimatedRowCount?: number; } /** * Column information from schema introspection */ export interface IColumnInfo { /** Column name */ name: string; /** Data type */ type: string; /** Nullable */ nullable: boolean; /** Default value */ defaultValue?: any; /** Is primary key */ isPrimaryKey: boolean; /** Is unique */ isUnique: boolean; /** Is auto increment */ isAutoIncrement: boolean; /** Maximum length */ maxLength?: number; /** Numeric precision */ precision?: number; /** Numeric scale */ scale?: number; /** Column comment */ comment?: string; } /** * Index information from schema introspection */ export interface IIndexInfo { /** Index name */ name: string; /** Table name */ table: string; /** Indexed columns */ columns: string[]; /** Is unique index */ unique: boolean; /** Is primary key index */ primaryKey: boolean; /** Index type/method */ type?: string; /** Index size in bytes */ size?: number; /** Partial index condition */ where?: string; } /** * Constraint information from schema introspection */ export interface IConstraintInfo { /** Constraint name */ name: string; /** Constraint type */ type: string; /** Columns involved */ columns: string[]; /** Referenced table (for foreign keys) */ referencedTable?: string; /** Referenced columns (for foreign keys) */ referencedColumns?: string[]; /** Check expression (for check constraints) */ expression?: string; } /** * Index statistics */ export interface IIndexStatistics { /** Index name */ indexName: string; /** Table name */ tableName: string; /** Number of index scans */ scans: number; /** Tuples read via index */ tuplesRead: number; /** Tuples fetched via index */ tuplesFetched?: number; /** Index size in bytes */ sizeBytes: number; /** Formatted size string */ sizeFormatted: string; /** Last time index was used */ lastUsed?: Date; /** Whether index appears bloated */ bloated?: boolean; /** Bloat percentage */ bloatPercent?: number; } import { FieldType, ICreateCollectionMigration, IIndexFieldDefinition } from './migration.interface'; /** * Mongoose-style field type aliases */ export type SimpleFieldType = FieldType | 'String' | 'Number' | 'Integer' | 'BigInt' | 'Float' | 'Double' | 'Decimal' | 'Boolean' | 'Date' | 'ObjectId' | 'Array' | 'Object' | 'Mixed'; /** * Mongoose-style field definition for simplified API */ export interface ISimpleFieldDefinition { /** Field type */ type: SimpleFieldType; /** Field is required (default: false) */ required?: boolean; /** Field must be unique */ unique?: boolean; /** Default value */ default?: any; /** Is primary key */ primaryKey?: boolean; /** Auto increment/generate */ autoIncrement?: boolean; /** Minimum length for string types (validation) */ minLength?: number; /** Maximum length for string types (database column size) */ maxLength?: number; /** Precision for decimal types */ precision?: number; /** Scale for decimal types */ scale?: number; /** Enum values */ enum?: string[]; /** Reference to another collection (for relations) */ ref?: string; /** Create index on this field */ index?: boolean | { unique?: boolean; sparse?: boolean; name?: string; }; /** Field comment */ comment?: string; } /** * Mongoose-style schema definition * Supports both shorthand (fieldName: 'string') and full definition */ export interface ISimpleSchemaDefinition { [fieldName: string]: SimpleFieldType | ISimpleFieldDefinition; } /** * Options for simplified schema create */ export interface ISimpleCreateOptions { /** Auto-add created_at and updated_at timestamps */ timestamps?: boolean; /** Index definitions */ indexes?: Array<{ /** Fields to index */ fields: string[] | IIndexFieldDefinition[]; /** Unique index */ unique?: boolean; /** Index name (auto-generated if not provided) */ name?: string; /** Sparse index */ sparse?: boolean; }>; /** SQL-specific options */ sqlOptions?: ICreateCollectionMigration['sqlOptions']; /** MongoDB-specific options */ mongoOptions?: ICreateCollectionMigration['mongoOptions']; /** DynamoDB-specific options */ dynamoOptions?: ICreateCollectionMigration['dynamoOptions']; /** Cassandra-specific options */ cassandraOptions?: ICreateCollectionMigration['cassandraOptions']; } /** * Options for simplified schema drop */ export interface ISimpleDropOptions { /** Only drop if exists */ ifExists?: boolean; /** Cascade to dependent objects */ cascade?: boolean; } /** * Options for simplified index creation */ export interface ISimpleIndexOptions { /** Unique index */ unique?: boolean; /** Index name */ name?: string; /** Sparse index */ sparse?: boolean; /** Partial index condition (SQL) */ where?: string; /** TTL in seconds (MongoDB) */ expireAfterSeconds?: number; }