@heychunky/core 0.14.0 → 0.15.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/admin/apps.d.ts +3 -0
- package/dist/admin/apps.d.ts.map +1 -1
- package/dist/admin/apps.js +16 -2
- package/dist/admin/apps.js.map +1 -1
- package/dist/admin/index.d.ts +2 -0
- package/dist/admin/index.d.ts.map +1 -1
- package/dist/admin/index.js +2 -0
- package/dist/admin/index.js.map +1 -1
- package/dist/admin/migrations.d.ts +19 -0
- package/dist/admin/migrations.d.ts.map +1 -1
- package/dist/admin/migrations.js +27 -0
- package/dist/admin/migrations.js.map +1 -1
- package/dist/admin/orgs.d.ts +142 -0
- package/dist/admin/orgs.d.ts.map +1 -0
- package/dist/admin/orgs.js +166 -0
- package/dist/admin/orgs.js.map +1 -0
- package/dist/admin/register.d.ts +98 -0
- package/dist/admin/register.d.ts.map +1 -0
- package/dist/admin/register.js +191 -0
- package/dist/admin/register.js.map +1 -0
- package/dist/services/db.d.ts +16 -0
- package/dist/services/db.d.ts.map +1 -1
- package/dist/services/db.js +27 -22
- package/dist/services/db.js.map +1 -1
- package/package.json +3 -2
- package/register/0001-baseline/01-invite-requests.sql +11 -0
- package/register/0001-baseline/02-invite-requests-email-key.sql +1 -0
- package/register/0001-baseline/03-login-codes.sql +12 -0
- package/register/0001-baseline/04-login-codes-email-idx.sql +1 -0
- package/register/0001-baseline/05-notifications.sql +11 -0
- package/register/0001-baseline/06-notifications-unread-idx.sql +1 -0
- package/register/0001-baseline/07-users.sql +13 -0
- package/register/0001-baseline/08-users-email-key.sql +1 -0
- package/register/0001-baseline/09-users-one-superadmin.sql +1 -0
- package/register/0001-baseline/10-users-username-unique.sql +1 -0
- package/register/0001-baseline/11-api-tokens.sql +13 -0
- package/register/0001-baseline/12-apps.sql +14 -0
- package/register/0001-baseline/13-apps-name-key.sql +1 -0
- package/register/0001-baseline/14-apps-owner-idx.sql +1 -0
- package/register/0001-baseline/15-contexts.sql +9 -0
- package/register/0001-baseline/16-credit-ledger.sql +10 -0
- package/register/0001-baseline/17-credit-ledger-user.sql +1 -0
- package/register/0001-baseline/18-runs.sql +16 -0
- package/register/0001-baseline/19-sessions.sql +10 -0
- package/register/0001-baseline/20-sessions-user-idx.sql +1 -0
- package/register/0001-baseline/21-app-chunks.sql +7 -0
- package/register/0001-baseline/22-context-members.sql +10 -0
- package/register/0002-orgs/01-orgs.sql +14 -0
- package/register/0002-orgs/02-orgs-name-key.sql +1 -0
- package/register/0002-orgs/03-org-members.sql +10 -0
- package/register/0002-orgs/04-org-members-user-idx.sql +1 -0
- package/register/0002-orgs/05-apps-org-id.sql +1 -0
- package/register/0002-orgs/06-apps-org-idx.sql +1 -0
- package/register/0002-orgs/07-apps-org-name-key.sql +1 -0
- package/register/0002-orgs/08-credit-ledger-org-id.sql +1 -0
- package/register/0002-orgs/09-credit-ledger-org-idx.sql +1 -0
- package/register/0002-orgs/10-api-tokens-org-id.sql +1 -0
- package/register/0002-orgs/11-api-tokens-created-by.sql +1 -0
- package/register/0002-orgs/12-backfill-personal-orgs.sql +15 -0
- package/register/0002-orgs/13-backfill-org-members.sql +12 -0
- package/register/0002-orgs/14-backfill-apps-org.sql +14 -0
- package/register/0002-orgs/15-backfill-credit-ledger-org.sql +11 -0
- package/register/0002-orgs/16-backfill-api-tokens-org.sql +12 -0
- package/register/README.md +73 -0
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
-- A token names its own organisation, which is what answers "whose data is
|
|
2
|
+
-- this" for a request that arrives with no session behind it.
|
|
3
|
+
--
|
|
4
|
+
-- `created_by` keeps the person, because a token is minted by somebody and a
|
|
5
|
+
-- revoked key is only findable if the register remembers who made it. The
|
|
6
|
+
-- organisation is the tenancy; the user is the provenance — the same split
|
|
7
|
+
-- `apps` makes between `org_id` and `owner_id`.
|
|
8
|
+
update api_tokens t
|
|
9
|
+
set org_id = o.id, created_by = coalesce(t.created_by, t.user_id)
|
|
10
|
+
from users u
|
|
11
|
+
join orgs o on lower(o.name) = lower(u.username) and o.kind = 'personal'
|
|
12
|
+
where u.id = t.user_id and t.org_id is null;
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
# The register's own schema
|
|
2
|
+
|
|
3
|
+
`.heychunky/migrations` is how an *app's* database changes: files ride the
|
|
4
|
+
branch, and `_heychunky_migrations` records what each database has applied. The
|
|
5
|
+
register had no equivalent — it is not an app and has no repository of its own,
|
|
6
|
+
so its schema lived only in the database and in whoever remembered typing it.
|
|
7
|
+
|
|
8
|
+
It has one now. This directory is that repository, and the mechanism is the
|
|
9
|
+
same one an app gets rather than a second one.
|
|
10
|
+
|
|
11
|
+
```
|
|
12
|
+
register/
|
|
13
|
+
0001-baseline/ the register as it stood on 2026-09-08, 22 statements
|
|
14
|
+
0002-orgs/ organisations, the tenancy boundary — 16 statements
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
**A change is a directory, its statements numbered inside it.** One statement
|
|
18
|
+
per file, because the database client sends one query per request and answers a
|
|
19
|
+
string holding two as though all was well. The ledger id is the path —
|
|
20
|
+
`0002-orgs/05-apps-org-id.sql` — so what a database has applied reads as whole
|
|
21
|
+
changes rather than as filenames somebody has to regroup mentally.
|
|
22
|
+
|
|
23
|
+
Both numbers pad, because everything sorts lexically.
|
|
24
|
+
|
|
25
|
+
## Applying it
|
|
26
|
+
|
|
27
|
+
```
|
|
28
|
+
heychunky register what it has, and what it owes
|
|
29
|
+
heychunky register migrate --confirm apply what it owes
|
|
30
|
+
heychunky register verify what must be true of the rows
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
All four take `--app <app> --env <environment>` to reach a register other than
|
|
34
|
+
the factory's own. There is more than one: heychunky-app runs in six
|
|
35
|
+
environments and each has a database of this shape, which is how the schema
|
|
36
|
+
reaches the one the tests and the dev deployment use.
|
|
37
|
+
|
|
38
|
+
The files are read from the installed Core rather than from a repository at a
|
|
39
|
+
ref, which is the one place this differs from an app's migrations. An app's
|
|
40
|
+
files ride the branch, because "what does staging still owe" has to be
|
|
41
|
+
answerable from the branch alone. The register has one database and no ladder,
|
|
42
|
+
so the schema it can be brought to is the schema its CLI was built against —
|
|
43
|
+
and no unreviewed local edit can reach it by accident.
|
|
44
|
+
|
|
45
|
+
## Adopting, for a database that predates the ledger
|
|
46
|
+
|
|
47
|
+
The baseline is a record before it is a script. The live register already held
|
|
48
|
+
every statement in it, so running it would fail on the first `create table`:
|
|
49
|
+
|
|
50
|
+
```
|
|
51
|
+
heychunky register adopt 0001-baseline --confirm
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
That records the statements as applied having run none of them. It is **checked
|
|
55
|
+
rather than trusted** — every statement's table or index is looked up in the
|
|
56
|
+
catalog first, and a change that is not entirely true of the register is refused
|
|
57
|
+
with the missing pieces named. The failure it guards is invisible otherwise: a
|
|
58
|
+
false receipt, and then a schema change silently skipped forever after.
|
|
59
|
+
|
|
60
|
+
It found real drift the first time it ran. The factory's dev register had no
|
|
61
|
+
`runs` table where production did, so the honest sequence there was to apply
|
|
62
|
+
that one statement and adopt the rest. A single statement id is accepted as well
|
|
63
|
+
as a change name, which is how that is done.
|
|
64
|
+
|
|
65
|
+
## What is deliberately not enforced
|
|
66
|
+
|
|
67
|
+
**Deleting a user leaves their personal organisation behind.** `org_members`
|
|
68
|
+
cascades; `orgs` does not, because an organisation outlives the people in it —
|
|
69
|
+
and no foreign key can say "except the personal one". There is no delete-a-user
|
|
70
|
+
path in the product today, so the invariant is left to `register verify`, which
|
|
71
|
+
counts a personal organisation whose name is nobody's username. When deleting a
|
|
72
|
+
user becomes a real operation it deletes the organisation too, and that check is
|
|
73
|
+
what will catch anyone who forgets.
|