mirror of
https://github.com/BreizhHardware/Jellystat.git
synced 2026-01-18 16:27:20 +01:00
Merge pull request #250 from halkeye/allow-tables-roles
Allow overriding owner of tables during migrations
This commit is contained in:
@@ -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 = {
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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 @@
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -59,4 +59,4 @@ exports.up = async function(knex) {
|
||||
exports.down = async function(knex) {
|
||||
await knex.raw(`DROP VIEW jf_all_user_activity;`);
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -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);
|
||||
`);
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -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);
|
||||
`);
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -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)');
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -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)');
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -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);`);
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -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);`);
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -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);
|
||||
`);
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -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);
|
||||
});
|
||||
|
||||
@@ -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);
|
||||
});
|
||||
|
||||
@@ -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);
|
||||
});
|
||||
|
||||
@@ -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);
|
||||
});
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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}";
|
||||
`);
|
||||
};
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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" });
|
||||
|
||||
Reference in New Issue
Block a user