Documentation
¶
Index ¶
- func Migration(sqlDir string, session *dbr.Session) error
- func NewMySQL(addr string, sqlDir string, migration bool) *dbr.Session
- func NewRedis(addr string, password string) *redis.Conn
- func NewRedisFromConfig(cfg *config.Config) *redis.Conn
- func NewSqlite(filepath string, sqlDir string) *dbr.Session
- func ReconcileThreadSchemaRecords(ctx context.Context, db *sql.DB) error
- func RewriteLegacyMigrationIDs(ctx context.Context, db *sql.DB) error
- type BaseModel
- type FileDirMigrationSource
- type Time
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewRedisFromConfig ¶ added in v1.4.0
NewRedisFromConfig 从 cfg 构造 Redis 连接,自动应用 RedisTLS / CA 等设置。
func ReconcileThreadSchemaRecords ¶
ReconcileThreadSchemaRecords pre-seeds gorp_migrations with the thread module's migration IDs when the thread tables are already present from a prior snapshot-built install but the migration rows are missing. Without this, the next sql-migrate.Exec would try to apply CREATE TABLE `thread` (no IF NOT EXISTS) and panic with Error 1050.
Why a separate step from RewriteLegacyMigrationIDs: the legacy-ID rewrite is a 1:1 in-place rename, while this is a "the schema is here, please record that" reconciliation. Splitting them keeps each function's invariants narrow.
Idempotent on three axes:
- fresh install (no thread tables): no-op.
- already-reconciled install (rows present): no-op.
- already-applied install (sql-migrate ran the migrations itself): no-op.
Call after RewriteLegacyMigrationIDs and before module.Setup.
func RewriteLegacyMigrationIDs ¶
RewriteLegacyMigrationIDs maps any legacy entries in `gorp_migrations.id` to their new timestamp-prefixed equivalents.
Why this exists: sql-migrate (rubenv/sql-migrate@v1.5.2 migrate.go:135-146) falls back to lexicographic `m.Id < other.Id` when filenames don't start with digits, so the historical `<module>-<YYYYMMDD>-<NN>.sql` scheme ordered migrations by module name first — which caused cross-module dependencies like `botfather-20260417-01.sql` (ALTERs `robot`) to run before `robot-20210926-01.sql` (CREATEs the table). The fix is to rename every file to a 14-digit timestamp prefix; the cost is that any already-applied database has the old IDs in `gorp_migrations` and would otherwise hit sql-migrate's "unknown migration in database" safety check.
This function is idempotent: it only rewrites rows whose old ID is present AND whose new ID is absent, and it leaves no trace on a fresh install (the table is empty, so the loop is a no-op).
Call this once at startup, before any call to migrate.Exec / module.Setup.
Types ¶
type FileDirMigrationSource ¶
type FileDirMigrationSource struct {
Dir string
}
FileDirMigrationSource 文件目录源 遇到目录进行递归获取
func (FileDirMigrationSource) FindMigrations ¶
func (f FileDirMigrationSource) FindMigrations() ([]*migrate.Migration, error)
FindMigrations FindMigrations