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

Improve the dbseed.js script #263

Merged
merged 6 commits into from Apr 5, 2021
Merged

Improve the dbseed.js script #263

merged 6 commits into from Apr 5, 2021

Conversation

nickytonline
Copy link
Contributor

@nickytonline nickytonline commented Apr 3, 2021

Description

Incorporates all the improvements suggested for dbseed.js in #262.

Related Tickets & Documents

Closes #262

QA Instructions, Screenshots, Recordings

  1. Grab this branch, e.g. via the GitHub CLI, gh co 263
  2. Run yarn to install the new packages.
  3. Run yarn emulators to ensure the emulated Firestore is running.
  4. Run node dbseed.js from the root of the project. The database should seed with 10 jobs.
  5. Stop the emulator by terminating the yarn emulators command via CTRL + C
  6. Run yarn emulators to ensure the emulated Firestore is running.
  7. Run node dbseed.js --seedSize=15 from the root of the project. The database should seed with 15 jobs.

[optional] What gif best describes this PR or how it makes you feel?

A G.I. Joe figuring bobbing his head

@vercel
Copy link

vercel bot commented Apr 3, 2021

This pull request is being automatically deployed with Vercel (learn more).
To see the status of your deployment, click below or on the icon next to each commit.

🔍 Inspect: https://vercel.com/drewclem/protege/or3KD8o1d5eosyyt71SBGk4KhiAD
✅ Preview: https://protege-git-fix-dbseed-drewclem.vercel.app

@nickytonline nickytonline changed the title Added the dotenv package. Improve the dbseed.js script Apr 3, 2021

// Seeding data is only for non-production environments.
if (process.env.NODE_ENV === 'production') {
throw new Error(
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Throw an error if we are in the production environment.

try {
;[...Array(10).keys()].map(() =>
Copy link
Contributor Author

Choose a reason for hiding this comment

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

We don't need to map the array as we're not mapping to anything. A loop is good for the job.

;[...Array(10).keys()].map(() =>
db.collection('jobs').add({
for (let i = 0; i < seedSize; i++) {
const job = {
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 found it difficult to grok the job when it was directly in the add method. Happy to put it back if you prefer that.

@sethburtonhall sethburtonhall merged commit a0bbf7b into develop Apr 5, 2021
@sethburtonhall sethburtonhall deleted the fix-dbseed branch April 5, 2021 15:20
@sethburtonhall
Copy link
Contributor

Looks good @nickytonline. Thanks!!

@nickytonline
Copy link
Contributor Author

nickytonline commented Apr 5, 2021

One notable change is to env.local.template. Ensure your env.local file includes this line.

https://github.com/drewclem/protege/blob/a0bbf7bff2d7bdddce8ba55a9eabc34bc6457e45/.env.local.template#L9

Failing to do so will result in the following error.

Error: Could not load the default credentials. Browse to https://cloud.google.com/docs/authentication/getting-started for more information.
    at GoogleAuth.getApplicationDefaultAsync (/Users/some_user/projects/protege/node_modules/google-auth-library/build/src/auth/googleauth.js:173:19)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Improve the database seed script
2 participants