manager

package
v0.2.6 Latest Latest
Warning

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

Go to latest
Published: Dec 12, 2024 License: BSD-2-Clause Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	LogsTable = `dbvm_logs` // 日志表名称

	ConfFile  = `dbvm.yaml`
	PlanFile  = `dbvm.plan`
	DeployDir = `deploy`
	RevertDir = `revert`
)

默认配置

Variables

View Source
var (
	MagicIgnore  = []byte(`IGNORE`)   // 忽略指定的错误
	MagicNoTrans = []byte(`NO-TRANS`) // 不需要启动事务
)

魔法注释

Functions

func AddPlan

func AddPlan(dir string, plan *Plan, project, engine string) error

AddPlan 添加部署计划

func ConvertUri2Dsn added in v0.2.5

func ConvertUri2Dsn(uri string) (string, error)

ConvertUri2Dsn 直接将DB-URI转换为DSN

func DbUri2Dsn

func DbUri2Dsn(params *Params) string

DbUri2Dsn 转换DB-URI参数为DSN

func InitProject

func InitProject(project *ProjectInfo) error

InitProject 初始化项目

func RegisterEngine

func RegisterEngine(name string, eng Engine)

RegisterEngine 注册数据库引擎

Types

type ConfParser

type ConfParser func(dir string) (*Config, error)

ConfParser 配置文件解析函数

type Config

type Config struct {
	Engine    string `yaml:"engine"`    // 优先使用dburi中的engine
	FromTable string `yaml:"fromTable"` // 重命名日志表
	LogsTable string `yaml:"logsTable"` // [default= dbvm_logs]

	Rule *Rule `yaml:"rule"`
}

Config 数据库配置

func ParseConfig

func ParseConfig(dir string) (*Config, error)

解析配置文件

type Database

type Database struct {
	Create bool `yaml:"create"`
	Drop   bool `yaml:"drop"`
}

Database 数据库规则

type Engine

type Engine interface {
	// Connect 连接到数据库
	Connect(*Params) error
	// Close 关闭数据库连接
	Close()

	// Initiate 初始化日志表
	Initiate(string) error

	// ListLogs 获取版本更新历史
	ListLogs() ([]*Log, error)

	// Deploy 部署指定版本
	Deploy(*Plan) error
	// Revert 回退指定版本
	Revert(*Plan) error
}

Engine 数据库驱动引擎

func GetEngine

func GetEngine(name string) Engine

GetEngine 获取数据库引擎,可能为空

type Field

type Field struct {
	NotNull bool     `yaml:"notNull"`
	Excepts []string `yaml:"excepts"`
}

Field 字段规则

type Log

type Log struct {
	ID     uint32 // 日志ID, 可选
	Name   string // 版本名称,必须
	Time   uint64 // 部署时间,可选
	Status uint8  // 完成状态,必须(0未完成,1已完成)
}

Log 数据库操作日志

type Manager

type Manager struct {
	// contains filtered or unexported fields
}

Manager 管理器,非线程安全

func New

func New(dir, dburi string) (mgr *Manager, err error)

New 初始化版本管理器

func NewWithParser

func NewWithParser(dir, dburi string, confParser ConfParser, planParser PlanParser) (mgr *Manager, err error)

NewWithParser 自定义配置解析

func (*Manager) Close

func (m *Manager) Close()

Close 关闭管理器

func (*Manager) Deploy

func (m *Manager) Deploy(to string, forces []string) error

Deploy 部署到指定版本

func (*Manager) GetLogsTable

func (m *Manager) GetLogsTable() string

GetLogsTable 获取日志数据库的表名

func (*Manager) Revert

func (m *Manager) Revert(to string) error

Revert 回退版本

type Params

type Params struct {
	Engine   string
	Username string
	Password string
	Host     string
	Port     string
	Database string
	Query    string
	Fragment string
}

Params 数据库参数 Engine & Database can't be empty

func ParseDbUri

func ParseDbUri(uri string) (params *Params, err error)

ParseDbUri 从URI字符串中解析数据库参数

type Plan

type Plan struct {
	Name     string
	Requires []string
	Time     time.Time
	User     string
	Hostname string
	Note     string
	Deploy   string
	Revert   string
	// contains filtered or unexported fields
}

Plan 执行计划

func ParsePlan

func ParsePlan(dir string) (map[string]string, []*Plan, error)

解析执行计划列表

type PlanParser

type PlanParser func(dir string) (map[string]string, []*Plan, error)

PlanParser 部署计划解析函数

type ProjectInfo

type ProjectInfo struct {
	Version string
	Project string
	URI     string
	Dir     string
	Engine  string
	Table   string
}

ProjectInfo 项目信息

type Rule

type Rule struct {
	Database *Database `yaml:"database"`
	Field    *Field    `yaml:"field"`
}

Rule 规则

Jump to

Keyboard shortcuts

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