Skip to content

feat: add configurable backup file prefix - #356

Merged
RambokDev merged 3 commits into
Portabase:devfrom
Antoninj:codex/configurable-s3-prefix
Jul 21, 2026
Merged

feat: add configurable backup file prefix#356
RambokDev merged 3 commits into
Portabase:devfrom
Antoninj:codex/configurable-s3-prefix

Conversation

@Antoninj

@Antoninj Antoninj commented Jul 5, 2026

Copy link
Copy Markdown
Contributor

Summary

Adds an optional dashboard environment variable, BACKUP_FILE_PREFIX, for the object-key namespace used when backup files are sent to configured storage channels.

  • Defaults to backups, preserving existing deployments.
  • Normalizes leading/trailing slashes and falls back to backups for an empty value.
  • Includes the normalized prefix in each storage channel sent to agents, including encrypted storage payloads.
  • Documents the variable in .env.example.

Coordinated changes

Deploy this PR together with the agent change before setting a custom prefix.

Validation

  • git diff --check
  • Type-check not run: pnpm is unavailable in the development environment.

Summary by CodeRabbit

  • New Features
    • Added an optional configuration for customizing the storage prefix used for backup files.
    • Backup paths now use the configured prefix while preserving the default backups location.
    • Storage status information now includes the active backup prefix.

@coderabbitai

coderabbitai Bot commented Jul 5, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

Adds optional BACKUP_FILE_PREFIX configuration, documents its default, normalizes the value, and uses it for backup storage paths and database storage-channel responses.

Changes

Backup prefix configuration

Layer / File(s) Summary
Backup prefix configuration
.env.example, src/env.mjs
Documents, validates, loads, and normalizes the optional BACKUP_FILE_PREFIX environment variable, defaulting to backups.
Backup prefix propagation
src/features/storages/utils/storages.helpers.ts, src/features/agents/utils/status/storage-channels.helpers.ts
Uses the normalized prefix in backup paths and includes it in returned storage-channel objects.

Estimated code review effort: 2 (Simple) | ~10 minutes

Possibly related issues

Suggested reviewers: asuniia, rambokdev

Poem

A bunny tuned the backup trail,
With tidy slashes in the gale.
Channels share the prefix too,
And stored files know where to chew.
Hop, hop—defaults guide them through!

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the main change: making the backup file prefix configurable.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@Antoninj
Antoninj marked this pull request as ready for review July 5, 2026 10:06
@Antoninj Antoninj changed the title [codex] Add configurable S3 storage prefix enhancement: add configurable S3 storage prefix Jul 5, 2026
@RambokDev

RambokDev commented Jul 5, 2026

Copy link
Copy Markdown
Collaborator

Hi @Antoninj ,

Could you describe a bit more you use case ?

Tests are in : https://github.com/Portabase/e2e-tests you can are test to it directly

