dbmigrate

package
v1.27.0 Latest Latest
Warning

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

Go to latest
Published: Jul 3, 2026 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Overview

Package dbmigrate는 embed.FS의 manifest.txt 순서대로 SQL 파일을 실행합니다.

패키지 개요

이 패키지는 bot별 migrations embed.FS와 database/sql 또는 pgx 실행 함수를 주입받아 manifest 순서를 공통으로 처리합니다. manifest 라인은 "NNN file.sql" 형식을 기대하며 빈 줄과 '#' 주석은 무시합니다.

주요 사용 패턴

err := dbmigrate.Apply(ctx, migrations.FS, dbmigrate.SQLExec(db))
err = dbmigrate.Apply(ctx, migrations.FS, func(ctx context.Context, query string) error {
    _, execErr := conn.Exec(ctx, query)
    return execErr
}, dbmigrate.WithOnly("0001_repository_baseline.sql"))

Index

Constants

View Source
const (
	// ManifestName은 기본 migration manifest 파일명이다.
	ManifestName = "manifest.txt"
)

Variables

This section is empty.

Functions

func Apply

func Apply(ctx context.Context, fsys fs.FS, exec Execer, opts ...Option) error

Apply는 manifest 순서대로 SQL 파일을 읽어 exec로 실행한다.

func Manifest

func Manifest(fsys fs.FS) (names []string, err error)

Manifest는 manifest.txt를 파싱해 적용 순서대로 SQL 파일명을 반환한다.

Types

type Execer

type Execer func(context.Context, string) error

Execer는 migration SQL 실행 함수다.

func SQLExec

func SQLExec(db SQLExecer) Execer

SQLExec는 database/sql 계열 handle을 Execer로 감싼다.

type Option

type Option func(*options)

Option은 migration 적용 동작을 조정한다.

func WithOnly

func WithOnly(names ...string) Option

WithOnly는 지정한 migration 파일명만 manifest 순서대로 적용한다.

type SQLExecer

type SQLExecer interface {
	ExecContext(ctx context.Context, query string, args ...any) (sql.Result, error)
}

SQLExecer는 database/sql 계열 ExecContext 최소 인터페이스다.

Jump to

Keyboard shortcuts

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