Post-Migrator/main.go
Ross Trottier 93f5c70236 First Test Run Complete
- TODO Thread Post Creation
- TODO Hunt Down Broken Slideshow Links
2024-05-23 07:41:47 -06:00

85 lines
2.4 KiB
Go

package main
import (
"database/sql"
"federated.computer/wp-sync-slowtwitch/services/migration"
"fmt"
)
// WP Config
const baseUrl = "https://slowtwitch.cloud/"
const wordpressKey = "admin@slowtwitch.cloud"
const wordpressSecret = "6zY7 xsKZ dGIt l1Lp ypIK 6TWh"
// DB Config
const slowtwitchAdminUser = "admin"
const slowtwitchAdminPass = "yxnh93Ybbz2Nm8#mp28zCVv"
const slowtwitchDbName = "slowtwitch"
const migrationDbName = "slowtwitch_transfer"
const federatedDbUrl = "slowtwitch.northend.network"
const federatedDbPort = "3306"
var slowtwitchDB *sql.DB
var resultsDB *sql.DB
func main() {
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.")
} else {
slowtwitchDB = slowtwitchDatabase
}
resultsDatabase, resultsDBerr := migration.Connect(slowtwitchAdminUser, slowtwitchAdminPass, federatedDbUrl, federatedDbPort, migrationDbName)
if resultsDBerr != nil {
panic("Could not connect to results database.")
} else {
resultsDB = resultsDatabase
}
}
func migrateAuthors() {
fmt.Println("Migrating Authors and Editors")
editorMigration := migration.MigrateAuthors{
SlowtwitchDatabase: slowtwitchDB,
ResultsDatabase: resultsDB,
WordpressBaseUrl: baseUrl,
WordpressUser: wordpressKey,
WordpressPassword: wordpressSecret,
}
editorResults := editorMigration.Execute()
fmt.Println("Migrated", len(editorResults), "Editors and Authors")
}
func migrateCategories() {
fmt.Println("Migrating Categories")
categoryMigration := migration.MigrateCategories{
SlowtwitchDatabase: slowtwitchDB,
ResultsDatabase: resultsDB,
WordpressBaseUrl: baseUrl,
WordpressUser: wordpressKey,
WordpressPassword: wordpressSecret,
}
categoryResults := categoryMigration.Execute()
fmt.Println("Migrated", len(categoryResults), "Categories")
}
func migratePosts() {
fmt.Println("Migrating Posts")
postMigration := migration.MigratePosts{
SlowtwitchDatabase: slowtwitchDB,
ResultsDatabase: resultsDB,
WordpressBaseUrl: baseUrl,
WordpressUser: wordpressKey,
WordpressPassword: wordpressSecret,
}
results := postMigration.Execute()
fmt.Println("Migration complete, migrated", len(results), "Posts")
}