fix(core): update

This commit is contained in:
Philipp Kunz 2022-07-27 23:11:03 +02:00
parent 87c3548f91
commit 3272b87e10
2 changed files with 29 additions and 24 deletions

View File

@ -3,6 +3,6 @@
*/
export const commitinfo = {
name: '@pushrocks/smartclickhouse',
version: '2.0.5',
version: '2.0.6',
description: 'an odm for talking to clickhouse'
}

View File

@ -38,29 +38,7 @@ export class TimeDataTable {
retainDataForDays: 30
});
// create table in clickhouse
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');
await newTable.setup();
return newTable;
}
@ -75,6 +53,32 @@ export class TimeDataTable {
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[] = [];
/**
@ -174,6 +178,7 @@ export class TimeDataTable {
console.log(`Ran into an error. Trying to set up things properly again.`);
await this.smartClickHouseDbRef.pingDatabaseUntilAvailable();
await this.smartClickHouseDbRef.createDatabase();
await this.setup();
this.columns = [];
this.healingDeferred.resolve();
this.healingDeferred = null;