migrate

package module
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Mar 14, 2025 License: MIT Imports: 2 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

Migrate

migrate is a wrapper around the goose migration tool for managing database migrations in Go applications. This package provides a straightforward interface for applying, rolling back, and managing migrations using a specified database dialect.

Installation

go get github.com/gosuit/migrate

Features

• Apply Migrations: Easily apply all pending migrations to the specified database.

• Rollback Migrations: Roll back the most recent migration or revert to a specific version.

• Dialect Support: Supports various database dialects through the goose library.

Usage

package main

import (
    "database/sql"
    "log"

    "github.com/gosuit/migrate"
)

func main() {
    db, err := <init sql.DB>

    err = migrate.Migrate(db, migrate.Postgres, "./migrations")
    if err != nil {
        log.Fatalf("failed to apply migrations: %v", err)
    }
}

Contributing

Contributions are welcome! Please feel free to submit a pull request or open an issue for any enhancements or bug fixes.

License

This project is licensed under the MIT License. See the LICENSE file for details.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Down

func Down(db *sql.DB, dialect Dialect, path string) error

Down rolls back a single migration from the current version

func DownTo

func DownTo(db *sql.DB, dialect Dialect, path string, version int64) error

DownTo rolls back migrations to a specific version.

func Migrate

func Migrate(db *sql.DB, dialect Dialect, path string) error

Migrate applies all pending database migrations to the specified database.

Types

type Dialect

type Dialect string
const (
	Postgres   Dialect = "postgres"
	Mysql      Dialect = "mysql"
	Sqlite3    Dialect = "sqlite3"
	Mssql      Dialect = "mssql"
	Redshift   Dialect = "redshift"
	TiDB       Dialect = "tidb"
	ClickHouse Dialect = "clickhouse"
)

Jump to

Keyboard shortcuts

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