-
Notifications
You must be signed in to change notification settings - Fork 286
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: Rafael Belchior <[email protected]> Signed-off-by: Yogesh01000100 <[email protected]>
- Loading branch information
1 parent
c625bbb
commit 9ed98cc
Showing
9 changed files
with
128 additions
and
32 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,35 @@ | ||
import path from "path"; | ||
import { v4 as uuidv4 } from "uuid"; | ||
import dotenv from "dotenv"; | ||
|
||
const envPath = process.env.ENV_PATH; | ||
dotenv.config({ path: envPath }); | ||
|
||
// default configuration for knex | ||
module.exports = { | ||
development: { | ||
client: "sqlite3", | ||
connection: { | ||
filename: path.resolve(__dirname, ".dev-" + uuidv4() + ".sqlite3"), | ||
filename: path.join(__dirname, "data", "/.dev-" + uuidv4() + ".sqlite3"), | ||
}, | ||
migrations: { | ||
directory: path.resolve(__dirname, "migrations"), | ||
}, | ||
seeds: { | ||
directory: path.resolve(__dirname, "seeds"), | ||
}, | ||
useNullAsDefault: true, | ||
}, | ||
production: { | ||
client: "pg", | ||
connection: { | ||
host: process.env.DB_HOST, | ||
port: process.env.DB_PORT, | ||
user: process.env.DB_USER, | ||
password: process.env.DB_PASSWORD, | ||
database: process.env.DB_NAME, | ||
}, | ||
migrations: { | ||
directory: path.resolve(__dirname, "migrations"), | ||
}, | ||
}, | ||
}; |
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" }), | ||
}); | ||
} |