PostgreSQL support

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
  • 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)

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.

2 Likes

Is anyone working on PostgreSQL support and had some progress?

If not, I will try above tips :nerd_face:

I started working on bringing PostgreSQL support to WriteFreely :nerd_face: My current progress is in db-postgresql branch: GitHub - gytisrepecka/writefreely at db-postgresql

At current stage build succeeds - tried on arm64 device. Note: github.com/lib/pq library requires Go version 1.15!

Currently I am rewriting schema.sql from MySQL create table statements to PostgreSQL - it takes effort since datatypes and constraint definitions are different.

Will keep posted about my progress :blush:

2 Likes

This is great to hear, @gytisrepecka! Looking forward to seeing your progress.

1 Like