mirror of
https://github.com/IT4Change/gradido.git
synced 2026-02-06 09:56:05 +00:00
fixed migration
This commit is contained in:
parent
bd384a75bf
commit
8688385a6f
@ -7,23 +7,36 @@
|
||||
/* eslint-disable @typescript-eslint/no-explicit-any */
|
||||
|
||||
export async function upgrade(queryFn: (query: string, values?: any[]) => Promise<Array<any>>) {
|
||||
// federated communities
|
||||
await queryFn('DROP INDEX `public_api_key` ON `federated_communities`;')
|
||||
await queryFn('UPDATE `federated_communities` SET `public_key` = UNHEX(public_key);')
|
||||
try {
|
||||
await queryFn(
|
||||
'ALTER TABLE `federated_communities` MODIFY COLUMN `public_key` binary(32) NOT NULL;',
|
||||
)
|
||||
await queryFn('ALTER TABLE `communities` MODIFY COLUMN `public_key` binary(32) NOT NULL;')
|
||||
} catch(e){
|
||||
console.log(e)
|
||||
}
|
||||
await queryFn(
|
||||
'ALTER TABLE `federated_communities` ADD COLUMN `public_key_new` binary(32) NOT NULL AFTER `public_key`;',
|
||||
)
|
||||
await queryFn('UPDATE `federated_communities` SET public_key_new = substring(public_key,1,32);')
|
||||
await queryFn('ALTER TABLE `federated_communities` DROP COLUMN public_key;')
|
||||
await queryFn('ALTER TABLE `federated_communities` RENAME COLUMN public_key_new TO public_key;')
|
||||
await queryFn(
|
||||
'ALTER TABLE `federated_communities` ADD CONSTRAINT `public_api_key` UNIQUE (public_key, api_version);',
|
||||
)
|
||||
|
||||
// communities
|
||||
await queryFn(
|
||||
'ALTER TABLE `communities` ADD COLUMN `public_key_new` binary(32) NOT NULL AFTER `public_key`;',
|
||||
)
|
||||
await queryFn('UPDATE `communities` SET public_key_new = substring(public_key,1,32);')
|
||||
await queryFn('ALTER TABLE `communities` DROP COLUMN public_key;')
|
||||
await queryFn('ALTER TABLE `communities` RENAME COLUMN public_key_new TO public_key;')
|
||||
}
|
||||
|
||||
export async function downgrade(queryFn: (query: string, values?: any[]) => Promise<Array<any>>) {
|
||||
await queryFn(
|
||||
'ALTER TABLE `federated_communities` MODIFY COLUMN `public_key` binary(64) NOT NULL;',
|
||||
)
|
||||
await queryFn('UPDATE `federated_communities` SET `public_key` = HEX(public_key);')
|
||||
await queryFn(
|
||||
'UPDATE `federated_communities` SET `public_key` = substring(HEX(public_key),1,64);',
|
||||
)
|
||||
await queryFn(
|
||||
'ALTER TABLE `communities` MODIFY COLUMN `public_key` binary(64) NULL DEFAULT NULL;',
|
||||
)
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user