[PR #45] The First Admin Registration as a Seed Command
- What changed: A seed command (npm run seed:admins) was created to add the first admin. The address is passed only through an environment variable at run time.
- Decision: No real address is kept in the repository. A preview catches a mistyped address, and if any address is wrong, nothing is added.
- Still unknown: Whether a registered address can actually log in will be checked after the login work is finished.
PR #45 is the record of building a seed command (a command that creates the first data a system needs) to add the first admins. No agent-led work ran.
What was done and why
- Admin login uses a Google account. The server rejects any address that is not in the admin table. So someone has to add the first admin addresses to the table once.
- A command,
npm run seed:admins, was built for this. The addresses are read only from an environment variable at run time.
Options considered
- Addresses are not written into code. It was not yet decided whether the repository would be made public, so no real address appears in code, tests, or the work record. The rejected options were writing addresses into code and putting them in a settings file. Both leave the addresses in the repository.
- A preview catches mistyped addresses. A mistyped address that belongs to someone else would make that person an admin. So a
--dry-runoption shows the full addresses before anything is written. The real run hides part of each address in its output. - If any address is invalid, nothing is written. An address with the wrong shape, or one outside the company domain, rejects the whole list. Addresses outside the company are blocked at login anyway, so rejecting them early is safer.
- A second run gives the same result. Addresses that already exist are skipped, and all inserts go in one transaction (all succeed or all are undone). Running two copies at once does not cause an error.
- Disabled admins are not turned back on. This keeps a departed person’s account from coming back without anyone noticing.
- A record of the change is kept. At first the plan had no record of adding an admin. The personal-data safety standard requires a record of granting and removing permissions, kept for a set period. So each new admin now gets one record line, with the address hidden. Skipped addresses and previews write nothing.
How it was checked
- Tests were written first. The test file did not exist yet, so the test failed before the code was written. The tests use only example-domain addresses.
- The tests cover adding two admins, lowercasing, running again to get skips with no row changes, keeping disabled admins off, rejecting six kinds of bad addresses with nothing written, and the preview writing nothing.
- A test for two runs at the same time first failed and was fixed. After the fix it passed several times in a row.
- The real command was run on an empty database: a missing value exits with an error, the preview shows what would be added, the first real run inserts, and the second run skips.
- The project’s check command passed.
Not yet checked
- Admin login does not exist yet, so a registered address has not yet been tested for actual login. That check happens after the login work is finished.
- Real addresses are not stored in the repository. They are entered in the shell at run time.
Lessons
- Settings that contain personal data create a risk if they sit in code. Designing the value to be read only at run time is safer.
- When wrong input changes permissions, show the result before running. A preview step is needed.
- Records of permission changes should be planned with the feature. Adding them later leaves out changes that already happened.