-
Notifications
You must be signed in to change notification settings - Fork 285
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(satp-hermes): improve DB management
Signed-off-by: Rafael Belchior <[email protected]>
- Loading branch information
1 parent
e027214
commit babc569
Showing
7 changed files
with
77 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 0 additions & 15 deletions
15
packages/cactus-plugin-satp-hermes/src/knex/migrations/20220331132128_create_logs_table.js
This file was deleted.
Oops, something went wrong.
16 changes: 16 additions & 0 deletions
16
packages/cactus-plugin-satp-hermes/src/knex/migrations/20220331132128_create_logs_table.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { Knex } from "knex"; | ||
|
||
export function up(knex: Knex): Knex.SchemaBuilder { | ||
return knex.schema.createTable("logs", (table) => { | ||
table.string("sessionID").notNullable(); | ||
table.string("type").notNullable(); | ||
table.string("key").notNullable().primary(); | ||
table.string("operation").notNullable(); | ||
table.string("timestamp").notNullable(); | ||
table.string("data").notNullable(); | ||
}); | ||
} | ||
|
||
export function down(knex: Knex): Knex.SchemaBuilder { | ||
return knex.schema.dropTable("logs"); | ||
} |
13 changes: 0 additions & 13 deletions
13
.../cactus-plugin-satp-hermes/src/knex/migrations/20240130234303_create_remote_logs_table.js
This file was deleted.
Oops, something went wrong.
14 changes: 14 additions & 0 deletions
14
.../cactus-plugin-satp-hermes/src/knex/migrations/20240130234303_create_remote_logs_table.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { Knex } from "knex"; | ||
|
||
export async function up(knex: Knex): Promise<void> { | ||
return knex.schema.createTable("remote-logs", (table) => { | ||
table.string("hash").notNullable(); | ||
table.string("signature").notNullable(); | ||
table.string("signerPubKey").notNullable(); | ||
table.string("key").notNullable().primary(); | ||
}); | ||
} | ||
|
||
export async function down(knex: Knex): Promise<void> { | ||
return knex.schema.dropTable("remote-logs"); | ||
} |
35 changes: 35 additions & 0 deletions
35
packages/cactus-plugin-satp-hermes/src/knex/seeds/1724235145_create_dummy_entries.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
// 20240821000000_seed_dev_logs.ts | ||
|
||
import { Knex } from "knex"; | ||
|
||
export async function seed(knex: Knex): Promise<void> { | ||
// Check if we're in the development environment | ||
if (process.env.NODE_ENV !== "development") { | ||
console.log("Skipping seed: Not in development environment"); | ||
return; | ||
} | ||
|
||
// Function to clear table if it exists | ||
async function clearTableIfExists(tableName: string) { | ||
if (await knex.schema.hasTable(tableName)) { | ||
await knex(tableName).del(); | ||
console.log(`Cleared existing entries from ${tableName}`); | ||
} else { | ||
console.log(`Table ${tableName} does not exist, skipping clear`); | ||
} | ||
} | ||
|
||
// Clear existing entries if tables exist | ||
await clearTableIfExists("logs"); | ||
await clearTableIfExists("remote-logs"); | ||
|
||
// Insert a single deterministic log entry | ||
await knex("logs").insert({ | ||
sessionID: "test-session-001", | ||
type: "info", | ||
key: "test-log-001", | ||
operation: "create", | ||
timestamp: "2024-08-21T12:00:00Z", | ||
data: JSON.stringify({ message: "This is a test log entry" }), | ||
}); | ||
} |