Merge pull request #813 from spotify/freben/inventory_move_migrations

Move inventory migrations into the plugin itself
This commit is contained in:
Fredrik Adelöw
2020-05-12 10:40:57 +02:00
committed by GitHub
6 changed files with 24 additions and 50 deletions
@@ -15,11 +15,21 @@
*/
import { NotFoundError } from '@backstage/backend-common';
import path from 'path';
import Knex from 'knex';
import { v4 as uuidv4 } from 'uuid';
import { AddLocationRequest, Component, Inventory, Location } from './types';
export class DatabaseInventory implements Inventory {
static async create(database: Knex): Promise<DatabaseInventory> {
await database.migrate.latest({
directory: path.resolve(__dirname, '..', 'migrations'),
loadExtensions: ['.js'],
});
return new DatabaseInventory(database);
}
constructor(private readonly database: Knex) {}
async components(): Promise<Component[]> {
@@ -0,0 +1,45 @@
/*
* Copyright 2020 Spotify AB
*
* 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 * as Knex from 'knex';
export async function up(knex: Knex): Promise<any> {
return knex.schema
.createTable('locations', table => {
table
.uuid('id')
.primary()
.comment('Auto-generated ID of the location');
table
.string('type')
.notNullable()
.comment('The type of location');
table
.string('target')
.notNullable()
.comment('The actual target of the location');
})
.createTable('components', table => {
table
.string('name')
.primary()
.comment('The name of the component');
});
}
export async function down(knex: Knex): Promise<any> {
return knex.schema.dropTable('components').dropTable('locations');
}