Skip to content
This repository has been archived by the owner on Feb 26, 2024. It is now read-only.

@truffle/db Option to save .db directory to project directory #4503

Closed
wants to merge 9 commits into from
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,6 @@ packages/debugger/.tmp

# @truffle/contract
packages/contract/dist

# @truffle/db
**/*.db
tenthirtyone marked this conversation as resolved.
Show resolved Hide resolved
9 changes: 9 additions & 0 deletions packages/db/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ system that can keep track of multiple contracts in this situation.
## Built With

Truffle DB is built with:

- TypeScript
- GraphQL
- Apollo
Expand All @@ -36,9 +37,17 @@ db: {
enabled: true
}
```

Note: Enabling Truffle DB does not affect artifacts, but will produce a new `.db`
directory when you compile or migrate your project.

Add the following to your user truffle config (`~/.config/truffle-nodejs/config.json`) to enable saving the `.db` directory to your project directory
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So there's some infrastructure for doing this automatically via truffle config set <...>. I forget the exact syntax; @eggplantzzz or @cds-amal do you remember offhand?

In any event, we probably want to recommend that approach rather than forcing users to find this file and edit it manually - since the path differs based on OS (Mac will use ~/Library/Application\ Support/truffle-nodejs, for instance)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh fantastic.

I wasn't aware of the convenience command. I can probably drill down - packages/core/lib/commands/config.js (but wouldn't mind the exact syntax).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we need to do a separate PR to get this TODO addressed, and then rebase this once that's merged?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can jump over to tackle it since it's all connected.


```
db: {
saveToProjectRoot: true
}
```

It will soon be possible to load and access Truffle DB data via `truffle compile` and `truffle migrate`.
Stay tuned!
Expand Down
22 changes: 19 additions & 3 deletions packages/db/src/meta/pouch/adapters/fs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,25 @@ export interface DatabasesSettings {
directory: string;
}

export const getDefaultSettings: GetDefaultSettings = () => ({
directory: path.join(Config.getTruffleDataDirectory(), ".db", "json")
});
type UserConfigDbSettings = {
saveToProjectRoot?: boolean,
};

type UserConfig = {
get: (key: "db") => UserConfigDbSettings,
};

export const getDefaultSettings: GetDefaultSettings = () => {
const userConfig: UserConfig = Config.getUserConfig();

return {
directory: path.join(
userConfig.get("db")?.saveToProjectRoot
? Config.detect().workingDirectory
: Config.getTruffleDataDirectory()
, ".db", "json")
};
};

export class Databases<C extends Collections> extends Base.Databases<C> {
private directory: string;
Expand Down
22 changes: 19 additions & 3 deletions packages/db/src/meta/pouch/adapters/sqlite.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,25 @@ export interface DatabasesSettings {
directory: string;
}

export const getDefaultSettings: GetDefaultSettings = () => ({
directory: path.join(Config.getTruffleDataDirectory(), ".db", "sqlite")
});
type UserConfigDbSettings = {
saveToProjectRoot?: boolean,
};

type UserConfig = {
get: (key: "db") => UserConfigDbSettings,
};

export const getDefaultSettings: GetDefaultSettings = () => {
const userConfig: UserConfig = Config.getUserConfig();

return {
directory: path.join(
userConfig.get("db")?.saveToProjectRoot
? Config.detect().workingDirectory
: Config.getTruffleDataDirectory()
, ".db", "sqlite")
};
};

export class Databases<C extends Collections> extends Base.Databases<C> {
private directory: string;
Expand Down