Skip to content

Closes #365: Added Seed Script - #386

Merged
katconnors merged 8 commits into
mainfrom
seed-file
Aug 21, 2024
Merged

Closes #365: Added Seed Script#386
katconnors merged 8 commits into
mainfrom
seed-file

Conversation

@katconnors

Copy link
Copy Markdown
Contributor

Seed script has been added to populate tables with test data.
One can use npm run db:seed to add three students and one staff member to the database.

image
image

@katconnors katconnors linked an issue Aug 20, 2024 that may be closed by this pull request

@mrabbitt mrabbitt left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I tried out the db:seed command on my local environment and it worked great! I also tried out a couple of error scenarios:

  1. If db:seed is run right after db:reset without logging in to create an admin user first, it failed as I'd expect. The error message is basically NoResultError: no result with a stacktrace. ✅
  2. If db:seed is run a second time after it runs successfully, it fails as expected with error: duplicate key value violates unique constraint "student_email_key". ✅

One other thought for future improvement: Should there be a test to make sure the db:seed command doesn't fail in the future if there are schema changes to the database?

I pointed out one typo and made a minor improvement suggestion in other comments, but otherwise it looks great to me.

Thanks for adding this!

Comment thread README.md Outdated
4. Seed database (Optional)
````sh
npm run db:seed # Seed the database with test data
``` # Must be done after login to Compass app

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think the backticks on this line are a typo.

Suggested change
``` # Must be done after login to Compass app
# Must be done after login to Compass app

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks for documenting that the command must be run after logging into Compass to create the admin user. 👍

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

You're welcome! Good suggestion- I'll open up a ticket for a test to be added.

Comment thread src/backend/db/lib/seed.ts Outdated
Comment on lines +56 to +60
const newstaff = await db
.selectFrom("user")
.select("user_id")
.where("first_name", "=", "Helen")
.executeTakeFirstOrThrow();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Minor improvement suggestion: This select query could be replaced by capturing the user_id from the result of the above insert statement.

See the "Return one column" example here: https://kysely-org.github.io/kysely-apidoc/classes/InsertQueryBuilder.html#returning

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Good callout. Updated this!

@katconnors

Copy link
Copy Markdown
Contributor Author

Thanks for the feedback, @mrabbitt!

@katconnors katconnors mentioned this pull request Aug 20, 2024
2 tasks
@katconnors
katconnors requested a review from mrabbitt August 20, 2024 22:57

@mrabbitt mrabbitt left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Looks good to me.

