database structure
This commit is contained in:
26
lib/snippets/database/patch_actions/RenameColumn.ts
Normal file
26
lib/snippets/database/patch_actions/RenameColumn.ts
Normal file
@ -0,0 +1,26 @@
|
||||
import { Serializable } from '../classes/Serializable';
|
||||
|
||||
export class RenameColumn implements Serializable {
|
||||
public column: string;
|
||||
public new_name: string;
|
||||
|
||||
public constructor (column: string, new_name = null) {
|
||||
if (new_name === null) {
|
||||
const regex = /(?<column>[a-z_]+) (?<new_name>[a-z_]+)/iu;
|
||||
const res = regex.exec (column);
|
||||
if (res === null || typeof res.groups === 'undefined')
|
||||
throw new Error ('invalid string to deserialize');
|
||||
|
||||
this.column = res.groups.column;
|
||||
this.new_name = res.groups.new_name;
|
||||
return;
|
||||
}
|
||||
|
||||
this.column = column;
|
||||
this.new_name = new_name as unknown as string;
|
||||
}
|
||||
|
||||
public serialize (): string {
|
||||
return `${this.column} ${this.new_name}`;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user