From f858ec163cdcbbcabf15019e2da76a95c41f87a5 Mon Sep 17 00:00:00 2001 From: Simon Ser Date: Tue, 8 Feb 2022 15:38:41 +0100 Subject: [PATCH] db_postgres: use enum for sasl_mechanism Ensures only supported mechanisms get stored in the DB. --- db_postgres.go | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/db_postgres.go b/db_postgres.go index 5ede40e..ce27eec 100644 --- a/db_postgres.go +++ b/db_postgres.go @@ -33,6 +33,8 @@ CREATE TABLE "User" ( realname VARCHAR(255) ); +CREATE TYPE sasl_mechanism AS ENUM ('PLAIN', 'EXTERNAL'); + CREATE TABLE "Network" ( id SERIAL PRIMARY KEY, name VARCHAR(255), @@ -43,7 +45,7 @@ CREATE TABLE "Network" ( realname VARCHAR(255), pass VARCHAR(255), connect_commands VARCHAR(1023), - sasl_mechanism VARCHAR(255), + sasl_mechanism sasl_mechanism, sasl_plain_username VARCHAR(255), sasl_plain_password VARCHAR(255), sasl_external_cert BYTEA, @@ -80,6 +82,13 @@ CREATE TABLE "DeliveryReceipt" ( var postgresMigrations = []string{ "", // migration #0 is reserved for schema initialization `ALTER TABLE "Network" ALTER COLUMN nick DROP NOT NULL`, + ` + CREATE TYPE sasl_mechanism AS ENUM ('PLAIN', 'EXTERNAL'); + ALTER TABLE "Network" + ALTER COLUMN sasl_mechanism + TYPE sasl_mechanism + USING sasl_mechanism::sasl_mechanism; + `, } type PostgresDB struct {