From 9f2d3a1737581237e45aacaba02346f4e939e251 Mon Sep 17 00:00:00 2001
From: Subv <subv2112@gmail.com>
Date: Sat, 23 May 2020 11:46:28 -0500
Subject: [PATCH] Manually set the default values for the OpenID Connect
 columns.

There is a Knex issue ( https://github.com/knex/knex/issues/2649 ) that prevents .defaultTo from working for text columns.
---
 .../20200523114256_openid_default_values.js   | 36 +++++++++++++++++++
 1 file changed, 36 insertions(+)
 create mode 100644 backend/migrations/20200523114256_openid_default_values.js

diff --git a/backend/migrations/20200523114256_openid_default_values.js b/backend/migrations/20200523114256_openid_default_values.js
new file mode 100644
index 0000000..90622ed
--- /dev/null
+++ b/backend/migrations/20200523114256_openid_default_values.js
@@ -0,0 +1,36 @@
+const migrate_name = 'openid_default_values';
+const logger       = require('../logger').migrate;
+
+/**
+ * Migrate
+ *
+ * @see http://knexjs.org/#Schema
+ *
+ * @param   {Object}  knex
+ * @param   {Promise} Promise
+ * @returns {Promise}
+ */
+exports.up = function (knex/*, Promise*/) {
+	logger.info('[' + migrate_name + '] Migrating Up...');
+
+	return knex.schema.raw('ALTER TABLE proxy_host ALTER openidc_redirect_uri SET DEFAULT \'\'')
+		.then(() => knex.schema.raw('ALTER TABLE proxy_host ALTER openidc_discovery SET DEFAULT \'\''))
+		.then(() => knex.schema.raw('ALTER TABLE proxy_host ALTER openidc_auth_method SET DEFAULT \'client_secret_post\''))
+		.then(() => knex.schema.raw('ALTER TABLE proxy_host ALTER openidc_client_id SET DEFAULT \'\''))
+		.then(() => knex.schema.raw('ALTER TABLE proxy_host ALTER openidc_client_secret SET DEFAULT \'\''))
+		.then(() => {
+			logger.info('[' + migrate_name + '] proxy_host Table altered');
+		});
+};
+
+/**
+ * Undo Migrate
+ *
+ * @param   {Object}  knex
+ * @param   {Promise} Promise
+ * @returns {Promise}
+ */
+exports.down = function (knex, Promise) {
+	logger.warn('[' + migrate_name + '] You can\'t migrate down this one.');
+	return Promise.resolve(true);
+};