From 6841660ba4ac6b93e94cde43acc925ffab49194c Mon Sep 17 00:00:00 2001 From: Patrik Oldsberg Date: Wed, 29 Dec 2021 12:01:46 +0100 Subject: [PATCH] app-backend: added initial db migration for asset cache Signed-off-by: Patrik Oldsberg --- .../migrations/20211229105307_init.js | 47 +++++++++++++++++++ plugins/app-backend/package.json | 2 + 2 files changed, 49 insertions(+) create mode 100644 plugins/app-backend/migrations/20211229105307_init.js diff --git a/plugins/app-backend/migrations/20211229105307_init.js b/plugins/app-backend/migrations/20211229105307_init.js new file mode 100644 index 0000000000..e44e58f539 --- /dev/null +++ b/plugins/app-backend/migrations/20211229105307_init.js @@ -0,0 +1,47 @@ +/* + * Copyright 2021 The Backstage Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// @ts-check + +/** + * @param {import('knex').Knex} knex + */ +exports.up = async function up(knex) { + return knex.schema.createTable('static_asset_cache', table => { + table.comment( + 'A cache of static assets that where previously deployed and may still be lazy-loaded by clients', + ); + table + .string('path') + .primary() + .notNullable() + .comment('The path of the file'); + table + .dateTime('last_modified_at') + .notNullable() + .comment( + 'Timestamp of when the asset was most recently seen in a deployment', + ); + table.binary('content').notNullable().comment('The asset content'); + }); +}; + +/** + * @param {import('knex').Knex} knex + */ +exports.down = async function down(knex) { + return knex.schema.dropTable('static_asset_cache'); +}; diff --git a/plugins/app-backend/package.json b/plugins/app-backend/package.json index d5cbe9c07d..e8cd4a4135 100644 --- a/plugins/app-backend/package.json +++ b/plugins/app-backend/package.json @@ -39,6 +39,7 @@ "express-promise-router": "^4.1.0", "fs-extra": "9.1.0", "helmet": "^4.0.0", + "knex": "^0.95.1", "winston": "^3.2.1", "yn": "^4.0.0" }, @@ -51,6 +52,7 @@ }, "files": [ "dist", + "migrations/**/*.{js,d.ts}", "static" ] }