Skip to content

Commit

Permalink
Merge pull request #1626 from openkfw/migration-script-v2
Browse files Browse the repository at this point in the history
Add: migration script
  • Loading branch information
mayrmartin authored Jan 31, 2024
2 parents a34f3e5 + f4396c5 commit 1be239e
Show file tree
Hide file tree
Showing 75 changed files with 4,225 additions and 811 deletions.
9 changes: 5 additions & 4 deletions api/src/service/cache2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,6 @@ async function updateCache(ctx: Ctx, conn: ConnToken, onlyStreamName?: string):
newItems.push(...batch);
first += batch.length;
}

// It would be nice to have a `panic!` macro, but whatever:
if (isRebuild && (!newItems.length || !first)) {
logger.fatal(
Expand All @@ -351,9 +350,11 @@ async function updateCache(ctx: Ctx, conn: ConnToken, onlyStreamName?: string):

let cursorToLastItem: StreamCursor | undefined = cursor;
// If there are new items, we update the cursor to point to the latest one:
const lastIndex = first - 1;
const lastTxid = newItems[newItems.length - 1].txid;
cursorToLastItem = { index: lastIndex, txid: lastTxid };
if (newItems.length > 0) {
const lastIndex = first - 1;
const lastTxid = newItems[newItems.length - 1].txid;
cursorToLastItem = { index: lastIndex, txid: lastTxid };
}

if (cursorToLastItem !== undefined) {
cache.streamState.set(streamName, cursorToLastItem);
Expand Down
2 changes: 1 addition & 1 deletion api/src/service/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ export async function revokeGlobalPermission(
logger.debug({ intent, recipient }, "Revoking global permission");
const permissions = await getGlobalPermissionList(conn);

if (Object.keys(permissions).length === 0) {
if (Object.keys(permissions).length == 0) {
throw new VError("No global permissions found, escaping");
}

Expand Down
10 changes: 10 additions & 0 deletions api/src/user_create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,16 @@ export function addHttpHandler(

if (Result.isErr(bodyResult)) {
const { code, body } = toHttpError(new VError(bodyResult, "failed to create user"));
if (code == 409) {
request.log.warn({ warn: bodyResult }, "User already exists, skipping");
reply.status(200).send({
id: serviceUser.id,
displayName: "Name",
organization: "Orga",
address: serviceUser.address,
});
return;
}
request.log.error({ err: bodyResult }, "Invalid request body");
reply.status(code).send(body);
return;
Expand Down
5 changes: 4 additions & 1 deletion docker-compose/api/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
services:
api:
image: trubudget/api:${TAG}
build: ../api
# image: trubudget/api:v2.2.1
environment:
PORT: ${API_PORT}
ORGANIZATION: ${ORGANIZATION}
Expand All @@ -9,6 +10,8 @@ services:
MULTICHAIN_RPC_PORT: ${MULTICHAIN_RPC_PORT}
MULTICHAIN_RPC_USER: ${MULTICHAIN_RPC_USER}
ROOT_SECRET: ${ROOT_SECRET}
DOCUMENT_FEATURE_ENABLED: ${DOCUMENT_FEATURE_ENABLED}
STORAGE_SERVICE_EXTERNAL_URL: ${STORAGE_SERVICE_EXTERNAL_URL}
MULTICHAIN_RPC_PASSWORD: ${MULTICHAIN_RPC_PASSWORD}
BLOCKCHAIN_PORT: ${BLOCKCHAIN_PORT}
JWT_SECRET: ${JWT_SECRET}
Expand Down
20 changes: 7 additions & 13 deletions docker-compose/storage-service/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
version: "3"
services:
storage-service:
image: trubudget/storage-service:${TAG}
build: ../storage-service
# image: trubudget/storage-service:${TAG}
environment:
PORT: ${STORAGE_SERVICE_PORT}
ACCESS_CONTROL_ALLOW_ORIGIN: ${STORAGE_SERVICE_ACCESS_CONTROL_ALLOW_ORIGIN}
Expand All @@ -27,29 +28,22 @@ services:
ports:
- ${MINIO_PORT}:${MINIO_PORT}
healthcheck:
test:
[
"CMD",
"curl",
"-f",
"http://localhost:9000/minio/health/live"
]
test: ["CMD", "curl", "-f", "http://localhost:9000/minio/health/live"]
interval: 30s
timeout: 20s
retries: 3
# networks:
# mynetwork:
# ipv4_address: 172.21.0.3


api:
environment:
DOCUMENT_FEATURE_ENABLED: true
STORAGE_SERVICE_HOST: ${STORAGE_SERVICE_HOST}
STORAGE_SERVICE_PORT: ${STORAGE_SERVICE_PORT}
STORAGE_SERVICE_EXTERNAL_URL: ${STORAGE_SERVICE_EXTERNAL_URL}

frontend:
environment:
STORAGE_SERVICE_HOST: ${STORAGE_SERVICE_HOST}
STORAGE_SERVICE_PORT: ${STORAGE_SERVICE_PORT}
# frontend:
# environment:
# STORAGE_SERVICE_HOST: ${STORAGE_SERVICE_HOST}
# STORAGE_SERVICE_PORT: ${STORAGE_SERVICE_PORT}
3 changes: 2 additions & 1 deletion migration/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ DESTINATION_RPC_PASSWORD=
DESTINATION_RPC_HOST=
BACKUP_FILE_LOCATION=
DESTINATION_BLOCKCHAIN_BASE_URL="http://localhost:8085"
ROOT_SECRET=
ORGANIZATION=
MIGRATION_USER_PASSWORD=
ROOT_SECRET_SOURCE=
ROOT_SECRET_DESTINATION=
11 changes: 5 additions & 6 deletions migration/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

### Migrate an existing TruBudget instance to a new instance

1. Create a backup of your old TruBudget instance. Make sure the source instance uses version 1.30.1
1. Create a backup of your old TruBudget instance. Make sure the source instance uses version 1.30.0
2. Download the latest TruBudget release (2.x), this instance will be the destination instance.
3. With the release of TruBudget 2.0, some environment variables changed. Make sure to adapt the `.env` file on the
destination instance to your need. If you are not already using the operation script now it's a great chance to start
Expand All @@ -12,14 +12,13 @@
- `AUTOSTART: false`
- `NODE_ENV: development`

7. Use the operation script to bootstrap the new set-up. Make sure to enable all desired features (i.e.
storage-service). **If you do not use the operation script make sure the provisioning is disabled!**
7. Use the operation script to bootstrap the new set-up. Make sure to enable all desired features. If you store documents on TruBudget instance, you must enable the document feature as documents will not be stored on chain!
8. Copy the `.env.example` of the migration script to `.env` & set all variables accordingly.
9. Run the migration script using `npm run start`
9. Run the migration script using `npm run build && npm run start`
10. Once the migration finished make sure to set following environment variables on the destination instance by
changing the `.env` file
- AUTOSTART: true
- NODE_ENV: production
- `AUTOSTART: true`
- `NODE_ENV: production`

#### Environment Variables

Expand Down
Loading

0 comments on commit 1be239e

Please sign in to comment.