Merge remote-tracking branch 'upstream/master'
This commit is contained in:
+6
-6
@@ -1415,22 +1415,22 @@ __metadata:
|
||||
linkType: hard
|
||||
|
||||
"typescript@npm:^4.1.3":
|
||||
version: 4.9.3
|
||||
resolution: "typescript@npm:4.9.3"
|
||||
version: 4.9.4
|
||||
resolution: "typescript@npm:4.9.4"
|
||||
bin:
|
||||
tsc: bin/tsc
|
||||
tsserver: bin/tsserver
|
||||
checksum: 17b8f816050b412403e38d48eef0e893deb6be522d6dc7caf105e54a72e34daf6835c447735fd2b28b66784e72bfbf87f627abb4818a8e43d1fa8106396128dc
|
||||
checksum: e782fb9e0031cb258a80000f6c13530288c6d63f1177ed43f770533fdc15740d271554cdae86701c1dd2c83b082cea808b07e97fd68b38a172a83dbf9e0d0ef9
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"typescript@patch:typescript@^4.1.3#~builtin<compat/typescript>":
|
||||
version: 4.9.3
|
||||
resolution: "typescript@patch:typescript@npm%3A4.9.3#~builtin<compat/typescript>::version=4.9.3&hash=a1c5e5"
|
||||
version: 4.9.4
|
||||
resolution: "typescript@patch:typescript@npm%3A4.9.4#~builtin<compat/typescript>::version=4.9.4&hash=a1c5e5"
|
||||
bin:
|
||||
tsc: bin/tsc
|
||||
tsserver: bin/tsserver
|
||||
checksum: ef65c22622d864497d0a0c5db693523329b3284c15fe632e93ad9aa059e8dc38ef3bd767d6f26b1e5ecf9446f49bd0f6c4e5714a2eeaf352805dc002479843d1
|
||||
checksum: 37f6e2c3c5e2aa5934b85b0fddbf32eeac8b1bacf3a5b51d01946936d03f5377fe86255d4e5a4ae628fd0cd553386355ad362c57f13b4635064400f3e8e05b9d
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
|
||||
@@ -0,0 +1,103 @@
|
||||
/*
|
||||
* Copyright 2022 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.
|
||||
*/
|
||||
|
||||
import { Knex } from 'knex';
|
||||
import { TestDatabases } from '@backstage/backend-test-utils';
|
||||
import fs from 'fs';
|
||||
|
||||
const migrationsDir = `${__dirname}/../migrations`;
|
||||
const migrationsFiles = fs.readdirSync(migrationsDir).sort();
|
||||
|
||||
async function migrateUpOnce(knex: Knex): Promise<void> {
|
||||
await knex.migrate.up({ directory: migrationsDir });
|
||||
}
|
||||
|
||||
async function migrateDownOnce(knex: Knex): Promise<void> {
|
||||
await knex.migrate.down({ directory: migrationsDir });
|
||||
}
|
||||
|
||||
async function migrateUntilBefore(knex: Knex, target: string): Promise<void> {
|
||||
const index = migrationsFiles.indexOf(target);
|
||||
if (index === -1) {
|
||||
throw new Error(`Migration ${target} not found`);
|
||||
}
|
||||
for (let i = 0; i < index; i++) {
|
||||
await migrateUpOnce(knex);
|
||||
}
|
||||
}
|
||||
|
||||
describe('migrations', () => {
|
||||
const databases = TestDatabases.create({
|
||||
ids: ['MYSQL_8', 'POSTGRES_13', 'POSTGRES_9', 'SQLITE_3'],
|
||||
});
|
||||
|
||||
it.each(databases.eachSupportedId())(
|
||||
'20221109192547_search_add_original_value_column.js, %p',
|
||||
async databaseId => {
|
||||
const knex = await databases.init(databaseId);
|
||||
|
||||
await migrateUntilBefore(
|
||||
knex,
|
||||
'20221109192547_search_add_original_value_column.js',
|
||||
);
|
||||
|
||||
await knex
|
||||
.insert({
|
||||
entity_id: 'i',
|
||||
entity_ref: 'k:ns/n',
|
||||
unprocessed_entity: '{}',
|
||||
errors: '[]',
|
||||
next_update_at: new Date(),
|
||||
last_discovery_at: new Date(),
|
||||
})
|
||||
.into('refresh_state');
|
||||
await knex
|
||||
.insert({ entity_id: 'i', key: 'k1', value: 'v1' })
|
||||
.into('search');
|
||||
await knex
|
||||
.insert({ entity_id: 'i', key: 'k2', value: null })
|
||||
.into('search');
|
||||
|
||||
await expect(knex('search')).resolves.toEqual(
|
||||
expect.arrayContaining([
|
||||
{ entity_id: 'i', key: 'k1', value: 'v1' },
|
||||
{ entity_id: 'i', key: 'k2', value: null },
|
||||
]),
|
||||
);
|
||||
|
||||
await migrateUpOnce(knex);
|
||||
|
||||
await expect(knex('search')).resolves.toEqual(
|
||||
expect.arrayContaining([
|
||||
{ entity_id: 'i', key: 'k1', value: 'v1', original_value: 'v1' },
|
||||
{ entity_id: 'i', key: 'k2', value: null, original_value: null },
|
||||
]),
|
||||
);
|
||||
|
||||
await migrateDownOnce(knex);
|
||||
|
||||
await expect(knex('search')).resolves.toEqual(
|
||||
expect.arrayContaining([
|
||||
{ entity_id: 'i', key: 'k1', value: 'v1' },
|
||||
{ entity_id: 'i', key: 'k2', value: null },
|
||||
]),
|
||||
);
|
||||
|
||||
await knex.destroy();
|
||||
},
|
||||
60_000,
|
||||
);
|
||||
});
|
||||
Reference in New Issue
Block a user