|
| 1 | +--- |
| 2 | +title: Migrate to dual bucket architecture |
| 3 | +description: Learn how to migrate from single bucket to dual bucket architecture |
| 4 | +--- |
| 5 | + |
| 6 | +In order to make MediaLit truly vendor agnostic, we decided to move from a single bucket architecture to a dual bucket architecture. |
| 7 | + |
| 8 | +This is based on our years of learning from running MediaLit in production and all the community feedback we have received over the years. |
| 9 | + |
| 10 | +## Why dual bucket architecture? |
| 11 | + |
| 12 | +This makes the architecture portable across cloud providers. We discovered that providers like Backblaze B2 does not support hosting both private and public files in the same bucket. |
| 13 | + |
| 14 | +## How to migrate to dual bucket architecture? |
| 15 | + |
| 16 | +1. Create new buckets as detailed in [Self hosting](/self-hosting) section. |
| 17 | + |
| 18 | +2. Copy data from the old bucket to the new bucket. To do this, you will have to checkout MediaLit's Git [repo](https://github.com/codelitdev/medialit), then do the following in the terminal |
| 19 | + |
| 20 | +```sh |
| 21 | +cd <medialit-repo> |
| 22 | +pnpm i |
| 23 | +pnpm --filter @medialit/scripts migrate:dual_bucket_architecture --dry-run # To see the changes without actually performing those |
| 24 | +pnpm --filter @medialit/scripts migrate:dual_bucket_architecture |
| 25 | +``` |
| 26 | +3. Upgrade the MediaLit DB by running the following migration, by logging into your MediaLit's database and copy pasting the content of the file. |
| 27 | + |
| 28 | +`.migrations/00005-migrate-to-dual-bucket-architecture` |
| 29 | + |
| 30 | +4. Update .env file for the MediaLit API container. |
| 31 | + |
| 32 | +```sh |
| 33 | +CLOUD_BUCKET_NAME=your-private-bucket |
| 34 | +CLOUD_PUBLIC_BUCKET_NAME=your-public-bucket |
| 35 | +PATH_PREFIX=bucket-folder-to-place-the-files-in # This is optional |
| 36 | +CDN_ENDPOINT=endpoint |
| 37 | + |
| 38 | +# Optional, if using Cloudfront |
| 39 | +ACCESS_PRIVATE_BUCKET_VIA_CLOUDFRONT=true |
| 40 | +CLOUDFRONT_KEY_PAIR_ID=key |
| 41 | +CLOUDFRONT_PRIVATE_KEY=priv-key |
| 42 | +``` |
| 43 | + |
| 44 | +5. Re-deploy the MediaLit API container. |
| 45 | +``` |
| 46 | +docker compose pull |
| 47 | +docker compose down |
| 48 | +docker compose up -d |
| 49 | +``` |
0 commit comments