14. August 2022 2 min read
Convert MySql exported data from Adminer JSON file to php array which can be imported into SleekDB
I wanted to put my personal blog on Kubernetes cluster, but the main hurdle was to get the MySQL server running on cluster. Because other applications already migrated to PostgreSQL server this would basically require a pod with persistent volume running on cluster for nothing. So I look at other solution. I am the only author of the articles so the database is in read-only mode for website serving. Because database is not really needed in this case I have decided to look for other options. One of the options was SQLite database, which would be stored in browser RAM and executed at user side. That meant each user would in fact get my whole database and since it is fairly small it would still mean transferring some not used data to the user. So I discarded the option and kept looking. I discovered SleekDB, which is a NoSQL database that uses json files for storage and it is implemented as native php arrays. The json data can be stored in git and edited through a simple text browser. That means embedded version control and easy readability of the data. So the biggest hurdle was to migrate the MySQL database to the SleekDB. Adminer script is able to export SQL file or CSV file. First I tried with SQL file, but there was no decent SQL to JSON converter for my double and single quoted links. So I used csv, and there was a decent CSV to JSON converter found here. After that I needed to convert JSON file to Php array, which I imported in a simple php script which then created the database and inserted the data.