For anyone who wants to add PostgreSQL support to WriteFreely, here’s a basic walkthrough.
First, modify WriteFreely to connect to a PostgreSQL database.
- Change your
[database] type
config value to something like “postgresql” - Check for this new driver value inside
connectToDatabase()
in app.go- Import the github.com/lib/pq library in app.go
- Connect to the PostgreSQL database
- Compile the app
Without any other modifications, see what breaks:
- Run
./writefreely db init
and see if it succeeds - Click around the app and see what breaks. Areas to focus on:
- Publish posts. Update the published date to some time in the future (testing
NOW()
funcs) - Publish posts with hashtags, then navigate to the hashtag page and make sure the posts load (testing
LIKE
queries) - Enable MathJax, save blog settings, disable MathJax, save blog settings (testing upserts)
- Create pinned posts with titles longer than 80 characters (testing column clipping)
- Publish posts. Update the published date to some time in the future (testing
And make any changes necessary. Our standard approach is to add small helper funcs like these where differences between database systems exist.
If you want to contribute to the project, open a pull request once you’ve thoroughly tested everything. Then, add some automated tests to the ones we’ve already started in database_test.go
. The more coverage we have, the more likely we are to quickly accept your changes, because they’ll help immensely with maintaining this.