refactor: move structs to models
This commit is contained in:
parent
9c7c12b76d
commit
be782fb9c2
3 changed files with 37 additions and 32 deletions
|
@ -5,15 +5,6 @@ import (
|
|||
"fmt"
|
||||
)
|
||||
|
||||
type MigrationGraph struct {
|
||||
// Reference to the root of the graph.
|
||||
Root *Migration
|
||||
// Name to struct mapping of all migrations part of the graph.
|
||||
Migrations map[string]Migration
|
||||
// Mapping of all migrations to their parent, if any.
|
||||
parentage map[string]*Migration
|
||||
}
|
||||
|
||||
func NewMigrationGraph() MigrationGraph {
|
||||
return MigrationGraph{Migrations: map[string]Migration{}, parentage: map[string]*Migration{}}
|
||||
}
|
||||
|
|
23
migrate.go
23
migrate.go
|
@ -17,21 +17,6 @@ import (
|
|||
"strconv"
|
||||
)
|
||||
|
||||
type MigrationHeaders struct {
|
||||
Requirements []string
|
||||
}
|
||||
|
||||
type Migration struct {
|
||||
Path string
|
||||
Name string
|
||||
Requires string
|
||||
Run bool
|
||||
}
|
||||
|
||||
type DB interface {
|
||||
Exec(sql string, args ...any) (sql.Result, error)
|
||||
}
|
||||
|
||||
var commentPrefix = []byte("--")
|
||||
var requirementPrefix = []byte("requires:")
|
||||
|
||||
|
@ -143,14 +128,6 @@ func getMigrations(migrationsRoot string) ([]Migration, error) {
|
|||
return migrationGraph.GetLinearHistory()
|
||||
}
|
||||
|
||||
type DatabaseConfiguration struct {
|
||||
Host string
|
||||
User string
|
||||
Password string
|
||||
DatabaseName string
|
||||
Port int
|
||||
}
|
||||
|
||||
func ConnectToDatabase(config DatabaseConfiguration) (*sql.DB, error) {
|
||||
connectionString := fmt.Sprintf("postgresql://%s:%s@%s:%d?sslmode=disable", config.User, config.Password, config.Host, config.Port)
|
||||
return sql.Open(config.DatabaseName, connectionString)
|
||||
|
|
37
models.go
Normal file
37
models.go
Normal file
|
@ -0,0 +1,37 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"database/sql"
|
||||
)
|
||||
|
||||
type MigrationHeaders struct {
|
||||
Requirements []string
|
||||
}
|
||||
|
||||
type Migration struct {
|
||||
Path string
|
||||
Name string
|
||||
Requires string
|
||||
Run bool
|
||||
}
|
||||
|
||||
type DatabaseConfiguration struct {
|
||||
Host string
|
||||
User string
|
||||
Password string
|
||||
DatabaseName string
|
||||
Port int
|
||||
}
|
||||
|
||||
type MigrationGraph struct {
|
||||
// Reference to the root of the graph.
|
||||
Root *Migration
|
||||
// Name to struct mapping of all migrations part of the graph.
|
||||
Migrations map[string]Migration
|
||||
// Mapping of all migrations to their parent, if any.
|
||||
parentage map[string]*Migration
|
||||
}
|
||||
|
||||
type DB interface {
|
||||
Exec(sql string, args ...any) (sql.Result, error)
|
||||
}
|
Loading…
Reference in a new issue