Compare commits
4 Commits
214b113865
...
dev
Author | SHA1 | Date | |
---|---|---|---|
ba16c60168 | |||
46be34c4b0 | |||
3e773b5327 | |||
146c9b661f |
@ -1,20 +0,0 @@
|
||||
/*
|
||||
* 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 <timo@scode.ovh>, May 2020
|
||||
*/
|
||||
|
||||
import { ColumnType } from './ColumnType';
|
||||
import { Relation } from './Relation';
|
||||
|
||||
export class Column {
|
||||
public name: string;
|
||||
public type: ColumnType;
|
||||
public relation?: Relation;
|
||||
|
||||
public constructor (name: string, type: ColumnType) {
|
||||
this.name = name;
|
||||
this.type = type;
|
||||
}
|
||||
}
|
@ -1,27 +0,0 @@
|
||||
/*
|
||||
* 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 <timo@scode.ovh>, May 2020
|
||||
*/
|
||||
|
||||
export enum ColumnType {
|
||||
string = 'string',
|
||||
text = 'text',
|
||||
integer = 'integer',
|
||||
big_integer = 'bigInteger',
|
||||
float = 'float',
|
||||
decimal = 'decimal',
|
||||
increments = 'increments',
|
||||
big_increments = 'bigIncrements',
|
||||
boolean = 'boolean',
|
||||
date = 'date',
|
||||
date_time ='datetime',
|
||||
time = 'time',
|
||||
timestamp = 'timestamp',
|
||||
binary = 'binary',
|
||||
enum = 'enu',
|
||||
json='json',
|
||||
jsonb='jsonb',
|
||||
uuid='uuid'
|
||||
}
|
@ -1,21 +0,0 @@
|
||||
/*
|
||||
* 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 <timo@scode.ovh>, May 2020
|
||||
*/
|
||||
|
||||
import { Table } from './Table';
|
||||
|
||||
export class Database {
|
||||
public tables: Array<Table> = [];
|
||||
|
||||
public get_table (name: string): Table|null {
|
||||
for (const table of this.tables) {
|
||||
if (table.name === name)
|
||||
return table;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
@ -1,12 +0,0 @@
|
||||
/*
|
||||
* 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 <timo@scode.ovh>, May 2020
|
||||
*/
|
||||
|
||||
import { Database } from './Database';
|
||||
|
||||
export interface PatchAction {
|
||||
apply(db: Database): void;
|
||||
}
|
@ -1,22 +0,0 @@
|
||||
/*
|
||||
* 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 <timo@scode.ovh>, May 2020
|
||||
*/
|
||||
|
||||
export enum PatchActions {
|
||||
rename_column = 'rc',
|
||||
add_column = 'ac',
|
||||
drop_column = 'dc',
|
||||
add_relation = 'ar',
|
||||
drop_relation = 'dr',
|
||||
set_column_type = 'tc',
|
||||
add_table = 'at',
|
||||
drop_table = 'dt',
|
||||
rename_table = 'rt',
|
||||
insert_data = 'id',
|
||||
update_data = 'ud',
|
||||
mutate_data = 'md',
|
||||
delete_data = 'dd'
|
||||
}
|
@ -1,16 +0,0 @@
|
||||
/*
|
||||
* 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 <timo@scode.ovh>, May 2020
|
||||
*/
|
||||
|
||||
export class Relation {
|
||||
public column: string;
|
||||
public table: string;
|
||||
|
||||
public constructor (table: string, column: string) {
|
||||
this.column = column;
|
||||
this.table = table;
|
||||
}
|
||||
}
|
@ -1,10 +0,0 @@
|
||||
/*
|
||||
* 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 <timo@scode.ovh>, May 2020
|
||||
*/
|
||||
|
||||
export interface Serializable {
|
||||
serialize(): string;
|
||||
}
|
@ -1,26 +0,0 @@
|
||||
/*
|
||||
* 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 <timo@scode.ovh>, May 2020
|
||||
*/
|
||||
|
||||
import { Column } from './Column';
|
||||
|
||||
export class Table {
|
||||
public name: string;
|
||||
public columns: Array<Column> = [];
|
||||
|
||||
public constructor (name: string) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public get_column (name: string): Column|null {
|
||||
for (const col of this.columns) {
|
||||
if (col.name === name)
|
||||
return col;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
@ -1,18 +0,0 @@
|
||||
/*
|
||||
* 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 <timo@scode.ovh>, May 2020
|
||||
*/
|
||||
|
||||
import { Snippet } from '../../Snippet';
|
||||
|
||||
export default class Database implements Snippet {
|
||||
public is_active (): boolean {
|
||||
return false;
|
||||
}
|
||||
|
||||
public start (): Promise<void> {
|
||||
return Promise.resolve ();
|
||||
}
|
||||
}
|
@ -1,60 +0,0 @@
|
||||
/*
|
||||
* 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 <timo@scode.ovh>, May 2020
|
||||
*/
|
||||
|
||||
import { Serializable } from '../classes/Serializable';
|
||||
import { PatchAction } from '../classes/PatchAction';
|
||||
import { Database } from '../classes/Database';
|
||||
|
||||
export class RenameColumn implements Serializable, PatchAction {
|
||||
public table: string;
|
||||
public column: string;
|
||||
public new_name: string;
|
||||
|
||||
public constructor (
|
||||
column: string,
|
||||
new_name: string|null = null,
|
||||
table: string|null = null
|
||||
) {
|
||||
if (new_name === null || table === null) {
|
||||
const regex
|
||||
= /(?<table>[a-z_]+) (?<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;
|
||||
this.table = res.groups.table;
|
||||
return;
|
||||
}
|
||||
|
||||
this.column = column;
|
||||
this.table = table;
|
||||
this.new_name = new_name;
|
||||
}
|
||||
|
||||
public serialize (): string {
|
||||
return `${this.table} ${this.column} ${this.new_name}`;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
@ -31,6 +31,8 @@
|
||||
"typescript": "^3.8.3"
|
||||
},
|
||||
"dependencies": {
|
||||
"@sapphirecode/console-app": "^2.0.6",
|
||||
"@sapphirecode/modelling": "^1.1.6",
|
||||
"@sapphirecode/standard": "^1.0.1",
|
||||
"enquirer": "^2.3.5",
|
||||
"fs-extra": "^9.0.0",
|
||||
|
36
yarn.lock
36
yarn.lock
@ -43,6 +43,18 @@
|
||||
resolved "https://registry.yarnpkg.com/@ovyerus/licenses/-/licenses-6.4.4.tgz#596e3ace46ab7c70bcf0e2b17f259796a4bedf9f"
|
||||
integrity sha512-IHjc31WXciQT3hfvdY+M59jBkQp70Fpr04tNDVO5rez2PNv4u8tE6w//CkU+GeBoO9k2ahneSqzjzvlgjyjkGw==
|
||||
|
||||
"@sapphirecode/console-app@^2.0.6":
|
||||
version "2.0.6"
|
||||
resolved "https://registry.yarnpkg.com/@sapphirecode/console-app/-/console-app-2.0.6.tgz#5034a2beddd9d0cb5f29e5b9ffff4c36cc647b31"
|
||||
integrity sha512-dceIFY+hTMzCXpPH2ZIy+zVA7qwt1N7maNL9RjnkZNIoiJicyPnnkF3W8JHubh/i00ejzepXoBf6gJEgDeHclw==
|
||||
dependencies:
|
||||
"@sapphirecode/modelling" "^1.0.35"
|
||||
"@sapphirecode/utilities" "^1.3.4"
|
||||
enquirer "^2.3.5"
|
||||
fs-extra "^9.0.0"
|
||||
hjson "^3.2.1"
|
||||
yargs "^15.3.1"
|
||||
|
||||
"@sapphirecode/eslint-config-es6@^1.1.1":
|
||||
version "1.1.12"
|
||||
resolved "https://registry.yarnpkg.com/@sapphirecode/eslint-config-es6/-/eslint-config-es6-1.1.12.tgz#cc38dcbf59c450ac09d8042f3d69cd784005aec9"
|
||||
@ -69,11 +81,30 @@
|
||||
eslint-plugin-node "^11.1.0"
|
||||
eslint-plugin-sort-requires-by-path "^1.0.2"
|
||||
|
||||
"@sapphirecode/modelling@^1.0.35":
|
||||
version "1.1.5"
|
||||
resolved "https://registry.yarnpkg.com/@sapphirecode/modelling/-/modelling-1.1.5.tgz#71b1ec6a8938ad4e8a3ea13bd6bd9d54eaabedcd"
|
||||
integrity sha512-5MkawJexd0FzcFDlD+bt/mmNuwtjRyMqntHHKpieov2pU4HJxJoQL1k5gnrDmKittXZsl2OOweNi/Xa2cYxmCA==
|
||||
dependencies:
|
||||
"@sapphirecode/utilities" "^1.3.2"
|
||||
|
||||
"@sapphirecode/modelling@^1.1.6":
|
||||
version "1.1.6"
|
||||
resolved "https://registry.yarnpkg.com/@sapphirecode/modelling/-/modelling-1.1.6.tgz#84b1b760e07a8fa3da326b7b973b23f52e149a0e"
|
||||
integrity sha512-WxuMUNHtcC0wbPXtgzi5JX1mjFZbmoWpwCP3iICja3K6ecu4ptk7npnDM3klL+kThq9CMWAIffOheo4y5b4Cgg==
|
||||
dependencies:
|
||||
"@sapphirecode/utilities" "^1.3.2"
|
||||
|
||||
"@sapphirecode/standard@^1.0.1":
|
||||
version "1.1.8"
|
||||
resolved "https://registry.yarnpkg.com/@sapphirecode/standard/-/standard-1.1.8.tgz#07c48ea91c7d1555d0110419d5eeeb6f2d11b246"
|
||||
integrity sha512-O3dO6fujxlnR/7DoRpLB5NtTG4FMnRgDN0574rAT9oaUsL2rf3rpinlyeB2V36C8wtpihbcAw7zA5FSEPO3sdw==
|
||||
|
||||
"@sapphirecode/utilities@^1.3.2", "@sapphirecode/utilities@^1.3.4":
|
||||
version "1.5.1"
|
||||
resolved "https://registry.yarnpkg.com/@sapphirecode/utilities/-/utilities-1.5.1.tgz#d7e5a3791aa558bf968bb201ab3cc34b60d3e650"
|
||||
integrity sha512-CU19QMj6WjUuup5mpKK6QOY/NROIUBpoQ1pOokmD7J3wd7NND9xntU9bnzSxrPc5OfhqY5r+S30+hdrEsoAXbA==
|
||||
|
||||
"@types/color-name@^1.1.1":
|
||||
version "1.1.1"
|
||||
resolved "https://registry.yarnpkg.com/@types/color-name/-/color-name-1.1.1.tgz#1c1261bbeaa10a8055bbc5d8ab84b7b2afc846a0"
|
||||
@ -789,6 +820,11 @@ has@^1.0.3:
|
||||
dependencies:
|
||||
function-bind "^1.1.1"
|
||||
|
||||
hjson@^3.2.1:
|
||||
version "3.2.1"
|
||||
resolved "https://registry.yarnpkg.com/hjson/-/hjson-3.2.1.tgz#20de41dc87fc9a10d1557d0230b0e02afb1b09ac"
|
||||
integrity sha512-OhhrFMeC7dVuA1xvxuXGTv/yTdhTvbe8hz+3LgVNsfi9+vgz0sF/RrkuX8eegpKaMc9cwYwydImBH6iePoJtdQ==
|
||||
|
||||
hosted-git-info@^2.1.4:
|
||||
version "2.8.8"
|
||||
resolved "https://registry.yarnpkg.com/hosted-git-info/-/hosted-git-info-2.8.8.tgz#7539bd4bc1e0e0a895815a2e0262420b12858488"
|
||||
|
Reference in New Issue
Block a user