diff --git a/backend/migrations.js b/backend/migrations.js index b348ae1..0240694 100644 --- a/backend/migrations.js +++ b/backend/migrations.js @@ -1,3 +1,6 @@ +process.env.POSTGRES_USER = process.env.POSTGRES_USER ?? "postgres"; +process.env.POSTGRES_ROLE = + process.env.POSTGRES_ROLE ?? process.env.POSTGRES_USER; module.exports = { development: { @@ -55,4 +58,4 @@ module.exports = { } } }; - \ No newline at end of file + diff --git a/backend/migrations/001_app_config_table.js b/backend/migrations/001_app_config_table.js index e1a4185..8b03f72 100644 --- a/backend/migrations/001_app_config_table.js +++ b/backend/migrations/001_app_config_table.js @@ -10,7 +10,7 @@ exports.up = async function(knex) { table.text('APP_USER'); table.text('APP_PASSWORD'); }); - await knex.raw(`ALTER TABLE app_config OWNER TO "${process.env.POSTGRES_USER}";`); + await knex.raw(`ALTER TABLE app_config OWNER TO "${process.env.POSTGRES_ROLE}";`); } }catch (error) { console.error(error); diff --git a/backend/migrations/002_jf_activity_watchdog_table.js b/backend/migrations/002_jf_activity_watchdog_table.js index 9b55e87..6344a5c 100644 --- a/backend/migrations/002_jf_activity_watchdog_table.js +++ b/backend/migrations/002_jf_activity_watchdog_table.js @@ -20,7 +20,7 @@ exports.up = async function(knex) { table.timestamp('ActivityDateInserted').defaultTo(knex.fn.now()); table.text('PlayMethod'); }); - await knex.raw(`ALTER TABLE jf_activity_watchdog OWNER TO "${process.env.POSTGRES_USER}";`); + await knex.raw(`ALTER TABLE jf_activity_watchdog OWNER TO "${process.env.POSTGRES_ROLE}";`); } } catch (error) { console.error(error); diff --git a/backend/migrations/003_jf_libraries_table.js b/backend/migrations/003_jf_libraries_table.js index 970e0c3..b37a57a 100644 --- a/backend/migrations/003_jf_libraries_table.js +++ b/backend/migrations/003_jf_libraries_table.js @@ -11,7 +11,7 @@ exports.up = async function(knex) { table.text('CollectionType').notNullable(); table.text('ImageTagsPrimary'); }); - await knex.raw(`ALTER TABLE jf_libraries OWNER TO "${process.env.POSTGRES_USER}";`); + await knex.raw(`ALTER TABLE jf_libraries OWNER TO "${process.env.POSTGRES_ROLE}";`); } } catch (error) { console.error(error); @@ -25,4 +25,4 @@ exports.up = async function(knex) { console.error(error); } }; - \ No newline at end of file + diff --git a/backend/migrations/004_jf_library_items_table.js b/backend/migrations/004_jf_library_items_table.js index ff4cf0b..0d0c53c 100644 --- a/backend/migrations/004_jf_library_items_table.js +++ b/backend/migrations/004_jf_library_items_table.js @@ -22,7 +22,7 @@ exports.up = async function(knex) { table.text('ParentId').notNullable().references('Id').inTable('jf_libraries').onDelete('SET NULL').onUpdate('NO ACTION'); table.text('PrimaryImageHash'); }); - await knex.raw(`ALTER TABLE IF EXISTS jf_library_items OWNER TO "${process.env.POSTGRES_USER}";`); + await knex.raw(`ALTER TABLE IF EXISTS jf_library_items OWNER TO "${process.env.POSTGRES_ROLE}";`); } } catch (error) { diff --git a/backend/migrations/005_jf_library_seasons_table.js b/backend/migrations/005_jf_library_seasons_table.js index c048404..a85e90f 100644 --- a/backend/migrations/005_jf_library_seasons_table.js +++ b/backend/migrations/005_jf_library_seasons_table.js @@ -16,7 +16,7 @@ exports.up = async function(knex) { table.text('SeriesPrimaryImageTag'); }); - await knex.raw(`ALTER TABLE IF EXISTS jf_library_seasons OWNER TO "${process.env.POSTGRES_USER}";`); + await knex.raw(`ALTER TABLE IF EXISTS jf_library_seasons OWNER TO "${process.env.POSTGRES_ROLE}";`); } } catch (error) { console.error(error); diff --git a/backend/migrations/006_jf_library_episodes_table.js b/backend/migrations/006_jf_library_episodes_table.js index 64514fb..c8cd6c4 100644 --- a/backend/migrations/006_jf_library_episodes_table.js +++ b/backend/migrations/006_jf_library_episodes_table.js @@ -24,7 +24,7 @@ exports.up = async function(knex) { table.text('SeriesName'); }); - await knex.raw(`ALTER TABLE IF EXISTS jf_library_episodes OWNER TO "${process.env.POSTGRES_USER}";`); + await knex.raw(`ALTER TABLE IF EXISTS jf_library_episodes OWNER TO "${process.env.POSTGRES_ROLE}";`); } } catch (error) { console.error(error); diff --git a/backend/migrations/007_jf_playback_activity_table.js b/backend/migrations/007_jf_playback_activity_table.js index 6d0bc9a..fe725d1 100644 --- a/backend/migrations/007_jf_playback_activity_table.js +++ b/backend/migrations/007_jf_playback_activity_table.js @@ -21,7 +21,7 @@ exports.up = async function(knex) { table.text('PlayMethod'); }); - await knex.raw(`ALTER TABLE IF EXISTS jf_playback_activity OWNER TO "${process.env.POSTGRES_USER}";`); + await knex.raw(`ALTER TABLE IF EXISTS jf_playback_activity OWNER TO "${process.env.POSTGRES_ROLE}";`); } } catch (error) { console.error(error); diff --git a/backend/migrations/008_js_users_table.js b/backend/migrations/008_js_users_table.js index 4609108..7964e84 100644 --- a/backend/migrations/008_js_users_table.js +++ b/backend/migrations/008_js_users_table.js @@ -11,7 +11,7 @@ table.boolean('IsAdministrator'); }); - await knex.raw(`ALTER TABLE IF EXISTS jf_users OWNER TO "${process.env.POSTGRES_USER}";`);; + await knex.raw(`ALTER TABLE IF EXISTS jf_users OWNER TO "${process.env.POSTGRES_ROLE}";`);; } } catch (error) { console.error(error); @@ -26,4 +26,4 @@ } }; - \ No newline at end of file + diff --git a/backend/migrations/009_jf_all_user_activity_view.js b/backend/migrations/009_jf_all_user_activity_view.js index a23dda9..320cf35 100644 --- a/backend/migrations/009_jf_all_user_activity_view.js +++ b/backend/migrations/009_jf_all_user_activity_view.js @@ -59,4 +59,4 @@ exports.up = async function(knex) { exports.down = async function(knex) { await knex.raw(`DROP VIEW jf_all_user_activity;`); }; - \ No newline at end of file + diff --git a/backend/migrations/013_fs_last_user_activity_function.js b/backend/migrations/013_fs_last_user_activity_function.js index 5df1384..8e17f1c 100644 --- a/backend/migrations/013_fs_last_user_activity_function.js +++ b/backend/migrations/013_fs_last_user_activity_function.js @@ -44,7 +44,7 @@ exports.up = function(knex) { $BODY$; ALTER FUNCTION fs_last_user_activity(text) - OWNER TO "${process.env.POSTGRES_USER}"; + OWNER TO "${process.env.POSTGRES_ROLE}"; `).catch(function(error) { console.error(error); }); @@ -55,4 +55,4 @@ exports.up = function(knex) { DROP FUNCTION IF EXISTS fs_last_user_activity(text); `); }; - \ No newline at end of file + diff --git a/backend/migrations/014_fs_library_stats_function.js b/backend/migrations/014_fs_library_stats_function.js index b4a9fbb..353286d 100644 --- a/backend/migrations/014_fs_library_stats_function.js +++ b/backend/migrations/014_fs_library_stats_function.js @@ -28,7 +28,7 @@ exports.up = async function(knex) { $BODY$; ALTER FUNCTION fs_library_stats(integer, text) - OWNER TO "${process.env.POSTGRES_USER}"; + OWNER TO "${process.env.POSTGRES_ROLE}"; `).catch(function(error) { console.error(error); }); @@ -39,4 +39,4 @@ exports.up = async function(knex) { DROP FUNCTION IF EXISTS fs_library_stats(integer, text); `); }; - \ No newline at end of file + diff --git a/backend/migrations/015_fs_most_active_user_function.js b/backend/migrations/015_fs_most_active_user_function.js index 3927a57..bbc3647 100644 --- a/backend/migrations/015_fs_most_active_user_function.js +++ b/backend/migrations/015_fs_most_active_user_function.js @@ -20,7 +20,7 @@ exports.up = function(knex) { END; $BODY$; ALTER FUNCTION fs_most_active_user(integer) - OWNER TO "${process.env.POSTGRES_USER}"; + OWNER TO "${process.env.POSTGRES_ROLE}"; `).catch(function(error) { console.error(error); }); @@ -29,4 +29,4 @@ exports.up = function(knex) { exports.down = function(knex) { return knex.raw('DROP FUNCTION IF EXISTS fs_most_active_user(integer)'); }; - \ No newline at end of file + diff --git a/backend/migrations/016_fs_most_played_items_function.js b/backend/migrations/016_fs_most_played_items_function.js index 5ac4b79..c15f404 100644 --- a/backend/migrations/016_fs_most_played_items_function.js +++ b/backend/migrations/016_fs_most_played_items_function.js @@ -47,7 +47,7 @@ exports.up = async function(knex) { $BODY$; ALTER FUNCTION fs_most_played_items(integer, text) - OWNER TO "${process.env.POSTGRES_USER}"; + OWNER TO "${process.env.POSTGRES_ROLE}"; `).catch(function(error) { console.error(error); }); @@ -56,4 +56,4 @@ exports.up = async function(knex) { exports.down = async function(knex) { await knex.raw('DROP FUNCTION IF EXISTS fs_most_played_items(integer, text)'); }; - \ No newline at end of file + diff --git a/backend/migrations/017_fs_most_popular_items_function.js b/backend/migrations/017_fs_most_popular_items_function.js index 3e60d69..6379306 100644 --- a/backend/migrations/017_fs_most_popular_items_function.js +++ b/backend/migrations/017_fs_most_popular_items_function.js @@ -53,7 +53,7 @@ exports.up = async function(knex) { END; $BODY$; ALTER FUNCTION fs_most_popular_items(integer, text) - OWNER TO "${process.env.POSTGRES_USER}"; + OWNER TO "${process.env.POSTGRES_ROLE}"; `).catch(function(error) { console.error(error); }); @@ -62,4 +62,4 @@ exports.up = async function(knex) { exports.down = async function(knex) { await knex.raw(`DROP FUNCTION fs_most_popular_items(integer, text);`); }; - \ No newline at end of file + diff --git a/backend/migrations/018_fs_most_used_clients_function.js b/backend/migrations/018_fs_most_used_clients_function.js index 31e90c6..d03ddb6 100644 --- a/backend/migrations/018_fs_most_used_clients_function.js +++ b/backend/migrations/018_fs_most_used_clients_function.js @@ -22,7 +22,7 @@ exports.up = async function(knex) { $BODY$; ALTER FUNCTION fs_most_used_clients(integer) - OWNER TO "${process.env.POSTGRES_USER}"; + OWNER TO "${process.env.POSTGRES_ROLE}"; `).catch(function(error) { console.error(error); }); @@ -31,4 +31,4 @@ exports.up = async function(knex) { exports.down = async function(knex) { await knex.raw(`DROP FUNCTION fs_most_used_clients(integer);`); }; - \ No newline at end of file + diff --git a/backend/migrations/019_fs_most_viewed_libraries_function.js b/backend/migrations/019_fs_most_viewed_libraries_function.js index 9ab33a3..e3a43cf 100644 --- a/backend/migrations/019_fs_most_viewed_libraries_function.js +++ b/backend/migrations/019_fs_most_viewed_libraries_function.js @@ -51,7 +51,7 @@ exports.up = function(knex) { $BODY$; ALTER FUNCTION fs_most_viewed_libraries(integer) - OWNER TO "${process.env.POSTGRES_USER}"; + OWNER TO "${process.env.POSTGRES_ROLE}"; `).catch(function(error) { console.error(error); }); @@ -62,4 +62,4 @@ exports.up = function(knex) { DROP FUNCTION IF EXISTS fs_most_viewed_libraries(integer); `); }; - \ No newline at end of file + diff --git a/backend/migrations/020_fs_user_stats_function.js b/backend/migrations/020_fs_user_stats_function.js index 0ee0d28..6c1b34d 100644 --- a/backend/migrations/020_fs_user_stats_function.js +++ b/backend/migrations/020_fs_user_stats_function.js @@ -32,7 +32,7 @@ exports.up = async function(knex) { $BODY$; ALTER FUNCTION fs_user_stats(integer, text) - OWNER TO "${process.env.POSTGRES_USER}"; + OWNER TO "${process.env.POSTGRES_ROLE}"; `).catch(function(error) { console.error(error); }); diff --git a/backend/migrations/021_fs_watch_stats_over_time_functions.js b/backend/migrations/021_fs_watch_stats_over_time_functions.js index 03f6e17..d95d6be 100644 --- a/backend/migrations/021_fs_watch_stats_over_time_functions.js +++ b/backend/migrations/021_fs_watch_stats_over_time_functions.js @@ -48,7 +48,7 @@ exports.up = async function (knex) { $BODY$; ALTER FUNCTION fs_watch_stats_over_time(integer) - OWNER TO "${process.env.POSTGRES_USER}"; + OWNER TO "${process.env.POSTGRES_ROLE}"; `).catch(function(error) { console.error(error); }); diff --git a/backend/migrations/022_fs_watch_stats_popular_days_of_week_function.js b/backend/migrations/022_fs_watch_stats_popular_days_of_week_function.js index 2801c0b..25ec192 100644 --- a/backend/migrations/022_fs_watch_stats_popular_days_of_week_function.js +++ b/backend/migrations/022_fs_watch_stats_popular_days_of_week_function.js @@ -56,7 +56,7 @@ exports.up =async function(knex) { END; $BODY$; ALTER FUNCTION fs_watch_stats_popular_days_of_week(integer) - OWNER TO "${process.env.POSTGRES_USER}"; + OWNER TO "${process.env.POSTGRES_ROLE}"; `).catch(function(error) { console.error(error); }); diff --git a/backend/migrations/023_fs_watch_stats_popular_hour_of_day_function,js.js b/backend/migrations/023_fs_watch_stats_popular_hour_of_day_function,js.js index 9871c26..2b029ec 100644 --- a/backend/migrations/023_fs_watch_stats_popular_hour_of_day_function,js.js +++ b/backend/migrations/023_fs_watch_stats_popular_hour_of_day_function,js.js @@ -42,7 +42,7 @@ exports.up =async function(knex) { END; $BODY$; ALTER FUNCTION fs_watch_stats_popular_hour_of_day(integer) - OWNER TO "${process.env.POSTGRES_USER}"; + OWNER TO "${process.env.POSTGRES_ROLE}"; `).catch(function(error) { console.error(error); }); diff --git a/backend/migrations/024_jf_item_info_table.js b/backend/migrations/024_jf_item_info_table.js index 55ed620..be4c47f 100644 --- a/backend/migrations/024_jf_item_info_table.js +++ b/backend/migrations/024_jf_item_info_table.js @@ -12,7 +12,7 @@ exports.up = async function(knex) { table.text('Type'); }); - await knex.raw(`ALTER TABLE IF EXISTS jf_item_info OWNER TO "${process.env.POSTGRES_USER}";`); + await knex.raw(`ALTER TABLE IF EXISTS jf_item_info OWNER TO "${process.env.POSTGRES_ROLE}";`); } } catch (error) { console.error(error); diff --git a/backend/migrations/026_fs_last_user_activity_function.js b/backend/migrations/026_fs_last_user_activity_function.js index 66b862a..29f5016 100644 --- a/backend/migrations/026_fs_last_user_activity_function.js +++ b/backend/migrations/026_fs_last_user_activity_function.js @@ -37,7 +37,7 @@ exports.up = function(knex) { $BODY$; ALTER FUNCTION fs_last_user_activity(text) - OWNER TO "${process.env.POSTGRES_USER}"; + OWNER TO "${process.env.POSTGRES_ROLE}"; `).catch(function(error) { console.error(error); }); @@ -90,7 +90,7 @@ exports.up = function(knex) { $BODY$; ALTER FUNCTION fs_last_user_activity(text) - OWNER TO "${process.env.POSTGRES_USER}"; + OWNER TO "${process.env.POSTGRES_ROLE}"; `); }; \ No newline at end of file diff --git a/backend/migrations/028_jf_playback_reporting_plugin_data_table.js b/backend/migrations/028_jf_playback_reporting_plugin_data_table.js index b30e7b5..3be43a7 100644 --- a/backend/migrations/028_jf_playback_reporting_plugin_data_table.js +++ b/backend/migrations/028_jf_playback_reporting_plugin_data_table.js @@ -15,7 +15,7 @@ exports.up = async function(knex) { table.bigInteger('PlayDuration'); }); - await knex.raw(`ALTER TABLE IF EXISTS jf_playback_reporting_plugin_data OWNER TO "${process.env.POSTGRES_USER}";`); + await knex.raw(`ALTER TABLE IF EXISTS jf_playback_reporting_plugin_data OWNER TO "${process.env.POSTGRES_ROLE}";`); } } catch (error) { console.error(error); diff --git a/backend/migrations/030_jf_logging_table.js b/backend/migrations/030_jf_logging_table.js index 9765a16..0246f9a 100644 --- a/backend/migrations/030_jf_logging_table.js +++ b/backend/migrations/030_jf_logging_table.js @@ -12,7 +12,7 @@ exports.up = async function(knex) { table.json('Log'); table.text('Result'); }); - await knex.raw(`ALTER TABLE jf_logging OWNER TO "${process.env.POSTGRES_USER}";`); + await knex.raw(`ALTER TABLE jf_logging OWNER TO "${process.env.POSTGRES_ROLE}";`); } } catch (error) { console.error(error); diff --git a/backend/migrations/065_ji_insert_playback_plugin_data_to_activity_table_fixes.js b/backend/migrations/065_ji_insert_playback_plugin_data_to_activity_table_fixes.js index 28a3194..7bf9ef6 100644 --- a/backend/migrations/065_ji_insert_playback_plugin_data_to_activity_table_fixes.js +++ b/backend/migrations/065_ji_insert_playback_plugin_data_to_activity_table_fixes.js @@ -54,7 +54,7 @@ exports.up = async function (knex) { $BODY$; ALTER PROCEDURE public.ji_insert_playback_plugin_data_to_activity_table() - OWNER TO "${process.env.POSTGRES_USER ?? postgres}";`); + OWNER TO "${process.env.POSTGRES_ROLE}";`); } catch (error) { console.error(error); } @@ -114,7 +114,7 @@ exports.down = async function (knex) { $BODY$; ALTER PROCEDURE public.ji_insert_playback_plugin_data_to_activity_table() - OWNER TO "${process.env.POSTGRES_USER ?? postgres}";`); + OWNER TO "${process.env.POSTGRES_ROLE}";`); } catch (error) { console.error(error); } diff --git a/backend/migrations/068_ji_insert_playback_plugin_data_to_activity_table_fixes_2.js b/backend/migrations/068_ji_insert_playback_plugin_data_to_activity_table_fixes_2.js index 9a8fbe8..4b5811d 100644 --- a/backend/migrations/068_ji_insert_playback_plugin_data_to_activity_table_fixes_2.js +++ b/backend/migrations/068_ji_insert_playback_plugin_data_to_activity_table_fixes_2.js @@ -55,7 +55,7 @@ exports.up = async function (knex) { $BODY$; ALTER PROCEDURE public.ji_insert_playback_plugin_data_to_activity_table() - OWNER TO "${process.env.POSTGRES_USER ?? postgres}"; + OWNER TO "${process.env.POSTGRES_ROLE}"; `); } catch (error) { console.error(error); @@ -118,7 +118,7 @@ exports.down = async function (knex) { $BODY$; ALTER PROCEDURE public.ji_insert_playback_plugin_data_to_activity_table() - OWNER TO "${process.env.POSTGRES_USER ?? postgres}";`); + OWNER TO "${process.env.POSTGRES_ROLE}";`); } catch (error) { console.error(error); } diff --git a/backend/server.js b/backend/server.js index 00c7874..baa7a2e 100644 --- a/backend/server.js +++ b/backend/server.js @@ -34,6 +34,10 @@ const tasks = require("./tasks/tasks"); const { setupWebSocketServer } = require("./ws"); const writeEnvVariables = require("./classes/env"); +process.env.POSTGRES_USER = process.env.POSTGRES_USER ?? "postgres"; +process.env.POSTGRES_ROLE = + process.env.POSTGRES_ROLE ?? process.env.POSTGRES_USER; + const app = express(); const db = knex(knexConfig.development); @@ -202,7 +206,9 @@ async function authenticate(req, res, next) { } } else { if (apiKey) { - const keysjson = await dbInstance.query('SELECT api_keys FROM app_config where "ID"=1').then((res) => res.rows[0].api_keys); + const keysjson = await dbInstance + .query('SELECT api_keys FROM app_config where "ID"=1') + .then((res) => res.rows[0].api_keys); if (!keysjson || Object.keys(keysjson).length === 0) { return res.status(404).json({ message: "No API keys configured" });