Skip to content

Commit

Permalink
Update table import in table-initialization.ts
Browse files Browse the repository at this point in the history
  • Loading branch information
DenisCarriere committed Feb 17, 2024
1 parent ebfd095 commit 776116e
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 21 deletions.
2 changes: 1 addition & 1 deletion src/clickhouse/table-initialization.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { logger } from "../logger.js";
import { Err, Ok, Result } from "../result.js";
import client from "./createClient.js";
import { augmentCreateTableStatement, getTableName, isCreateTableStatement } from "./table-utils.js";
import tables from "./tables/index.js";
import tables from "./tables/tables.js";

export async function initializeDefaultTables(): Promise<Result> {
const promiseResults = await Promise.allSettled(
Expand Down
3 changes: 2 additions & 1 deletion src/clickhouse/tables/blocks.sql
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
-- blocks --
CREATE TABLE IF NOT EXISTS blocks (
block_id FixedString(64),
block_number UInt32(),
Expand All @@ -6,4 +7,4 @@ CREATE TABLE IF NOT EXISTS blocks (
)
ENGINE = ReplacingMergeTree
PRIMARY KEY (block_id)
ORDER BY (block_id, chain, block_number, timestamp);
ORDER BY (block_id, chain, block_number, timestamp);
22 changes: 22 additions & 0 deletions src/clickhouse/tables/blocks_mv.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
-- view --
CREATE MATERIALIZED VIEW IF NOT EXISTS blocks_mv
ENGINE = MergeTree
ORDER BY (chain, timestamp, block_number)
AS SELECT
block_id,
block_number,
chain,
timestamp
FROM blocks;

-- DROP TABLE IF EXISTS blocks_mv;

-- OPTIMIZE TABLE blocks_mv FINAL;

-- -- insert --
-- INSERT INTO blocks_mv SELECT
-- block_id,
-- block_number,
-- chain,
-- timestamp
-- FROM blocks;
19 changes: 0 additions & 19 deletions src/clickhouse/tables/index.ts

This file was deleted.

14 changes: 14 additions & 0 deletions src/clickhouse/tables/tables.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { join } from "path";

function file(path: string) {
return Bun.file(join(import.meta.dirname, path)).text();
}

const glob = new Bun.Glob("**/*.sql");
const tables: [string, string][] = [];

for (const path of glob.scanSync(import.meta.dirname)) {
tables.push([path.replace(".sql", ""), await file(path)])
}

export default tables;

0 comments on commit 776116e

Please sign in to comment.