/* * Copyright (C) SapphireCode - All Rights Reserved * This file is part of Snippeteer which is released under BSD-3-Clause. * See file 'LICENSE' for full license details. * Created by Timo Hocker , May 2020 */ import { Persistent } from '@sapphirecode/modelling'; import { PatchAction } from '../classes/PatchAction'; import { Database } from '../classes/Database'; export class RenameColumn extends Persistent implements PatchAction { public get table (): string { return this.get ('table') as string; } public get column (): string { return this.get ('column') as string; } public get new_name (): string { return this.get ('new_name') as string; } public constructor ( column: string, new_name: string, table: string ) { super (); this.properties.column = 'string'; this.properties.table = 'string'; this.properties.new_name = 'string'; this.set ('column', column); this.set ('new_name', new_name); this.set ('table', table); } public apply (db: Database): void { const table = db.get_table (this.table); if (typeof table === 'undefined' || table === null) { throw new Error ( `table ${this.table} not found` ); } const column = table.get_column (this.column); if (typeof column === 'undefined' || column === null) { throw new Error ( `column ${this.column} not found in table ${this.table}` ); } column.name = this.new_name; } }