Skip to content

Commit

Permalink
fix: SQLite Directory Selection to Prefer Config Directory (#995)
Browse files Browse the repository at this point in the history
* fix: Prefer config.database.directory for SQLite directory if available

- Updated SQLite directory selection to use config.database.directory if provided.

* add test and use ternary

* changeset

---------

Co-authored-by: typedarray <[email protected]>
  • Loading branch information
erensanlier and 0xOlias authored Jul 24, 2024
1 parent 99b3a20 commit 44f7bbc
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/metal-apes-care.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@ponder/core": patch
---

Fixed a bug where the SQLite `directory` option in `ponder.config.ts` was not respected.
21 changes: 21 additions & 0 deletions packages/core/src/build/configAndIndexingFunctions.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -640,6 +640,27 @@ test("buildConfigAndIndexingFunctions() database uses sqlite by default", async
process.env.DATABASE_URL = prev;
});

test("buildConfigAndIndexingFunctions() database respects custom sqlite path", async () => {
const config = createConfig({
database: { kind: "sqlite", directory: "custom-sqlite/directory" },
networks: { mainnet: { chainId: 1, transport: http() } },
contracts: { a: { network: "mainnet", abi: [event0] } },
});

const { databaseConfig } = await buildConfigAndIndexingFunctions({
config,
rawIndexingFunctions: [{ name: "a:Event0", fn: () => {} }],
options,
});

console.log(databaseConfig);

expect(databaseConfig).toMatchObject({
kind: "sqlite",
directory: expect.stringContaining(path.join("custom-sqlite", "directory")),
});
});

test("buildConfigAndIndexingFunctions() database uses sqlite if specified even if DATABASE_URL env var present", async () => {
const config = createConfig({
database: { kind: "sqlite" },
Expand Down
7 changes: 6 additions & 1 deletion packages/core/src/build/configAndIndexingFunctions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,12 @@ export async function buildConfigAndIndexingFunctions({
// Build database.
let databaseConfig: DatabaseConfig;

const sqliteDir = path.join(ponderDir, "sqlite");
// Determine SQLite directory, preferring config.database.directory if available
const sqliteDir =
config.database?.kind === "sqlite" && config.database.directory
? path.resolve(config.database.directory)
: path.join(ponderDir, "sqlite");

const sqlitePrintPath = path.relative(rootDir, sqliteDir);

if (config.database?.kind) {
Expand Down

0 comments on commit 44f7bbc

Please sign in to comment.