This e2e tests are called in PR, like a component

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/features/channel/components/storages/s3.ts`:
- Around line 34-39: Add unit tests for buildKey to cover the centralized S3 key
normalization logic used by upload/get/delete/ping/copy. Focus on edge cases
around S3Config.prefix and path handling: empty or whitespace-only prefix,
prefix containing only slashes, path values with leading/trailing slashes, and
paths with multiple internal slashes. Use buildKey and S3Config as the main
symbols to locate the behavior and verify the returned key strings for each
case.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: fbc8effb-dc47-40c1-bf7e-80df479d9bde

📥 Commits

Reviewing files that changed from the base of the PR and between 6952ac5 and 8646ec9.

📒 Files selected for processing (3)
  • src/features/channel/components/storages/s3.form.tsx
  • src/features/channel/components/storages/s3.schema.ts
  • src/features/channel/components/storages/s3.ts
📜 Review details
🔇 Additional comments (3)
src/features/channel/components/storages/s3.schema.ts (1)

9-9: LGTM!

src/features/channel/components/storages/s3.form.tsx (1)

87-99: LGTM!

src/features/channel/components/storages/s3.ts (1)

34-39: 🗄️ Data Integrity & Integration

No backward-compatibility issue. prefix is opt-in; existing S3 configs keep using the raw object path, so there’s no key-namespace migration here.

			> Likely an incorrect or invalid review comment.

Comment thread src/features/channel/components/storages/s3.ts Outdated
@Antoninj

Antoninj commented Jul 5, 2026

Copy link
Copy Markdown
Contributor Author

@RambokDev

-> Could you describe a bit more you use case ?

The use case is the following: I use the same S3 bucket for multiple backups (not only portabase ones). Currently, portabase hardcodes the prefix to backups but I would like to configure the name to something else

Tests are in : https://github.com/Portabase/e2e-tests you can are test to it directly
This e2e tests are called in PR, like a component

thanks I'll take a look and see if adding an E2E test makes sense for my changes. But in any case, I'd need to get those changes in first

@Antoninj

Antoninj commented Jul 5, 2026

Copy link
Copy Markdown
Contributor Author

Added E2E coverage in Portabase/e2e-tests#11. It fills the new S3 Prefix field for the existing S3/R2 storage channel flow and verifies the value persists when reopening the channel. I left it as a draft because it depends on this PR introducing the Prefix field.

@RambokDev

Copy link
Copy Markdown
Collaborator

Hi @Antoninj,

I now understand your use case.

This PR will not work as-is because uploads are handled partly on the dashboard side at some point, but mainly by the agent when dispatching backup files to storage after the backup is completed.

What I suggest is adding an environment variable on the dashboard side, for example BACKUP_FILE_PREFIX. If defined, it would override the currently hardcoded /backups prefix and then be passed down to the agent.

I think this would be more generic and would apply consistently across the whole ecosystem.

Could you open an issue so we can continue the discussion there?

I can work on it ASAP, but if you want, you can also start implementing the dashboard-side part, and I can finish the agent-side integration.

Regards,

@Antoninj

Antoninj commented Jul 6, 2026

Copy link
Copy Markdown
Contributor Author

Sounds good I'll do that thanks

@RambokDev

Copy link
Copy Markdown
Collaborator

Sounds good I'll do that thanks

Feel free to ask if you have any questions. I’d be happy to help.

@Antoninj

Antoninj commented Jul 7, 2026

Copy link
Copy Markdown
Contributor Author

Thanks. I won't have time to iterate on this before next week end though.

@RambokDev

Copy link
Copy Markdown
Collaborator

Thanks. I won't have time to iterate on this before next week end though.

No problem, ping me when you have time

@Antoninj
Antoninj force-pushed the codex/configurable-s3-prefix branch from 8646ec9 to 4a77932 Compare July 18, 2026 11:07
@Antoninj Antoninj changed the title enhancement: add configurable S3 storage prefix feat: add configurable backup file prefix Jul 18, 2026

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/features/storages/utils/storages.helpers.ts`:
- Around line 23-25: Update getBackupFilePrefix and the dashboard-to-agent
configuration flow so the same normalized BACKUP_FILE_PREFIX is propagated to
agent-managed backups. Ensure agent uploads and subsequent storage operations
use this prefix instead of defaulting to /backups, while preserving the existing
"backups" fallback when the variable is unset.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: 10e8fbf6-8f74-4174-8bd3-4bf3b08c047f

📥 Commits

Reviewing files that changed from the base of the PR and between 8646ec9 and 4a77932.

📒 Files selected for processing (3)
  • .env.example
  • src/env.mjs
  • src/features/storages/utils/storages.helpers.ts
📜 Review details
🔇 Additional comments (2)
.env.example (1)

76-79: LGTM!

src/env.mjs (1)

69-70: LGTM!

Also applies to: 128-131, 159-159, 215-215

Comment on lines +23 to +25
function getBackupFilePrefix(): string {
return env.BACKUP_FILE_PREFIX?.trim().replace(/^\/+|\/+$/g, "") || "backups";
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🗄️ Data Integrity & Integration | 🟠 Major | 🏗️ Heavy lift

Propagate the prefix to agent-managed backups.

This helper only changes paths created by the dashboard. Agent uploads will continue using their existing /backups prefix unless BACKUP_FILE_PREFIX is included in the dashboard-to-agent configuration contract. That leaves backup sets split across prefixes and can make subsequent storage operations target inconsistent keys. Pass the normalized prefix to the agent, or centralize path construction before applying this dashboard-only change.

Also applies to: 63-63

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/features/storages/utils/storages.helpers.ts` around lines 23 - 25, Update
getBackupFilePrefix and the dashboard-to-agent configuration flow so the same
normalized BACKUP_FILE_PREFIX is propagated to agent-managed backups. Ensure
agent uploads and subsequent storage operations use this prefix instead of
defaulting to /backups, while preserving the existing "backups" fallback when
the variable is unset.

@Antoninj

Copy link
Copy Markdown
Contributor Author

Thanks. I won't have time to iterate on this before next week end though.

No problem, ping me when you have time

I updated the implementation based on your recommendations and linked the PR to an issue in the repo.

@RambokDev
RambokDev changed the base branch from main to dev July 21, 2026 18:14
@RambokDev
RambokDev merged commit 7c896d5 into Portabase:dev Jul 21, 2026
1 check passed
@coderabbitai coderabbitai Bot mentioned this pull request Jul 21, 2026
Merged
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants