added migration file

Signed-off-by: Manuel Scurti <manuel.scurti@agilelab.it>
This commit is contained in:
Manuel Scurti
2022-05-22 19:30:40 +02:00
parent 5e055079f0
commit 416014b7b8
3 changed files with 51 additions and 12 deletions
@@ -20,13 +20,6 @@
* @param {import('knex').Knex} knex
*/
exports.up = async function up(knex) {
/**
* key field length. must be enough for the chosen JWT signing algorithm.
* the default value is set to be enough for all supported algorithms of the
* `jose` library.
*/
const SIGNING_KEY_MAX_LENGTH = 512;
return knex.schema.createTable('signing_keys', table => {
table.comment(
'Signing keys that are currently in use or have recently been used to issue tokens',
@@ -41,10 +34,7 @@ exports.up = async function up(knex) {
.notNullable()
.defaultTo(knex.fn.now())
.comment('The creation time of the key');
table
.string('key', SIGNING_KEY_MAX_LENGTH)
.notNullable()
.comment('The serialized signing key');
table.string('key').notNullable().comment('The serialized signing key');
});
};
@@ -0,0 +1,49 @@
/*
* Copyright 2020 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) {
// Sqlite does not support alter column.
if (!knex.client.config.client.includes('sqlite3')) {
await knex.schema.alterTable('signing_keys', table => {
table
.text('key')
.notNullable()
.comment('The serialized signing key')
.alter({ alterType: true });
});
}
};
/**
* @param {import('knex').Knex} knex
*/
exports.down = async function down(knex) {
// Sqlite does not support alter column.
if (!knex.client.config.client.includes('sqlite3')) {
await knex.schema.alterTable('signing_keys', table => {
table
.string('key')
.notNullable()
.comment('The serialized signing key')
.alter({ alterType: true });
});
}
};
@@ -36,7 +36,7 @@ type Options = {
* Must match one of the algorithms defined for IdentityClient.
* When setting a different algorithm, check if the `key` field
* of the `signing_keys` table can fit the length of the generated keys.
* If not, modify the migration file in the migrations folder.
* If not, add a knex migration file in the migrations folder.
* More info on supported algorithms: https://github.com/panva/jose */
algorithm?: string;
};