Compare commits

..

2 Commits

3 changed files with 64 additions and 3 deletions

61
main.go
View File

@ -42,6 +42,67 @@ func connectToDatabases() {
} else { } else {
resultsDB = resultsDatabase resultsDB = resultsDatabase
} }
createEditorsTableSQL := `
create table if not exists EditorsResults(
Id int primary key not null auto_increment,
WordpressId int not null,
Username nvarchar(100) not null,
Email nvarchar(100),
IsSuccess BIT not null
);`
_, editorsTableErr := resultsDB.Exec(createEditorsTableSQL)
if editorsTableErr != nil {
panic("Could not create editors table.")
}
createCategoryResultsTableSQL := `
create table if not exists CategoryResults (
Id int primary key not null auto_increment,
SlowtwitchId int not null,
WordpressId int not null,
OldUrl nvarchar(500) not null,
OldUrlStatus int,
NewUrl nvarchar(500),
IsSuccess BIT not null,
ErrorMessage nvarchar(1500)
);`
_, createCategoryResultsTableErr := resultsDB.Exec(createCategoryResultsTableSQL)
if createCategoryResultsTableErr != nil {
panic("Could not create category results table.")
}
createImageResultsTableSQL := `
create table if not exists ImageResults(
Id int primary key not null auto_increment,
PostId int null,
WordpressId int not null,
OldUrl nvarchar(500) not null,
NewUrl nvarchar(500),
IsSuccess BIT not null,
ErrorMessage nvarchar(1500),
foreign key (PostId) references PostResults(Id)
);`
_, createImageResultsTableErr := resultsDB.Exec(createImageResultsTableSQL)
if createImageResultsTableErr != nil {
panic("Could not create image results table.")
}
createPostsResultsTableSQL := `
create table if not exists PostResults(
Id int primary key not null auto_increment,
SlowtwitchId int not null,
WordpressId int not null,
OldUrl nvarchar(500) not null,
OldUrlStatus int,
NewUrl nvarchar(500),
IsSuccess BIT not null,
ErrorMessage nvarchar(1500)
);`
_, createPostsResultsTableErr := resultsDB.Exec(createPostsResultsTableSQL)
if createPostsResultsTableErr != nil {
panic("Could not create post results table.")
}
} }
func migrateAuthors() { func migrateAuthors() {

View File

@ -243,7 +243,7 @@ func updatePostRelationships(postResults []PostResult, migration MigratePosts) {
relatedSlowtwitchIds, slowtwitchIdsErr := slowtwitch.GetRelatedArticleIds(postResult.SlowtwitchId, migration.SlowtwitchDatabase) relatedSlowtwitchIds, slowtwitchIdsErr := slowtwitch.GetRelatedArticleIds(postResult.SlowtwitchId, migration.SlowtwitchDatabase)
if slowtwitchIdsErr != nil { if slowtwitchIdsErr != nil || len(relatedSlowtwitchIds) == 0 {
continue continue
} }
for _, slowtwitchRelatedId := range relatedSlowtwitchIds { for _, slowtwitchRelatedId := range relatedSlowtwitchIds {
@ -251,7 +251,7 @@ func updatePostRelationships(postResults []PostResult, migration MigratePosts) {
if wordpressIdErr != nil { if wordpressIdErr != nil {
continue continue
} }
relatedSlowtwitchIds = append(relatedWordpressIds, wordpressRelatedId) relatedWordpressIds = append(relatedWordpressIds, wordpressRelatedId)
} }
if len(relatedWordpressIds) > 0 { if len(relatedWordpressIds) > 0 {

View File

@ -15,7 +15,7 @@ func GetRelatedArticleIds(postId int, db *sql.DB) ([]int, error) {
} }
var ids []int var ids []int
idsAsStrings := strings.Split(spaceSeparatedIds, " ") idsAsStrings := strings.Split(spaceSeparatedIds, "\r\n")
for _, stringId := range idsAsStrings { for _, stringId := range idsAsStrings {
id, err := strconv.Atoi(stringId) id, err := strconv.Atoi(stringId)
if err == nil { if err == nil {