@katconnors
katconnors merged commit 372f88d into main Aug 21, 2024
@katconnors
katconnors deleted the seed-file branch August 21, 2024 01:50
chengtchris1 added a commit that referenced this pull request Aug 28, 2024
* change `npm i --ci` to `npm ci` to help ensure reproducible builds (#353)

* Chore/upgrade NextJS (#361)

* update NextJS to 14 along with react, react-dom, other deps

* adjust min node version to NextJS 14's requirement

* Create dependabot.yml (#354)

configure dependabot for npm and Github Actions

* Closes #365: Added Seed Script (#386)

* structure for seeding db

* added seed.ts

* seed script functionality addded

* resolved seed data visualization, added student data

* seed data for staff

* update readme to include new script

* removed unused name

* cleanup, typo fixes

* Chore/fix lint warnings (#383)

* fix linting issues

* address remaining lint warnings

* fix type error in theme

* undo color changes

* Fix #369: Fixed Javascript console warnings on Create Benchmark page (#385)

Fixed warnings related to handling null for textarea values, custom Stepper icons.

* Created benchmark view new design (#347)

* Started redesigning subgoal list element.

* Added data section to subgoal list element

* Change description text to overline style

* Move 'Add benchmark' button to the right of the benchmark status tabs

* Change color of created on blurb

* 'Added clipboard icon before the description text in tile element'

* Improve appearence on mobile

* Improve appearence of "Add benchmark" button on mobile

* Add an All Tab, add filtering by status

* Center No subgoals yet text

* Fix type script issue

* Add placeholder graphic when theres no benchmarks

* Move benchmark section into its own component

* Fix TS Check error

* Fix TS check error

* Create a white goal page container

* Fix TSC error

* change padding between benchmark goal tile

* Seperate benchmark description into own component, add "view all goals" button, change button styling

* Fix tsc

* prettier

* Remove unneeded comment

* Fix centering on "No Benchmarks Yet" screen by adding margin

* Change the text color for 'Goal #X' label, removeunderline from 'View all Goals' button, change text from 'Add benchmark' to 'Create benchmark' to allign with figma

* Add placeholder links for collect/view Data

* Add button.tertiary class to Collect/View Data

* Replace Link component with buttons

* Remove edit goal and view all goals from BenchmarkGoalHeader to goal-header

* Rename benchmarks to benchmarks container, move child benchmarks into seperate component to allign with naming scheme

* typescript fixes

* typescript fixes

* typescript fixes, check for showEditGoal

* Remove 'subgoal' and merge files to benchmarks. Reduce props used for BenchmarksGoalHeader by moving logic to parent. Revert change to CSS.

* Remove unneeded comments and import statements

* Further clean up unused import statements

* Remove BenchmarkGoalHeader and move its logic into [goal_id].tsx

* Fix type check error for "submittedEditGoal()"

* Remove benchmarks file, combine with BenchmarkContainer. Simpify logic for displaying "NoBenchmarkGraphic"

* Try to replace references to subgoal to benchmark where possible

* Replace 'button' elements with MUI 'Button' elements, change a Link component with button classname to a button component wraped in Link

* Remove unused export

* Change buttons to MUI Button eelement on remaining benchmark fikes

* Move logic edit goal logic to goal header, change design to match Figma

* Edit button style on edit goal form

* Modify create.tsx to remove the wrapper element, remove unneeded white padding

* replace textarea with MUI textfield

* replace textarea with MUI TextareaAutosize

* Remove unneeded grid

* Bump axios from 1.6.8 to 1.7.5 (#393)

Bumps [axios](https://github.com/axios/axios) from 1.6.8 to 1.7.5.
- [Release notes](https://github.com/axios/axios/releases)
- [Changelog](https://github.com/axios/axios/blob/v1.x/CHANGELOG.md)
- [Commits](axios/axios@v1.6.8...v1.7.5)

---
updated-dependencies:
- dependency-name: axios
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

---------

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: NV <2823112+nickvisut@users.noreply.github.com>
Co-authored-by: Katrina Connors <32425204+katconnors@users.noreply.github.com>
Co-authored-by: mrabbitt <284825+mrabbitt@users.noreply.github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
chengtchris1 added a commit that referenced this pull request Aug 28, 2024
* Started redesigning subgoal list element.

* Added data section to subgoal list element

* Change description text to overline style

* Move 'Add benchmark' button to the right of the benchmark status tabs

* Change color of created on blurb

* 'Added clipboard icon before the description text in tile element'

* Improve appearence on mobile

* Improve appearence of "Add benchmark" button on mobile

* Add an All Tab, add filtering by status

* Center No subgoals yet text

* Fix type script issue

* Add placeholder graphic when theres no benchmarks

* Move benchmark section into its own component

* Fix TS Check error

* Fix TS check error

* Create a white goal page container

* Fix TSC error

* change padding between benchmark goal tile

* Seperate benchmark description into own component, add "view all goals" button, change button styling

* Fix tsc

* prettier

* Remove unneeded comment

* Fix centering on "No Benchmarks Yet" screen by adding margin

* Change the text color for 'Goal #X' label, removeunderline from 'View all Goals' button, change text from 'Add benchmark' to 'Create benchmark' to allign with figma

* Add placeholder links for collect/view Data

* Add button.tertiary class to Collect/View Data

* Replace Link component with buttons

* Remove edit goal and view all goals from BenchmarkGoalHeader to goal-header

* Rename benchmarks to benchmarks container, move child benchmarks into seperate component to allign with naming scheme

* typescript fixes

* typescript fixes

* typescript fixes, check for showEditGoal

* Remove 'subgoal' and merge files to benchmarks. Reduce props used for BenchmarksGoalHeader by moving logic to parent. Revert change to CSS.

* Remove unneeded comments and import statements

* Further clean up unused import statements

* Remove BenchmarkGoalHeader and move its logic into [goal_id].tsx

* Fix type check error for "submittedEditGoal()"

* Remove benchmarks file, combine with BenchmarkContainer. Simpify logic for displaying "NoBenchmarkGraphic"

* Try to replace references to subgoal to benchmark where possible

* Replace 'button' elements with MUI 'Button' elements, change a Link component with button classname to a button component wraped in Link

* Remove unused export

* Change buttons to MUI Button eelement on remaining benchmark fikes

* Move logic edit goal logic to goal header, change design to match Figma

* Edit button style on edit goal form

* Modify create.tsx to remove the wrapper element, remove unneeded white padding

* replace textarea with MUI textfield

* replace textarea with MUI TextareaAutosize

* Remove unneeded grid

* Merge main to Created-benchmark-view-new-design (#398)

* change `npm i --ci` to `npm ci` to help ensure reproducible builds (#353)

* Chore/upgrade NextJS (#361)

* update NextJS to 14 along with react, react-dom, other deps

* adjust min node version to NextJS 14's requirement

* Create dependabot.yml (#354)

configure dependabot for npm and Github Actions

* Closes #365: Added Seed Script (#386)

* structure for seeding db

* added seed.ts

* seed script functionality addded

* resolved seed data visualization, added student data

* seed data for staff

* update readme to include new script

* removed unused name

* cleanup, typo fixes

* Chore/fix lint warnings (#383)

* fix linting issues

* address remaining lint warnings

* fix type error in theme

* undo color changes

* Fix #369: Fixed Javascript console warnings on Create Benchmark page (#385)

Fixed warnings related to handling null for textarea values, custom Stepper icons.

* Created benchmark view new design (#347)

* Started redesigning subgoal list element.

* Added data section to subgoal list element

* Change description text to overline style

* Move 'Add benchmark' button to the right of the benchmark status tabs

* Change color of created on blurb

* 'Added clipboard icon before the description text in tile element'

* Improve appearence on mobile

* Improve appearence of "Add benchmark" button on mobile

* Add an All Tab, add filtering by status

* Center No subgoals yet text

* Fix type script issue

* Add placeholder graphic when theres no benchmarks

* Move benchmark section into its own component

* Fix TS Check error

* Fix TS check error

* Create a white goal page container

* Fix TSC error

* change padding between benchmark goal tile

* Seperate benchmark description into own component, add "view all goals" button, change button styling

* Fix tsc

* prettier

* Remove unneeded comment

* Fix centering on "No Benchmarks Yet" screen by adding margin

* Change the text color for 'Goal #X' label, removeunderline from 'View all Goals' button, change text from 'Add benchmark' to 'Create benchmark' to allign with figma

* Add placeholder links for collect/view Data

* Add button.tertiary class to Collect/View Data

* Replace Link component with buttons

* Remove edit goal and view all goals from BenchmarkGoalHeader to goal-header

* Rename benchmarks to benchmarks container, move child benchmarks into seperate component to allign with naming scheme

* typescript fixes

* typescript fixes

* typescript fixes, check for showEditGoal

* Remove 'subgoal' and merge files to benchmarks. Reduce props used for BenchmarksGoalHeader by moving logic to parent. Revert change to CSS.

* Remove unneeded comments and import statements

* Further clean up unused import statements

* Remove BenchmarkGoalHeader and move its logic into [goal_id].tsx

* Fix type check error for "submittedEditGoal()"

* Remove benchmarks file, combine with BenchmarkContainer. Simpify logic for displaying "NoBenchmarkGraphic"

* Try to replace references to subgoal to benchmark where possible

* Replace 'button' elements with MUI 'Button' elements, change a Link component with button classname to a button component wraped in Link

* Remove unused export

* Change buttons to MUI Button eelement on remaining benchmark fikes

* Move logic edit goal logic to goal header, change design to match Figma

* Edit button style on edit goal form

* Modify create.tsx to remove the wrapper element, remove unneeded white padding

* replace textarea with MUI textfield

* replace textarea with MUI TextareaAutosize

* Remove unneeded grid

* Bump axios from 1.6.8 to 1.7.5 (#393)

Bumps [axios](https://github.com/axios/axios) from 1.6.8 to 1.7.5.
- [Release notes](https://github.com/axios/axios/releases)
- [Changelog](https://github.com/axios/axios/blob/v1.x/CHANGELOG.md)
- [Commits](axios/axios@v1.6.8...v1.7.5)

---
updated-dependencies:
- dependency-name: axios
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

---------

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: NV <2823112+nickvisut@users.noreply.github.com>
Co-authored-by: Katrina Connors <32425204+katconnors@users.noreply.github.com>
Co-authored-by: mrabbitt <284825+mrabbitt@users.noreply.github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* Run prettier

* Run 'npm run format'

---------

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: NV <2823112+nickvisut@users.noreply.github.com>
Co-authored-by: Katrina Connors <32425204+katconnors@users.noreply.github.com>
Co-authored-by: mrabbitt <284825+mrabbitt@users.noreply.github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add seed script

2 participants