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"
|
"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 {
|
func NewMigrationGraph() MigrationGraph {
|
||||||
return MigrationGraph{Migrations: map[string]Migration{}, parentage: map[string]*Migration{}}
|
return MigrationGraph{Migrations: map[string]Migration{}, parentage: map[string]*Migration{}}
|
||||||
}
|
}
|
||||||
|
|
23
migrate.go
23
migrate.go
|
@ -17,21 +17,6 @@ import (
|
||||||
"strconv"
|
"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 commentPrefix = []byte("--")
|
||||||
var requirementPrefix = []byte("requires:")
|
var requirementPrefix = []byte("requires:")
|
||||||
|
|
||||||
|
@ -143,14 +128,6 @@ func getMigrations(migrationsRoot string) ([]Migration, error) {
|
||||||
return migrationGraph.GetLinearHistory()
|
return migrationGraph.GetLinearHistory()
|
||||||
}
|
}
|
||||||
|
|
||||||
type DatabaseConfiguration struct {
|
|
||||||
Host string
|
|
||||||
User string
|
|
||||||
Password string
|
|
||||||
DatabaseName string
|
|
||||||
Port int
|
|
||||||
}
|
|
||||||
|
|
||||||
func ConnectToDatabase(config DatabaseConfiguration) (*sql.DB, error) {
|
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)
|
connectionString := fmt.Sprintf("postgresql://%s:%s@%s:%d?sslmode=disable", config.User, config.Password, config.Host, config.Port)
|
||||||
return sql.Open(config.DatabaseName, connectionString)
|
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