diff --git a/MigrationMap.go b/MigrationMap.go index 688459e..fab309f 100644 --- a/MigrationMap.go +++ b/MigrationMap.go @@ -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{}} } diff --git a/migrate.go b/migrate.go index bee1ac6..c4216ed 100644 --- a/migrate.go +++ b/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) diff --git a/models.go b/models.go new file mode 100644 index 0000000..e93e9a1 --- /dev/null +++ b/models.go @@ -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) +}