Skip to content

#646 feat: add seed data for dummy users #647

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

Merged
merged 65 commits into from
May 23, 2025
Merged

#646 feat: add seed data for dummy users #647

merged 65 commits into from
May 23, 2025

Conversation

usrrname
Copy link
Contributor

@usrrname usrrname commented Mar 14, 2025

Changes

  • adds seeds/ folder and script for opting in to seed dummy users

  • include env_file property on docker-compose to read from .env variable changes a user might make during development

Testing:

Screenshot 2025-03-24 at 9 55 59 AM Screenshot 2025-03-24 at 9 55 07 AM

created [email protected], was able to log in with autogenerated password

#646

TODO:

  • make use of seed opt-in

@usrrname usrrname marked this pull request as ready for review March 14, 2025 21:28
@usrrname usrrname requested a review from evert March 14, 2025 21:36
@evert
Copy link
Member

evert commented Mar 15, 2025

Was this tested if you got an error?

@usrrname usrrname force-pushed the feat/646-seed-data branch from e45c656 to e3abaa3 Compare March 16, 2025 01:44
@usrrname usrrname force-pushed the feat/646-seed-data branch 7 times, most recently from 48ced72 to 1659c52 Compare March 16, 2025 05:01
@usrrname
Copy link
Contributor Author

Was this tested if you got an error?

Yep... working through these... tons of null value in column "field" of relation "table-name" violates not-null constraint

@usrrname usrrname force-pushed the feat/646-seed-data branch 6 times, most recently from 967094b to a888f27 Compare March 17, 2025 01:27
@evert
Copy link
Member

evert commented Mar 17, 2025

Last night I did get something going in, but it was still breaking

I noticed this was force-pushed after. Was this still an issue? Don't 100% understand how that could happen!

@usrrname usrrname force-pushed the feat/646-seed-data branch from a888f27 to a03a1b7 Compare March 17, 2025 20:06
@usrrname
Copy link
Contributor Author

The force-push was a result of me making changes, squashing a commit and pushing it up :p

@usrrname
Copy link
Contributor Author

Rebased... and still err-ing:

of note: PostgreSQL Database directory appears to contain a database; Skipping initialization
Seems like if there was already some data on a mounted volume, the migrations wont run.

Full Trace
Attaching to a12n-server-1, db-1
db-1           | 
db-1           | PostgreSQL Database directory appears to contain a database; Skipping initialization
db-1           | 
db-1           | 2025-03-17 23:20:34.425 UTC [1] LOG:  starting PostgreSQL 17.2 (Debian 17.2-1.pgdg120+1) on aarch64-unknown-linux-gnu, compiled by gcc (Debian 12.2.0-14) 12.2.0, 64-bit
db-1           | 2025-03-17 23:20:34.425 UTC [1] LOG:  listening on IPv4 address "0.0.0.0", port 5432
db-1           | 2025-03-17 23:20:34.425 UTC [1] LOG:  listening on IPv6 address "::", port 5432
db-1           | 2025-03-17 23:20:34.426 UTC [1] LOG:  listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"
db-1           | 2025-03-17 23:20:34.429 UTC [29] LOG:  database system was shut down at 2025-03-17 23:19:02 UTC
db-1           | 2025-03-17 23:20:34.434 UTC [1] LOG:  database system is ready to accept connections
a12n-server-1  | ⚾ @curveball/a12n-server 0.30.0
a12n-server-1  | PUBLIC_URI environment variable was not set, defaulting to http://localhost:8531/
a12n-server-1  | Running database migrations
a12n-server-1  | Running database seeds
db-1           | 2025-03-17 23:20:35.294 UTC [33] ERROR:  column "principal_id" of relation "user_info" does not exist at character 73
db-1           | 2025-03-17 23:20:35.294 UTC [33] STATEMENT:  insert into "user_info" ("family_name", "given_name", "locale", "name", "principal_id") values ($1, $2, $3, $4, $5)
a12n-server-1  | Migrations failed Error: Error while executing "/opt/app/dist/seeds/001_users.js" seed: insert into "user_info" ("family_name", "given_name", "locale", "name", "principal_id") values ($1, $2, $3, $4, $5) - column "principal_id" of relation "user_info" does not exist
a12n-server-1  |     at Seeder._waterfallBatch (/opt/app/node_modules/knex/lib/migrations/seed/Seeder.js:118:23)
a12n-server-1  | error: insert into "user_info" ("family_name", "given_name", "locale", "name", "principal_id") values ($1, $2, $3, $4, $5) - column "principal_id" of relation "user_info" does not exist
a12n-server-1  |     at Parser.parseErrorMessage (/opt/app/node_modules/pg-protocol/dist/parser.js:283:98)
a12n-server-1  |     at Parser.handlePacket (/opt/app/node_modules/pg-protocol/dist/parser.js:122:29)
a12n-server-1  |     at Parser.parse (/opt/app/node_modules/pg-protocol/dist/parser.js:35:38)
a12n-server-1  |     at Socket.<anonymous> (/opt/app/node_modules/pg-protocol/dist/index.js:11:42)
a12n-server-1  |     at Socket.emit (node:events:524:28)
a12n-server-1  |     at addChunk (node:internal/streams/readable:561:12)
a12n-server-1  |     at readableAddChunkPushByteMode (node:internal/streams/readable:512:3)
a12n-server-1  |     at Readable.push (node:internal/streams/readable:392:5)
a12n-server-1  |     at TCP.onStreamRead (node:internal/stream_base_commons:191:23) {
a12n-server-1  |   original: error: insert into "user_info" ("family_name", "given_name", "locale", "name", "principal_id") values ($1, $2, $3, $4, $5) - column "principal_id" of relation "user_info" does not exist
a12n-server-1  |       at Parser.parseErrorMessage (/opt/app/node_modules/pg-protocol/dist/parser.js:283:98)
a12n-server-1  |       at Parser.handlePacket (/opt/app/node_modules/pg-protocol/dist/parser.js:122:29)
a12n-server-1  |       at Parser.parse (/opt/app/node_modules/pg-protocol/dist/parser.js:35:38)
a12n-server-1  |       at Socket.<anonymous> (/opt/app/node_modules/pg-protocol/dist/index.js:11:42)
a12n-server-1  |       at Socket.emit (node:events:524:28)
a12n-server-1  |       at addChunk (node:internal/streams/readable:561:12)
a12n-server-1  |       at readableAddChunkPushByteMode (node:internal/streams/readable:512:3)
a12n-server-1  |       at Readable.push (node:internal/streams/readable:392:5)
a12n-server-1  |       at TCP.onStreamRead (node:internal/stream_base_commons:191:23) {
a12n-server-1  |     length: 134,
a12n-server-1  |     severity: 'ERROR',
a12n-server-1  |     code: '42703',
a12n-server-1  |     detail: undefined,
a12n-server-1  |     hint: undefined,
a12n-server-1  |     position: '73',
a12n-server-1  |     internalPosition: undefined,
a12n-server-1  |     internalQuery: undefined,
a12n-server-1  |     where: undefined,
a12n-server-1  |     schema: undefined,
a12n-server-1  |     table: undefined,
a12n-server-1  |     column: undefined,
a12n-server-1  |     dataType: undefined,
a12n-server-1  |     constraint: undefined,
a12n-server-1  |     file: 'parse_target.c',
a12n-server-1  |     line: '1065',
a12n-server-1  |     routine: 'checkInsertTargets'
a12n-server-1  |   }
a12n-server-1  | }
a12n-server-1 exited with code 1
Gracefully stopping... (press Ctrl+C again to force)

