fix(core): Support MySQL in MoveSshKeysToDatabase migration (#9120)

This commit is contained in:
Iván Ovejero 2024-04-11 11:00:20 +02:00 committed by GitHub
parent 284de5d6c7
commit cf435c3311
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -36,9 +36,11 @@ export class MoveSshKeysToDatabase1711390882123 implements ReversibleMigration {
} }
const settings = escape.tableName('settings'); const settings = escape.tableName('settings');
const key = escape.columnName('key');
const value = escape.columnName('value');
const rows: Array<{ value: string }> = await runQuery( const rows: Array<{ value: string }> = await runQuery(
`SELECT value FROM ${settings} WHERE key = '${this.settingsKey}';`, `SELECT value FROM ${settings} WHERE ${key} = '${this.settingsKey}';`,
); );
if (rows.length === 1) { if (rows.length === 1) {
@ -51,13 +53,13 @@ export class MoveSshKeysToDatabase1711390882123 implements ReversibleMigration {
return; return;
} }
const value = JSON.stringify({ const settingsValue = JSON.stringify({
encryptedPrivateKey: this.cipher.encrypt(privateKey), encryptedPrivateKey: this.cipher.encrypt(privateKey),
publicKey, publicKey,
}); });
await runQuery( await runQuery(
`INSERT INTO ${settings} (key, value) VALUES ('${this.settingsKey}', '${value}');`, `INSERT INTO ${settings} (${key}, ${value}) VALUES ('${this.settingsKey}', '${settingsValue}');`,
); );
try { try {
@ -72,9 +74,10 @@ export class MoveSshKeysToDatabase1711390882123 implements ReversibleMigration {
async down({ escape, runQuery, logger, migrationName }: MigrationContext) { async down({ escape, runQuery, logger, migrationName }: MigrationContext) {
const settings = escape.tableName('settings'); const settings = escape.tableName('settings');
const key = escape.columnName('key');
const rows: Array<{ value: string }> = await runQuery( const rows: Array<{ value: string }> = await runQuery(
`SELECT value FROM ${settings} WHERE key = '${this.settingsKey}';`, `SELECT value FROM ${settings} WHERE ${key} = '${this.settingsKey}';`,
); );
if (rows.length !== 1) { if (rows.length !== 1) {
@ -106,6 +109,6 @@ export class MoveSshKeysToDatabase1711390882123 implements ReversibleMigration {
return; return;
} }
await runQuery(`DELETE ${settings} WHERE WHERE key = 'features.sourceControl.sshKeys';`); await runQuery(`DELETE FROM ${settings} WHERE ${key} = 'features.sourceControl.sshKeys';`);
} }
} }