newscripts

package
v0.0.19 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 8, 2025 License: MIT Imports: 27 Imported by: 0

Documentation

Overview

Package newscripts: Intelligent migration script generation and management system Provides automated script creation with version control and naming conventions Features smart version progression and content generation based on database schema changes Integrates with GORM model analysis to generate appropriate migration scripts

newscripts: 智能迁移脚本生成和管理系统 提供自动化脚本创建,具有版本控制和命名约定 具有基于数据库结构变化的智能版本进展和内容生成 与 GORM 模型分析集成,生成适当的迁移脚本

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NextScriptCmd added in v0.0.13

func NextScriptCmd(config *Config) *cobra.Command

NextScriptCmd creates the main command for migration script management with subcommands Provides root command that displays current migration status and script information Includes create and update subcommands for comprehensive script management

NextScriptCmd 创建带有子命令的迁移脚本管理主命令 提供显示当前迁移状态和脚本信息的根命令 包含用于全面脚本管理的创建和更新子命令

Types

type Config added in v0.0.13

type Config struct {
	Migration *migrate.Migrate // Migration instance for version control // 用于版本控制的迁移实例
	Options   *Options         // Script generation options // 脚本生成选项
	DB        *gorm.DB         // Database connection for schema analysis // 用于结构分析的数据库连接
	Objects   []interface{}    // GORM model objects for migration analysis // 用于迁移分析的 GORM 模型对象
}

Config contains all necessary components for migration script generation via CLI Combines migration instance, options, database connection, and model objects Used to configure Cobra commands for script management operations

Config 包含通过 CLI 进行迁移脚本生成所需的所有组件 结合迁移实例、选项、数据库连接和模型对象 用于配置 Cobra 命令进行脚本管理操作

type NextScriptInfo added in v0.0.15

type NextScriptInfo struct {
	Action      ScriptAction // Type of script action to perform // 要执行的脚本操作类型
	ForwardName string       // Filename for forward migration script // 正向迁移脚本的文件名
	ReverseName string       // Filename for reverse migration script // 反向迁移脚本的文件名
}

NextScriptInfo contains information about the next migration script to be generated Includes action type and both forward and reverse script filenames Used to coordinate script creation and updates

NextScriptInfo 包含将要生成的下一个迁移脚本的信息 包含操作类型和正向、反向脚本文件名 用于协调脚本创建和更新

func GetNextScriptInfo added in v0.0.15

func GetNextScriptInfo(migration *migrate.Migrate, options *Options, naming *ScriptNaming) *NextScriptInfo

GetNextScriptInfo analyzes current migration state and determines next script information Examines existing migration files and database version to calculate appropriate next action Returns script naming details and action type for migration script creation

GetNextScriptInfo 分析当前迁移状态并确定下一个脚本信息 检查现有迁移文件和数据库版本来计算适当的下一步操作 返回用于迁移脚本创建的脚本命名详情和操作类型

func (*NextScriptInfo) GetScriptNames added in v0.0.17

func (scriptInfo *NextScriptInfo) GetScriptNames() *NextScriptNames

func (*NextScriptInfo) ScriptExists added in v0.0.15

func (scriptInfo *NextScriptInfo) ScriptExists(options *Options) bool

ScriptExists checks whether migration script files already exist in the target DIR Verifies existence of both forward and reverse script files Returns true if any of the script files are found

ScriptExists 检查迁移脚本文件是否已存在于目标 DIR 中 验证正向和反向脚本文件的存在性 如果找到任何脚本文件则返回 true

func (*NextScriptInfo) WriteScripts added in v0.0.15

func (scriptInfo *NextScriptInfo) WriteScripts(migrationOps checkmigration.MigrationOps, options *Options)

WriteScripts generates and writes both forward and reverse migration scripts to file system Creates script content from migration operations and handles file writing Supports both create and update scenarios based on script action

WriteScripts 生成并将正向和反向迁移脚本写入文件系统 从迁移操作创建脚本内容并处理文件写入 基于脚本操作支持创建和更新场景

type NextScriptNames added in v0.0.17

type NextScriptNames struct {
	ForwardName string
	ReverseName string
}

type Options

type Options struct {
	ScriptsInRoot string // Path to migration scripts DIR // 迁移脚本 DIR 路径
	DryRun        bool   // Enable dry-run mode without file writes // 启用试运行模式,不写入文件
	SurveyWritten bool   // Enable interactive confirmation prompts // 启用交互式确认提示
	DefaultSuffix string // Default file extension for scripts // 脚本的默认文件扩展名
}

Options contains configuration parameters for migration script generation and execution Controls script location, execution modes, and user interaction behavior Provides flexible configuration for different deployment and development scenarios

Options 包含迁移脚本生成和执行的配置参数 控制脚本位置、执行模式和用户交互行为 为不同的部署和开发场景提供灵活配置

func NewOptions

func NewOptions(scriptsInRoot string) *Options

NewOptions creates default configuration for script generation with specified root DIR Sets up reasonable defaults for safe script generation and execution Returns configured options ready for customization

NewOptions 为指定的根 DIR 创建脚本生成的默认配置 设置合理的默认值用于安全的脚本生成和执行 返回已配置的选项,可进一步自定义

type ScriptAction

type ScriptAction string

ScriptAction represents the type of action to perform on migration scripts Determines whether to create new scripts or update existing ones

ScriptAction 表示对迁移脚本执行的操作类型 决定是创建新脚本还是更新现有脚本

const (
	CreateScript ScriptAction = "create-script" // Create new migration scripts // 创建新的迁移脚本
	UpdateScript ScriptAction = "update-script" // Update existing scripts // 更新现有脚本
)

type ScriptNaming added in v0.0.13

type ScriptNaming struct {
	VersionType VersionPattern // Version number generation strategy // 版本号生成策略
	Description string         // Descriptive name for migration scripts // 迁移脚本的描述性名称
}

ScriptNaming contains configuration for migration script naming conventions Combines version generation strategy with descriptive naming Used to create consistent and meaningful script file names

ScriptNaming 包含迁移脚本命名约定的配置 将版本生成策略与描述性命名相结合 用于创建一致且有意义的脚本文件名

func NewScriptNaming added in v0.0.13

func NewScriptNaming() *ScriptNaming

NewScriptNaming creates default script naming configuration with incremental versioning Sets up standard naming patterns suitable for most migration scenarios Returns naming configuration ready for immediate use or further customization

NewScriptNaming 创建具有增量版本控制的默认脚本命名配置 设置适用于大多数迁移场景的标准命名模式 返回可立即使用或进一步自定义的命名配置

func (*ScriptNaming) NewScriptPrefix added in v0.0.13

func (T *ScriptNaming) NewScriptPrefix(version uint) string

type VersionPattern added in v0.0.13

type VersionPattern string

VersionPattern defines the strategy for generating migration script version numbers Supports different versioning approaches for various project requirements Each pattern provides unique benefits for different development workflows

VersionPattern 定义生成迁移脚本版本号的策略 为各种项目需求支持不同的版本控制方法 每种模式为不同的开发工作流提供独特优势

const (
	VersionNext VersionPattern = "NEXT" // Auto-incrementing numbers, e.g., 00001, 00002 // 自动递增编号,例如 00001, 00002
	VersionUnix VersionPattern = "UNIX" // Unix timestamp versions, e.g., 1678693920 // Unix 时间戳版本,例如 1678693920
	VersionTime VersionPattern = "TIME" // Formatted datetime versions, e.g., 20250621103045 // 格式化日时版本,例如 20250621103045
)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL