Documentation
¶
Index ¶
- func ValidateMigrationSignature(signature string, format SignatureFormat) error
- func ValidateTableName(name string) error
- type MigrationStatus
- type MigrationTracker
- type SchemerImplementation
- func (s *SchemerImplementation) AddMigration(migration contractsschema.MigrationInterface) error
- func (s *SchemerImplementation) AddMigrations(migrations []contractsschema.MigrationInterface) error
- func (s *SchemerImplementation) Down(ctx context.Context) error
- func (s *SchemerImplementation) Fresh(ctx context.Context) error
- func (s *SchemerImplementation) Reset(ctx context.Context) error
- func (s *SchemerImplementation) RollbackSteps(ctx context.Context, steps int) error
- func (s *SchemerImplementation) RollbackToBatch(ctx context.Context, batch int) error
- func (s *SchemerImplementation) SetSignatureValidation(enabled bool, format SignatureFormat)
- func (s *SchemerImplementation) SetTableName(name string) error
- func (s *SchemerImplementation) SetTransactionIsolationLevel(level string)
- func (s *SchemerImplementation) SetTransactionsEnabled(enabled bool)
- func (s *SchemerImplementation) Status() ([]MigrationStatus, error)
- func (s *SchemerImplementation) Up(ctx context.Context) error
- type SchemerInterface
- type SignatureFormat
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ValidateMigrationSignature ¶
func ValidateMigrationSignature(signature string, format SignatureFormat) error
ValidateMigrationSignature validates that a migration signature follows the specified format.
Supported formats:
- YYYY_MM_DD_HHMM_description (for datetime format)
- YYYY_MM_DD_NNN_description (for date format)
- unix_timestamp_description (for unix format)
- custom (no prefix format restriction, only length and non-empty)
Business Logic:
- Enforces maximum length of 255 characters
- Rejects empty signatures
- For "custom" format: only validates length and non-empty
- For other formats: requires at least 5 underscore-separated parts (or 2 for unix)
- Validates date part (YYYY_MM_DD) is a valid calendar date
- Validates time part (HHMM) or sequence part (NNN) based on format
- Validates description exists and is within length limits
func ValidateTableName ¶
ValidateTableName ensures the table name contains only safe characters. Exported to allow external validation of table names before creating a schemer instance.
Types ¶
type MigrationStatus ¶
type MigrationStatus struct {
ID string `json:"id"`
Description string `json:"description"`
Batch int `json:"batch"`
StartedAt time.Time `json:"started_at"`
CompletedAt time.Time `json:"completed_at"`
State string `json:"state"` // "pending", "completed", "failed"
}
MigrationStatus represents the status of a migration returned to users This is a DTO/response type derived from MigrationTracker data
type MigrationTracker ¶
type MigrationTracker struct {
ID string // The migration signature (e.g., "2024_06_15_120000_create_users_table")
Batch int // Timestamp ID (YYYYMMDDHHMMSS). Groups the run
Description string // The migration description from Description() method
StartedAt time.Time // When the migration started
CompletedAt time.Time // When the migration finished
}
MigrationTracker represents a migration record stored in the migration_tracker table This is the database model/entity used for persistence
type SchemerImplementation ¶
type SchemerImplementation struct {
// contains filtered or unexported fields
}
SchemerImplementation handles execution and tracking of interface-based migrations
func (*SchemerImplementation) AddMigration ¶
func (s *SchemerImplementation) AddMigration(migration contractsschema.MigrationInterface) error
AddMigration adds a new migration to the list
func (*SchemerImplementation) AddMigrations ¶
func (s *SchemerImplementation) AddMigrations(migrations []contractsschema.MigrationInterface) error
AddMigrations adds multiple migrations to the runner
func (*SchemerImplementation) Down ¶
func (s *SchemerImplementation) Down(ctx context.Context) error
Down rolls back the last migration
func (*SchemerImplementation) Fresh ¶
func (s *SchemerImplementation) Fresh(ctx context.Context) error
Fresh drops all tables and re-runs migrations
func (*SchemerImplementation) Reset ¶
func (s *SchemerImplementation) Reset(ctx context.Context) error
Reset rolls back and re-runs all migrations
func (*SchemerImplementation) RollbackSteps ¶
func (s *SchemerImplementation) RollbackSteps(ctx context.Context, steps int) error
RollbackSteps rolls back the specified number of migrations
func (*SchemerImplementation) RollbackToBatch ¶
func (s *SchemerImplementation) RollbackToBatch(ctx context.Context, batch int) error
RollbackToBatch rolls back all migrations to the specified batch
func (*SchemerImplementation) SetSignatureValidation ¶
func (s *SchemerImplementation) SetSignatureValidation(enabled bool, format SignatureFormat)
SetSignatureValidation enables or disables signature format validation. When enabled, each migration signature is validated against the specified format before execution. Default is disabled.
func (*SchemerImplementation) SetTableName ¶
func (s *SchemerImplementation) SetTableName(name string) error
SetTableName sets the name of the migration tracking table. The name is validated to prevent SQL injection.
func (*SchemerImplementation) SetTransactionIsolationLevel ¶
func (s *SchemerImplementation) SetTransactionIsolationLevel(level string)
SetTransactionIsolationLevel sets the transaction isolation level for migration operations
func (*SchemerImplementation) SetTransactionsEnabled ¶
func (s *SchemerImplementation) SetTransactionsEnabled(enabled bool)
SetTransactionsEnabled enables or disables transaction wrapping for migration operations
func (*SchemerImplementation) Status ¶
func (s *SchemerImplementation) Status() ([]MigrationStatus, error)
Status returns migration status
type SchemerInterface ¶
type SchemerInterface interface {
AddMigration(migration contractsschema.MigrationInterface) error
AddMigrations(migrations []contractsschema.MigrationInterface) error
Up(ctx context.Context) error
Down(ctx context.Context) error
RollbackSteps(ctx context.Context, steps int) error
RollbackToBatch(ctx context.Context, batch int) error
Status() ([]MigrationStatus, error)
Fresh(ctx context.Context) error
Reset(ctx context.Context) error
SetTransactionsEnabled(enabled bool)
SetTransactionIsolationLevel(level string)
SetTableName(name string) error
SetSignatureValidation(enabled bool, format SignatureFormat)
}
SchemerInterface defines the contract for migration management
func NewSchemer ¶
func NewSchemer(db *database.Database) SchemerInterface
NewSchemer creates a new SchemerImplementation instance Takes neat db instance as dependency, extracts schema and orm internally
type SignatureFormat ¶
type SignatureFormat string
SignatureFormat defines the format for migration signatures
const ( // SignatureFormatDateTime uses timestamp-based format (default) // Example: 2026_06_14_1200_create_users_table SignatureFormatDateTime SignatureFormat = "datetime" // SignatureFormatDate uses sequence-based format // Example: 2026_06_14_001_create_users_table SignatureFormatDate SignatureFormat = "date" // SignatureFormatUnix uses unix timestamp format (legacy) // Example: 1717080000_create_users_table SignatureFormatUnix SignatureFormat = "unix" // SignatureFormatCustom uses no prefix format restriction SignatureFormatCustom SignatureFormat = "custom" )