Files
lincodex/backend/db/migrations.go
T

26 lines
748 B
Go

// Package db embeds the versioned SQL migrations so the backend binary applies
// exactly the schema it was built with. The SQL files stay in db/migrations,
// where sqlc and sqlfluff also read them; go:embed cannot reach a parent
// directory, so the embedding package lives next to that directory.
package db
import (
"embed"
"fmt"
"io/fs"
)
const migrationsDirectory = "migrations"
//go:embed migrations/*.sql
var migrationFiles embed.FS
// Migrations returns the goose SQL migrations with file names at the root.
func Migrations() (fs.FS, error) {
migrations, err := fs.Sub(migrationFiles, migrationsDirectory)
if err != nil {
return nil, fmt.Errorf("db.Migrations - open embedded migrations: %w", err)
}
return migrations, nil
}