You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit c99a446
Browse filesBrowse the repository at this point in the historyBrowse files
Copy file name to clipboardExpand all lines: ee/packages/den-db/README.md
+47-38Lines changed: 47 additions & 38 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -9,46 +9,55 @@
9
9
- Always generate new migrations with Drizzle from this package.
10
10
- Do not create migrations from `den-api`, `den-controller`, or other apps.
11
11
12
-
## Commands
13
-
14
-
Generate a migration after editing the schema:
15
-
16
-
```bash
17
-
pnpm --dir ee/packages/den-db db:generate
18
-
```
19
-
20
-
Apply schema directly to a development database:
21
-
22
-
```bash
23
-
pnpm --dir ee/packages/den-db db:push
24
-
```
25
-
26
-
Run Drizzle migrations against a configured database:
27
-
28
-
```bash
29
-
pnpm --dir ee/packages/den-db db:migrate
12
+
## Install or upgrade Den
13
+
14
+
| Database and starting state | What to run | What happens |
15
+
| --- | --- | --- |
16
+
| Local MySQL | Run `pnpm dev:web-local`. To inspect first, set a loopback `DATABASE_URL` and run `pnpm --dir ee/packages/den-db db:migrate:local --check`. | On first startup, the runner replays from the historical foundation. On upgrade, it checks the schema and journal before applying pending SQL. It runs repairs and verifies the final schema and receipts before services start. Stop other connections before applying. See [local startup safety](#local-startup-safety). |
17
+
| Hosted PlanetScale | The [Den DB Migrate workflow](../../../.github/workflows/den-db-migrate.yml) runs on selected pushes to `dev`, on a schedule, or by manual dispatch. | On the existing production branch it opens a DDL window for pending migrations, runs `db:migrate`, and restores safe migrations. Check the workflow result for confirmation that safe migrations were re-enabled. |
18
+
| Self-hosted Den, empty database | Run the release image's migration job before starting Den. It executes `node /app/ee/packages/den-db/dist/scripts/bootstrap.js`. | Bootstrap installs the image's current-schema snapshot and records the bundled migration history as its baseline. The historical chain starts by altering existing tables. |
19
+
| Self-hosted Den, existing database | Run the same migration job from the **new** release before rolling out its services. For a pending 0097, follow the [0097 upgrade preconditions](#production-0097-upgrade-preconditions) first. | Bootstrap checks recorded history and applies pending migrations. An existing schema without a journal or with an unknown history needs deliberate recovery. Inspect an interrupted migration before retrying. |
20
+
21
+
Hosted `db:migrate` applies journaled SQL, runs schema repairs, then reconciles
22
+
default permission sets. The workflow also runs reconciliation separately so
23
+
permission catalog changes take effect even when there is no pending migration.
24
+
25
+
The self-hosted job runs schema repairs and attempts permission reconciliation
26
+
on fresh installs as well as upgrades. Reconciliation fills missing default
27
+
Member and Admin permission rows and is idempotent. Bootstrap logs a
28
+
reconciliation failure and continues. If it reports one, correct the cause and
29
+
rerun `pnpm --dir ee/packages/den-db db:reconcile-permissions` with the same
30
+
database configuration from a source checkout. The local migration runner
31
+
handles schema and receipts only.
32
+
33
+
## Development commands
34
+
35
+
- Generate SQL after a schema edit with `pnpm --dir ee/packages/den-db db:generate`.
36
+
- Apply the guarded local upgrade directly with `pnpm --dir ee/packages/den-db db:migrate:local` and a loopback `DATABASE_URL`.
37
+
- Use `pnpm --dir ee/packages/den-db db:push` only on a disposable development database. Direct schema pushes do not record the migration history used by upgrades.
38
+
- To run self-hosted bootstrap from a source checkout, build the workspace dependencies with `pnpm --filter '@openwork-ee/den-db^...' --if-present run build`, then run `pnpm --dir ee/packages/den-db db:bootstrap` against the intended database.
39
+
40
+
## Verify installs and upgrades locally
41
+
42
+
The [MySQL fixture](test/migration-preserved-tables.mysql.test.ts) uses Linux
43
+
MySQL 8.4 with case-sensitive table names (`lower_case_table_names=0`).
44
+
Set `OPENWORK_MIGRATION_TEST_MYSQL_URL` to a disposable loopback MySQL URL
45
+
whose database name begins with `exp_`. The fixture account needs permission
46
+
to create and drop temporary databases on that server. The test skips if the
47
+
variable is absent.
48
+
49
+
Run from the repository root with workspace dependencies installed.
50
+
51
+
```sh
52
+
pnpm --filter '@openwork-ee/den-db...' --if-present run build
}catch{assert.fail("Compiled bootstrap failed (driver output withheld); build den-db and its workspace dependencies before this test")}
78
+
}
51
79
try{
52
80
const[server]=awaitadmin.query<mysql.RowDataPacket[]>("SELECT VERSION() AS version, @@version_compile_os AS os, @@lower_case_table_names AS case_mode")
awaitt.test("fresh replay cannot silently switch to bootstrap if both preserved tables disappear before final verification",async()=>database(async(_quarantine,quarantineUrl)=>database(async(executor)=>{
0 commit comments