fix(core): update
This commit is contained in:
parent
87c3548f91
commit
3272b87e10
@ -3,6 +3,6 @@
|
|||||||
*/
|
*/
|
||||||
export const commitinfo = {
|
export const commitinfo = {
|
||||||
name: '@pushrocks/smartclickhouse',
|
name: '@pushrocks/smartclickhouse',
|
||||||
version: '2.0.5',
|
version: '2.0.6',
|
||||||
description: 'an odm for talking to clickhouse'
|
description: 'an odm for talking to clickhouse'
|
||||||
}
|
}
|
||||||
|
@ -38,29 +38,7 @@ export class TimeDataTable {
|
|||||||
retainDataForDays: 30
|
retainDataForDays: 30
|
||||||
});
|
});
|
||||||
|
|
||||||
// create table in clickhouse
|
await newTable.setup();
|
||||||
await smartClickHouseDbRefArg.clickhouseClient
|
|
||||||
.queryPromise(`
|
|
||||||
CREATE TABLE IF NOT EXISTS ${newTable.options.tableName} (
|
|
||||||
timestamp DateTime64(3, 'Europe/Berlin'),
|
|
||||||
message String
|
|
||||||
) ENGINE=MergeTree() ORDER BY timestamp`);
|
|
||||||
|
|
||||||
// lets adjust the TTL
|
|
||||||
await smartClickHouseDbRefArg.clickhouseClient
|
|
||||||
.queryPromise(`
|
|
||||||
ALTER TABLE ${newTable.options.tableName} MODIFY TTL toDateTime(timestamp) + INTERVAL ${newTable.options.retainDataForDays} DAY
|
|
||||||
`);
|
|
||||||
|
|
||||||
await newTable.updateColumns();
|
|
||||||
console.log(`=======================`)
|
|
||||||
console.log(
|
|
||||||
`table with name "${newTable.options.tableName}" in databse ${newTable.smartClickHouseDbRef.options.database} has the following columns:`
|
|
||||||
);
|
|
||||||
for (const column of newTable.columns) {
|
|
||||||
console.log(`>> ${column.name}: ${column.type}`);
|
|
||||||
}
|
|
||||||
console.log('^^^^^^^^^^^^^^\n');
|
|
||||||
|
|
||||||
return newTable;
|
return newTable;
|
||||||
}
|
}
|
||||||
@ -75,6 +53,32 @@ export class TimeDataTable {
|
|||||||
this.options = optionsArg;
|
this.options = optionsArg;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async setup() {
|
||||||
|
// create table in clickhouse
|
||||||
|
await this.smartClickHouseDbRef.clickhouseClient
|
||||||
|
.queryPromise(`
|
||||||
|
CREATE TABLE IF NOT EXISTS ${this.options.tableName} (
|
||||||
|
timestamp DateTime64(3, 'Europe/Berlin'),
|
||||||
|
message String
|
||||||
|
) ENGINE=MergeTree() ORDER BY timestamp`);
|
||||||
|
|
||||||
|
// lets adjust the TTL
|
||||||
|
await this.smartClickHouseDbRef.clickhouseClient
|
||||||
|
.queryPromise(`
|
||||||
|
ALTER TABLE ${this.options.tableName} MODIFY TTL toDateTime(timestamp) + INTERVAL ${this.options.retainDataForDays} DAY
|
||||||
|
`);
|
||||||
|
|
||||||
|
await this.updateColumns();
|
||||||
|
console.log(`=======================`)
|
||||||
|
console.log(
|
||||||
|
`table with name "${this.options.tableName}" in database ${this.smartClickHouseDbRef.options.database} has the following columns:`
|
||||||
|
);
|
||||||
|
for (const column of this.columns) {
|
||||||
|
console.log(`>> ${column.name}: ${column.type}`);
|
||||||
|
}
|
||||||
|
console.log('^^^^^^^^^^^^^^\n');
|
||||||
|
}
|
||||||
|
|
||||||
public columns: IColumnInfo[] = [];
|
public columns: IColumnInfo[] = [];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -174,6 +178,7 @@ export class TimeDataTable {
|
|||||||
console.log(`Ran into an error. Trying to set up things properly again.`);
|
console.log(`Ran into an error. Trying to set up things properly again.`);
|
||||||
await this.smartClickHouseDbRef.pingDatabaseUntilAvailable();
|
await this.smartClickHouseDbRef.pingDatabaseUntilAvailable();
|
||||||
await this.smartClickHouseDbRef.createDatabase();
|
await this.smartClickHouseDbRef.createDatabase();
|
||||||
|
await this.setup();
|
||||||
this.columns = [];
|
this.columns = [];
|
||||||
this.healingDeferred.resolve();
|
this.healingDeferred.resolve();
|
||||||
this.healingDeferred = null;
|
this.healingDeferred = null;
|
||||||
|
Loading…
Reference in New Issue
Block a user