From ad1225998fc712f33a5c50afdb0466337790f39d Mon Sep 17 00:00:00 2001 From: Ulf Gebhardt Date: Tue, 30 May 2023 10:59:47 +0200 Subject: [PATCH] created migration to correct public key length --- .../0067-community_table_public_key_length.ts | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 database/migrations/0067-community_table_public_key_length.ts diff --git a/database/migrations/0067-community_table_public_key_length.ts b/database/migrations/0067-community_table_public_key_length.ts new file mode 100644 index 000000000..b51a1e6e0 --- /dev/null +++ b/database/migrations/0067-community_table_public_key_length.ts @@ -0,0 +1,23 @@ +/* MIGRATION TO CORRECT THE PUBLIC KEY LENGTHS + * + * This migration corrects the length of the saved public keys to 32 as this is the length it is generated for. + */ + +/* eslint-disable @typescript-eslint/explicit-module-boundary-types */ +/* eslint-disable @typescript-eslint/no-explicit-any */ + +export async function upgrade(queryFn: (query: string, values?: any[]) => Promise>) { + await queryFn('ALTER TABLE `communities` MODIFY COLUMN `public_key` binary(32) NOT NULL;') + // TODO: it is unclear if this is actually nullable - the model defines "default: null, nullable: true", but the table seems to be created without nullability(?) + await queryFn( + 'ALTER TABLE `federated_communities` MODIFY COLUMN `public_key` binary(32) NULL DEFAULT NULL;', + ) +} + +export async function downgrade(queryFn: (query: string, values?: any[]) => Promise>) { + await queryFn('ALTER TABLE `communities` MODIFY COLUMN `public_key` binary(64) NOT NULL;') + // TODO: see above + await queryFn( + 'ALTER TABLE `federated_communities` MODIFY COLUMN `public_key` binary(64) NULL DEFAULT NULL;', + ) +}