@usrrname usrrname force-pushed the feat/646-seed-data branch 2 times, most recently from a4c20a3 to 992bb23 Compare March 22, 2025 18:15
@usrrname
Copy link
Contributor Author

Now.. it seems I can set seed.user / process.env.SEED_USER or cors.allowOrigin/process.env.CORS_ALLOW_ORIGIN in .env independently. However, if I set both, I'll get this error when I try to login with the admin user

Screenshot 2025-03-22 at 2 53 47 PM

@usrrname usrrname requested a review from evert March 22, 2025 18:57
@usrrname usrrname force-pushed the feat/646-seed-data branch from 0b9bb53 to 4c4ad92 Compare May 12, 2025 17:13
@usrrname usrrname requested a review from evert May 14, 2025 03:49
@usrrname
Copy link
Contributor Author

Screenshot 2025-05-14 at 1 31 58 PM Not sure what's going on here

@evert
Copy link
Member

evert commented May 14, 2025

I think it's because the .yml is invalid :')

@usrrname
Copy link
Contributor Author

Ohhh yeah I remember why I added the extra strategy with node versions now!

Screenshot 2025-05-14 at 9 44 54 PM

@usrrname
Copy link
Contributor Author

Screenshot 2025-05-21 at 11 22 37 AM I think this one is still there because that is what's on the `test.yml` on `main`

@usrrname usrrname requested a review from Copilot May 22, 2025 01:20
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR adds a seed script for dummy users and wires seed support into the database configuration, local development tools, and documentation.

  • Introduces src/seeds/001_users.ts to populate initial user data
  • Extends Knex config and CLI targets (Makefile, GitHub Actions) to run seeds
  • Updates docs (docs/server-settings.md, .github/CONTRIBUTING.md) and docker-compose.yml to document and enable environment-driven settings

Reviewed Changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
src/server-settings.ts Removed stray blank lines
src/seeds/001_users.ts New seed script to insert dummy users
src/database.ts Registers the seed directory and adds a seed() API
docs/server-settings.md Expanded settings table with environment-variable column
docker-compose.yml Added env_file reference for .env
Makefile Added knex-seed target
.github/workflows/test.yml Runs seeds after migrations in matrix CI jobs
.github/CONTRIBUTING.md Documented seed usage
Comments suppressed due to low confidence (3)

src/server-settings.ts:309

  • The %s placeholder is never supplied an argument here, so row.setting won’t appear in the log. Pass row.setting as a second parameter to console.warn.
console.warn('The setting %s may not be set from the database. We ignored it');

docs/server-settings.md:16

  • The new table header includes an “Environment Variable” column, but this row (and some below) has only four columns. Add the appropriate env var or a placeholder () to keep the table aligned.
| `login.defaultRedirect`     | String  | `/`         | The url that the user will be redirected to after the log in to a12nserver, and no other redirect_uri is provided by the application. It's a good idea to set this to your application URL.|

src/seeds/001_users.ts:35

  • The new seed functionality is not covered by any tests. Adding a simple integration test to verify that seed() inserts the expected records could prevent regressions.
export async function seed(knex: Knex): Promise<void> {

Copy link
Member

@evert evert left a comment

Choose a reason for hiding this comment

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

Lets go!

@evert evert merged commit e706e18 into main May 23, 2025
20 checks passed
@evert evert deleted the feat/646-seed-data branch May 23, 2025 18:52
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.

2 participants