app-backend: non-nullable assets store namespace, default to default instead

Signed-off-by: Patrik Oldsberg <poldsberg@gmail.com>
This commit is contained in:
Patrik Oldsberg
2024-04-14 12:02:41 +02:00
parent ef4655546d
commit cae72e6cdb
2 changed files with 10 additions and 4 deletions
@@ -22,7 +22,10 @@
exports.up = async function up(knex) {
await knex.schema.alterTable('static_assets_cache', table => {
// The namespace is used to allow operations on asset groups, e.g. delete all assets in a namespace
table.string('namespace').comment('The namespace of the file');
table
.string('namespace')
.defaultTo('default')
.comment('The namespace of the file');
table.dropPrimary();
table.primary(['namespace', 'path']);
});
@@ -32,7 +35,10 @@ exports.up = async function up(knex) {
* @param {import('knex').Knex} knex
*/
exports.down = async function down(knex) {
await knex.delete().from('static_assets_cache').whereNotNull('namespace');
await knex
.delete()
.from('static_assets_cache')
.whereNot('namespace', 'default');
await knex.schema.alterTable('static_assets_cache', table => {
table.dropPrimary();
@@ -50,7 +50,7 @@ export interface StaticAssetsStoreOptions {
export class StaticAssetsStore implements StaticAssetProvider {
#db: Knex;
#logger: Logger;
#namespace: string | null;
#namespace: string;
static async create(options: StaticAssetsStoreOptions) {
const { database } = options;
@@ -68,7 +68,7 @@ export class StaticAssetsStore implements StaticAssetProvider {
private constructor(client: Knex, logger: Logger, namespace?: string) {
this.#db = client;
this.#logger = logger;
this.#namespace = namespace ?? null;
this.#namespace = namespace ?? 'default';
}
/**