Run your instance
Upgrade misomoon
New versions are listed in the changelog and on the releases page. Read the notes for every version between yours and the new one before you upgrade.
An upgrade keeps your data. The deploy applies new migrations to every database, and migrations only add to the schema. To roll back, deploy the previous version again. The extra columns or tables that a newer migration added stay, and the older code ignores them.
Upgrade a command-line install
Get the new version:
git pull pnpm installIf you keep your own fork, merge the upstream
mainbranch into it instead. Keep your database ids inapps/api/wrangler.jsonc.Deploy:
pnpm --filter @misomoon/api run deployThe deploy applies new migrations, and then deploys the Worker.
Upgrade a Deploy to Cloudflare install
The button copied the deploy bundle into a repository that you own. Cloudflare deploys
that repository again each time you push to it. To upgrade, copy the new bundle into
your repository, and keep your own wrangler.jsonc, which holds your database ids.
Clone your repository, and go into it:
git clone https://github.com/<you>/<your-repo>.git cd <your-repo>Download the latest bundle:
curl -L https://github.com/jackzard/misomoon/archive/refs/heads/deploy.tar.gz | tar xzCopy it over your files, but keep your
wrangler.jsonc:rsync -a --exclude wrangler.jsonc misomoon-deploy/misomoon/ ./ rm -rf misomoon-deployCompare the new
wrangler.jsoncwith yours:curl -sL https://raw.githubusercontent.com/jackzard/misomoon/deploy/misomoon/wrangler.jsonc | diff wrangler.jsonc -Copy new settings into your file, such as a new variable or a new
compatibility_date. Don't copy thedatabase_idvalues.Commit and push:
git add -A git commit -m "Upgrade misomoon" git pushCloudflare builds and deploys the push. The
deployscript applies the new migrations first.
Scale the shards
Events and visits live in the shard databases. A D1 database holds up to 10 GB. When a
shard reaches SHARD_SOFT_LIMIT_MB (8,000 MB by default), it stops taking new days of
data, and its sites continue on another shard. Add shards before every shard is near
the limit. To see the size of each database, open Storage & Databases > D1 in
the Cloudflare dashboard.
More shards also spread the writes. One D1 database handles one write at a time, so a busy instance with many sites is faster with more shards.
Command-line installs
Set SHARD_COUNT to the number of shards you want, and deploy:
SHARD_COUNT=4 pnpm --filter @misomoon/api run deployThe deploy creates the new databases, binds them, migrates them, and deploys. A new
shard registers itself on the next request, and it takes most new sites because it has
the most free space. To see the plan without changing anything, add --plan:
SHARD_COUNT=4 pnpm --filter @misomoon/api run deploy -- --planTo remove shards, deploy with a smaller SHARD_COUNT. The extra shards are marked
retiring, and the Worker moves their data to the other shards every 5 minutes. Run
the same deploy again later. It unbinds each retiring shard after it is empty. The
script never deletes a database. Delete an empty one yourself with
wrangler d1 delete <name>.
Deploy to Cloudflare installs
Create a database:
npx wrangler d1 create misomoon-shard-2If your other databases are in the EU jurisdiction, add
--jurisdiction eu.Add it to
d1_databasesin yourwrangler.jsonc, with the id that the command printed:{ "binding": "SHARD_2", "database_name": "misomoon-shard-2", "database_id": "<id>", "migrations_dir": "migrations/shard" }Commit and push. The
deployscript migrates everySHARD_*binding, and the new shard registers itself.
To remove a shard from this kind of install, use a command-line install, because the data has to move first.