KKIMS on-site docs
Local rehearsal

Local database and content load

Run the migrations, load the handover's data bundle into the local PostgreSQL and S3 stand-in, check the row counts, and reload from scratch when you need to.

This page creates every table with the repo's migrations, then loads the real content and media from the handover's data bundle: 13,247 rows into five tables and 11,307 files into the kims-assets bucket. It is the same load you will run on KIMS from a one-off pod (Content load), so doing it here first proves the bundle you carry.

All commands that name local/docker-compose.yml run from the repo (<KIMS_FOLDER>/repos/kims-v2). deploy.mjs commands run from <KIMS_FOLDER>.

#Before you start

  • Postgres and the S3 stand-in are running and healthy, and the buckets exist: Services.
  • The handover zip is extracted to <KIMS_FOLDER>/KIMS-v2-handover-2026-11-24, with data-bundle/MANIFEST.json in it: Get the code.

#Quick way

Run from <KIMS_FOLDER>:

bash
node deployment-steps/scripts/deploy.mjs local db up
node deployment-steps/scripts/deploy.mjs local db seed
bash
node deployment-steps/scripts/deploy.mjs local db up
node deployment-steps/scripts/deploy.mjs local db seed
powershell
node deployment-steps/scripts/deploy.mjs local db up
node deployment-steps/scripts/deploy.mjs local db seed

db up ends OK: database kims on 127.0.0.1:5418 is up to date. db seed ends OK: kims is seeded from the bundle. Both are safe to run again:

  • If the database already holds exactly the bundle's row counts, db seed says already holds this bundle. Nothing to do.
  • If it holds different counts (you edited content in the CMS since), it warns, changes nothing, and points you at db reseed.
  • If some content tables are empty and others aren't (a broken half-load), it stops and tells you to reseed.

--bundle <path> uses a bundle somewhere else. --database <name> works on another database on the same server (for example kims_scratch), so you can try things without touching kims.

#Check the bundle first

The load checks every checksum itself, but checking first takes a few seconds and needs no services. Run from the repo:

bash
node scripts/handover/data-bundle.mjs check --from ../../KIMS-v2-handover-2026-11-24/data-bundle
bash
node scripts/handover/data-bundle.mjs check --from ../../KIMS-v2-handover-2026-11-24/data-bundle
powershell
node scripts/handover/data-bundle.mjs check --from ../../KIMS-v2-handover-2026-11-24/data-bundle

It counts up to 11000 of 11307 and ends:

text
bundle ok: 13247 rows, 11307 objects, made 2026-11-24T14:03:17.744Z

The same check is node deployment-steps/scripts/deploy.mjs kims bundle check from <KIMS_FOLDER>, which also prints the size and the migrations the bundle was made with.

#Run the migrations

#What they are

Plain SQL files in db/migrations, applied in name order by packages/db/src/cli.ts. Each applied file is recorded in the schema_migrations table, so running them again applies only new ones. There are 8 today: 0001_foundation, 0100_content_store, 0200_cms_users_and_sessions, 0300_jobs, 0301_secrets, 0400_media_assets, 0500_site_builds, 0501_site_builds_jenkins_number. The first one creates the citext extension.

On KIMS the same files run from the chart's kims-migrate Job, before every install and upgrade.

#1. Run them

Run from the repo:

bash
npm run db:migrate
bash
npm run db:migrate
powershell
npm run db:migrate

The first time it ends [migrate] done: 8 applied, 0 already in place. After that, 0 applied, 8 already in place.

Note

In PowerShell the line shows in red, wrapped in NativeCommandError. That is only because the runner writes to stderr. It worked if the line says done.

#2. Check them

bash
docker compose -f local/docker-compose.yml exec -T postgres psql -U kims -d kims -tAc "select count(*) from schema_migrations"
bash
docker compose -f local/docker-compose.yml exec -T postgres psql -U kims -d kims -tAc "select count(*) from schema_migrations"
powershell
docker compose -f local/docker-compose.yml exec -T postgres psql -U kims -d kims -tAc "select count(*) from schema_migrations"

You should see 8, one per .sql file in db/migrations.

Warning

Never edit a migration file once it has been applied anywhere. Add a new file instead. An edited file is not re-run, so the databases drift apart.

#Load the data bundle

#1. Check the database is empty

The load refuses a database that already has content: it never merges. Run from the repo:

bash
docker compose -f local/docker-compose.yml exec -T postgres psql -U kims -d kims -tAc "select count(*) from state_objects"
bash
docker compose -f local/docker-compose.yml exec -T postgres psql -U kims -d kims -tAc "select count(*) from state_objects"
powershell
docker compose -f local/docker-compose.yml exec -T postgres psql -U kims -d kims -tAc "select count(*) from state_objects"

You should see 0. Any other number means it is already loaded: skip to Check the counts, or see Load it again from scratch.

#2. Run the load

Run from the repo:

bash
node --env-file=.env.local scripts/handover/data-bundle.mjs load --from ../../KIMS-v2-handover-2026-11-24/data-bundle
bash
node --env-file=.env.local scripts/handover/data-bundle.mjs load --from ../../KIMS-v2-handover-2026-11-24/data-bundle
powershell
node --env-file=.env.local scripts/handover/data-bundle.mjs load --from ../../KIMS-v2-handover-2026-11-24/data-bundle

What it does, in order:

  1. Checks every file against MANIFEST.json (bundle ok: 13247 rows, 11307 objects, ...).
  2. Refuses a database that is missing a migration the bundle was made with, or whose content tables are not empty.
  3. Uploads the media to kims-assets, skipping any file already there at the same size (objects: 11307 uploaded, 0 already there the first time).
  4. Writes all the rows in one transaction, then prints each table's row count and load finished.

About 15 seconds when the media is already in the bucket, a few minutes when it isn't. --concurrency <n> changes how many uploads run at once (default 8).

If it stops part way, nothing is written to the database. Files already uploaded are skipped next time, so just run it again.

#What the bundle brings, and what it doesn't

Table Rows What it is
publish_versions 1 The published version: the content arrives as version 1
published_files 2,750 That version's files (the website reads these)
state_objects 8,274 Every content entry, with drafts and history
media_assets 1,102 The media library's records
media_usage 1,120 Which content uses which media

Not in the bundle: CMS people and sessions (they come from Keycloak and the People screen), jobs, site build history, and stored Google secrets (they were encrypted with the old environment's SECRETS_KEY, so they could not be read here anyway).

#Check the counts

#Quick way

node deployment-steps/scripts/deploy.mjs local db seed, run again from <KIMS_FOLDER>, prints rows now / in the bundle for the five tables and says whether they match.

#By hand

Run from the repo:

bash
docker compose -f local/docker-compose.yml exec -T postgres psql -U kims -d kims -c "select 'publish_versions' t, count(*) from publish_versions union all select 'published_files', count(*) from published_files union all select 'state_objects', count(*) from state_objects union all select 'media_assets', count(*) from media_assets union all select 'media_usage', count(*) from media_usage"
bash
docker compose -f local/docker-compose.yml exec -T postgres psql -U kims -d kims -c "select 'publish_versions' t, count(*) from publish_versions union all select 'published_files', count(*) from published_files union all select 'state_objects', count(*) from state_objects union all select 'media_assets', count(*) from media_assets union all select 'media_usage', count(*) from media_usage"
powershell
docker compose -f local/docker-compose.yml exec -T postgres psql -U kims -d kims -c "select 'publish_versions' t, count(*) from publish_versions union all select 'published_files', count(*) from published_files union all select 'state_objects', count(*) from state_objects union all select 'media_assets', count(*) from media_assets union all select 'media_usage', count(*) from media_usage"

Straight after a load you should see 1, 2,750, 8,274, 1,102 and 1,120. state_objects grows as content is edited in the CMS, and each publish adds a publish_versions row.

#The newest published version

bash
docker compose -f local/docker-compose.yml exec -T postgres psql -U kims -d kims -tAc "select max(version) from publish_versions"
bash
docker compose -f local/docker-compose.yml exec -T postgres psql -U kims -d kims -tAc "select max(version) from publish_versions"
powershell
docker compose -f local/docker-compose.yml exec -T postgres psql -U kims -d kims -tAc "select max(version) from publish_versions"

1 straight after the load. You need this number for a site build.

#The media in the bucket

node deployment-steps/scripts/deploy.mjs local storage up (from <KIMS_FOLDER>) ends with kims-assets: N objects. After the load, N is 11,307 or more.

#Load it again from scratch

To throw away everything in the local kims database and load the bundle fresh. This deletes CMS edits, CMS people, sessions, jobs, build history and stored Google secrets. Keycloak's database is not touched. The media already in the bucket is kept and not uploaded again.

#Quick way

Run from <KIMS_FOLDER>. Without --yes it only lists what is in the database (content entries, versions, media records, CMS people, sessions, jobs, site builds, stored secrets) and stops:

bash
node deployment-steps/scripts/deploy.mjs local db reseed
node deployment-steps/scripts/deploy.mjs local db reseed --yes
bash
node deployment-steps/scripts/deploy.mjs local db reseed
node deployment-steps/scripts/deploy.mjs local db reseed --yes
powershell
node deployment-steps/scripts/deploy.mjs local db reseed
node deployment-steps/scripts/deploy.mjs local db reseed --yes

With --yes it drops the database (closing open connections), creates it, migrates it, loads the bundle and checks the counts. It ends OK: kims recreated and seeded from the bundle. It refuses a DATABASE_URL that isn't on your machine, and the postgres and keycloak databases.

Afterwards restart the CMS and worker if they were running. The first Admin comes back through KIMS_BOOTSTRAP_ADMINS on their next sign-in; everyone else must be added again on the People screen.

#By hand

  1. Stop the CMS and the worker (Run the apps).
  2. Drop and recreate the database. Run from the repo:
bash
docker compose -f local/docker-compose.yml exec -T postgres psql -U kims -d postgres -c "drop database kims with (force)" -c "create database kims"
bash
docker compose -f local/docker-compose.yml exec -T postgres psql -U kims -d postgres -c "drop database kims with (force)" -c "create database kims"
powershell
docker compose -f local/docker-compose.yml exec -T postgres psql -U kims -d postgres -c "drop database kims with (force)" -c "create database kims"

You should see DROP DATABASE and CREATE DATABASE.

  1. Run the migrations again (Run them).
  2. Load the bundle again (Run the load).

#Trying things on a scratch database

Every local db command takes --database <name> (lower case letters, digits and _). For example, from <KIMS_FOLDER>:

bash
node deployment-steps/scripts/deploy.mjs local db up --database kims_scratch
node deployment-steps/scripts/deploy.mjs local db seed --database kims_scratch

The same lines work in PowerShell. The apps still use the database in .env.local.

#If it goes wrong

What you see Likely cause What to do
publish_versions already has N rows; load only goes into an empty database Already loaded Nothing to do, or load it again from scratch
The database is missing migrations the bundle was made with Migrations not run Run them, then load again
The bundle does not match its manifest (N problems) The copy is damaged or incomplete Extract the handover zip again (Get the code) and check it
load fails with ECONNREFUSED on port 9100 The S3 stand-in isn't running Services
npm run db:migrate fails with ECONNREFUSED 127.0.0.1:5418 Postgres isn't up yet Start it and wait for Healthy
Can't start: the database kims_scratch doesn't exist db seed on a database db up hasn't made Run db up --database kims_scratch first
Can't start: ... is half loaded Some content tables empty, others not local db reseed --yes
drop database says it is being accessed by other users Older Postgres syntax, or with (force) left off Use the command exactly as above; with (force) closes the other connections

#Sources

Built 2026-11-29. Commands are shown for the system picked at the top; every block has all three.