refactor main

This commit is contained in:
Ross Trottier 2024-05-21 11:37:55 -06:00
parent cb6dd813f5
commit 5119490b3d

14
main.go
View File

@ -21,7 +21,13 @@ var slowtwitchDB *sql.DB
var resultsDB *sql.DB
func main() {
//Connect to databases
connectToDatabases()
migrateAuthors()
migrateCategories()
migratePosts()
}
func connectToDatabases() {
slowtwitchDatabase, slowtwitchDbErr := migration.Connect(slowtwitchAdminUser, slowtwitchAdminPass, federatedDbUrl, federatedDbPort, slowtwitchDbName+"?parseTime=true")
if slowtwitchDbErr != nil {
panic("Could not connect to slowtwitch database.")
@ -34,7 +40,9 @@ func main() {
} else {
resultsDB = resultsDatabase
}
}
func migrateAuthors() {
fmt.Println("Migrating Authors and Editors")
editorMigration := migration.MigrateAuthors{
SlowtwitchDatabase: slowtwitchDB,
@ -45,7 +53,9 @@ func main() {
}
editorResults := editorMigration.Execute()
fmt.Println("Migrated", len(editorResults), "Editors and Authors")
}
func migrateCategories() {
fmt.Println("Migrating Categories")
categoryMigration := migration.MigrateCategories{
SlowtwitchDatabase: slowtwitchDB,
@ -56,7 +66,9 @@ func main() {
}
categoryResults := categoryMigration.Execute()
fmt.Println("Migrated", len(categoryResults), "Categories")
}
func migratePosts() {
fmt.Println("Migrating Posts")
postMigration := migration.MigratePosts{
SlowtwitchDatabase: slowtwitchDB,