This repository holds the code that was used when migrating the rsdb-beta version from mongodb to mysql.
This code is not to be distributed or used in any way without explicit permission of the Erik Westra
- Create a mysql database and initialize the schemas by running the rsdb-backend (this will automatically create all the required tables)
- Get a JSON dump of the mongodb database collections (articles, platforms, projects, contacts) using mongoexport
- For the articles and projects tables there were four or five entries where
tags
was specified as a string instead of an array of strings, I manually changed these in the json file as there were only a few cases of them. - Pull this repository to your local machine.
- Create an .env environment file with a database connection string to connect to your mysql database following the format below.
DB_CONNECTION_STRING="*USER*:*PASSWORD*@*PROTOCOL*(*HOST*:*PORT*)/*DATABASENAME*?parseTime=true"
- Place the json files in the repo using the following file structure:
- .env
- mongodump/
-articles.json
-contacts.json
-platforms.json
-projects.json
- main.go
- Run the main file
go run main.go
to populate the database with all the migrated data from mongodb
The LoadedData Type which holds all the data after it has been unmarshalled from json contains a function HandleEdgeCases()
located in ./importer/edgecases.go
. This function can be used to add any manipulations to any of the data arrays after being marshalled from JSON. I have used this to handle any weird edge cases in the mongodb database.
Unit tests can be run using the make unit-test
command or any of the normal testing commands for go. The advantage of using the make command is that it will install a small package called tparse which will parse the test coverage and success results into a nice table to display in the command line: