Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: update db utils script to reflect new architecture #289

Merged
merged 5 commits into from
Aug 16, 2023

Conversation

lanterno
Copy link
Contributor

@lanterno lanterno commented Aug 2, 2023

The dbUtils script is outdated, and doesn't work with the current backend. I've adjusted the script, and tested it.

Currently, there's no tests, but it might be a good idea later to add some.

Reviewing each commit separately should provide a better idea of the logical sequence of changes.

ToDo:

  • Rename the file to a more sensible name cli.ts
  • Use a proper CLI library/tool
  • Add some unit tests (maybe)

closes #300

@lanterno lanterno requested a review from PascalinDe August 2, 2023 14:35
@lanterno lanterno force-pushed the fix/update-dbUtils-script-to-reflect-new-architecture branch from f1468ca to dbdce2c Compare August 2, 2023 14:38
@lanterno lanterno marked this pull request as ready for review August 2, 2023 14:54
@lanterno lanterno requested a review from a team as a code owner August 2, 2023 14:54
@lanterno
Copy link
Contributor Author

lanterno commented Aug 2, 2023

I was planning to change the JS script into typescript, but apparently, it's a bit more complex to have a CLI in typescript, so I'll do that in another PR.

Update: there's also Commander.js that I'm investigating now. Still, for the next PR 😉

Copy link
Contributor

@PascalinDe PascalinDe left a comment

Choose a reason for hiding this comment

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

I'm wondering if /src is really the best place... maybe add a directory /src/scripts to make it clear that it's not part of the application code?

apart from that LGTM

@lanterno
Copy link
Contributor Author

lanterno commented Aug 7, 2023

@PascalinDe since it's a small script, I was thinking about renaming it to cli.ts in my next PR.
I think it goes along with the naming for the backend code server.ts.

What do you think?

@PascalinDe
Copy link
Contributor

@PascalinDe since it's a small script, I was thinking about renaming it to cli.ts in my next PR. I think it goes along with the naming for the backend code server.ts.

What do you think?

sounds great!

@lanterno lanterno requested review from pierluca and jbsv August 7, 2023 13:16
Copy link
Contributor

Choose a reason for hiding this comment

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

To add to @PascalinDe 's comments and your suggestion to rename this cli.js, I'd like to bring up the NPM convention of having a bin/ folder and defining it in the bin key in the package.json, with a shebang at the top. This would allow the usage of npx, which is always nice.

For references:
https://docs.npmjs.com/cli/v9/configuring-npm/package-json#bin
https://blog.shahednasser.com/how-to-create-a-npx-tool/

Copy link
Contributor

Choose a reason for hiding this comment

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

Obviously this could be in a follow up PR and not now :-)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Check it out.. now it's npx cli addAdmin --sciper 123

Copy link
Contributor

@PascalinDe PascalinDe left a comment

Choose a reason for hiding this comment

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

now that it is merged, can you update README.docker as well? thanks!

Ahmed Elghareeb added 2 commits August 9, 2023 11:32
This makes it easier to identify this script as part of the source code. Also, it's easier to make the src folder as a volume for docker compose for realtime update of the contents while the container is running.
@PascalinDe
Copy link
Contributor

PascalinDe commented Aug 9, 2023

the script is not executing properly in the Docker image:

root@40c225d12de8:/web/backend# NODE_PATH=./node_modules node -e 'require("./src/dbUtils").addAdmin("...")'
/web/backend/src/dbUtils.js:9
import { SequelizeAdapter } from 'casbin-sequelize-adapter';
^^^^^^

SyntaxError: Cannot use import statement outside a module
    at internalCompileFunction (node:internal/vm:73:18)
    at wrapSafe (node:internal/modules/cjs/loader:1153:20)
    at Module._compile (node:internal/modules/cjs/loader:1197:27)
    at Module._extensions..js (node:internal/modules/cjs/loader:1287:10)
    at Module.load (node:internal/modules/cjs/loader:1091:32)
    at Module._load (node:internal/modules/cjs/loader:938:12)
    at Module.require (node:internal/modules/cjs/loader:1115:19)
    at require (node:internal/modules/helpers:119:18)
    at [eval]:1:1
    at Script.runInThisContext (node:vm:122:12)

Node.js v20.5.0

I'm not very familiar with JavaScript, maybe it's not meant to be run like this? can you please clarify?

@lanterno lanterno added the node backend About the blockchain node label Aug 10, 2023
@lanterno lanterno force-pushed the fix/update-dbUtils-script-to-reflect-new-architecture branch from 7cbb9cf to ac4a3c7 Compare August 11, 2023 05:19
@lanterno
Copy link
Contributor Author

@PascalinDe @pierluca I rebased the PR to include the docker changes made by @PascalinDe, and I'm now using a CLI library called CommanderJS to build a CLI. along with npx and node bin, it's a great combination to have a cli tool

example: npx cli addAdmin --sciper 1234

I hope you like it :)

@coveralls
Copy link

coveralls commented Aug 11, 2023

Pull Request Test Coverage Report for Build 5829454076

  • 0 of 0 changed or added relevant lines in 0 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+0.05%) to 57.444%

Totals Coverage Status
Change from base Build 5809092943: 0.05%
Covered Lines: 3272
Relevant Lines: 5696

💛 - Coveralls

@lanterno lanterno force-pushed the fix/update-dbUtils-script-to-reflect-new-architecture branch from ac4a3c7 to 8e94ea6 Compare August 11, 2023 05:27
@lanterno lanterno force-pushed the fix/update-dbUtils-script-to-reflect-new-architecture branch from 8e94ea6 to 33da8d3 Compare August 11, 2023 06:05
@sonarqubecloud
Copy link

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

0.0% 0.0% Coverage
0.0% 0.0% Duplication

Copy link
Contributor

@PascalinDe PascalinDe left a comment

Choose a reason for hiding this comment

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

can you please update the README.docker as well?

Copy link
Contributor

@pierluca pierluca left a comment

Choose a reason for hiding this comment

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

Very nice ! LGTM

@pierluca pierluca merged commit f0f6a92 into main Aug 16, 2023
@pierluca pierluca deleted the fix/update-dbUtils-script-to-reflect-new-architecture branch August 16, 2023 08:32
@coveralls
Copy link

coveralls commented Sep 19, 2024

Pull Request Test Coverage Report for Build 5829454076

Warning: This coverage report may be inaccurate.

This pull request's base commit is no longer the HEAD commit of its target branch. This means it includes changes from outside the original pull request, including, potentially, unrelated coverage changes.

Details

  • 0 of 0 changed or added relevant lines in 0 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+0.05%) to 57.444%

Totals Coverage Status
Change from base Build 5809092943: 0.05%
Covered Lines: 3272
Relevant Lines: 5696

💛 - Coveralls

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
node backend About the blockchain node
Projects
None yet
Development

Successfully merging this pull request may close these issues.

CLI utility for backend
4 participants