Skip to content

Commit 28e7428

Browse files
authored
Integrate Seren API-key flow (#48)
* feat: integrate Seren API-key flow * chore: fmt main
1 parent dd53ed5 commit 28e7428

24 files changed

Lines changed: 1948 additions & 142 deletions

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,9 @@ Thumbs.db
2121
# Local AI/Agent configuration
2222
CLAUDE.md
2323
AGENTS.md
24+
GEMINI.md
2425

2526
# Local documentation (not for repo)
2627
docs/20251127_AlphaGrowth_Testing_Bugs.md
2728
docs/design-onboarding-improvements.md
28-
docs/plans/
29+
docs/plans/

Cargo.lock

Lines changed: 138 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ categories = ["command-line-utilities", "database"]
1414
[dependencies]
1515
tokio = { version = "1.35", features = ["full"] }
1616
tokio-postgres = { version = "0.7", features = ["with-serde_json-1"] }
17-
clap = { version = "4.4", features = ["derive"] }
17+
clap = { version = "4.4", features = ["derive", "env"] }
1818
anyhow = "1.0"
1919
tracing = "0.1"
2020
tracing-subscriber = { version = "0.3", features = ["env-filter"] }
@@ -37,3 +37,21 @@ base64 = "0.21"
3737
mongodb = "3.4"
3838
bson = "2.9"
3939
mysql_async = "0.34"
40+
dirs = "5.0"
41+
url = "2.5"
42+
chrono = { version = "0.4", default-features = false, features = ["clock"] }
43+
44+
[[test]]
45+
name = "fallback_test"
46+
path = "tests/fallback_test.rs"
47+
doc = false
48+
49+
[[test]]
50+
name = "state_test"
51+
path = "tests/state_test.rs"
52+
doc = false
53+
54+
[[test]]
55+
name = "interactive_serendb_test"
56+
path = "tests/interactive_serendb_test.rs"
57+
doc = false

README.md

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,31 @@ SerenAI provides managed PostgreSQL databases optimized for AI workloads. When r
2424
- Job monitoring and logging
2525
- Optimized for large database transfers
2626

27-
To replicate to SerenDB, simply run:
27+
### Option 1: Interactive Project Selection (Recommended)
28+
29+
With just your API key set, the tool will interactively guide you through selecting your target project and database:
30+
2831
```bash
2932
export SEREN_API_KEY="your-api-key" # Get from console.serendb.com
33+
34+
database-replicator init \
35+
--source "postgresql://user:pass@source:5432/db" \
36+
--local
37+
```
38+
39+
The tool will:
40+
41+
1. Show a picker to select your SerenDB project
42+
2. Automatically enable logical replication if needed
43+
3. Create missing databases on the target
44+
4. Save your selection for future `sync` commands
45+
46+
### Option 2: Explicit Connection String
47+
48+
If you already have your connection string, you can provide it directly:
49+
50+
```bash
51+
export SEREN_API_KEY="your-api-key"
3052
database-replicator init \
3153
--source "postgresql://user:pass@source:5432/db" \
3254
--target "postgresql://user:pass@your-db.serendb.com:5432/db"
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
I've got an idea I want to talk through with you. I'd like you to help me turn it into a fully formed design and spec (and eventually an implementation plan) Check out the current state of the project in our working directory to understand where we're starting off and then check the idea details below. Once done, ask me questions, one at a time, to help refine the idea. Ideally, the questions would be multiple choice, but open-ended questions are OK, too. Don't forget: only one question per message. Once you believe you understand what we're doing, stop and describe the design to me, in sections of maybe 200-300 words at a time, asking after each section whether it looks right so far. Keep in mind that whatever we fix here will affect the upstream repo /Users/taariqlewis/Projects/Seren_Projects/seren-replicator so all changes must be refactored upstream.
2+
3+
Here's the idea
4+
5+
1.would it be better UI/UX to remove the need for users to use the connecton string in the CLI for the databse the replicator/
6+
2. Instead have users use their SerenDB API key Alone
7+
3. The API Key allows users to lists all projects and all databases so the user just needs to select their target database to replicate against.
8+
4. And then the connection_string can be read from the project by the database replicator instead of the user entering it. Easier UI/UX.
9+
5. This will also fix the `sync` issue where there's no direct API to look up a project by endpoint hostname.
10+
6. The API is setup for users to adjust settings on project.
11+
7. When init is run, the user selects their target project and then database. No more need for connection string.
12+
8. When sync is run, the system selects their already targeted project and database so they are syncing to the same database. We want to avoid users having to be confused by different branches so just make sure they are syncing to same database.
13+
9. Existing APIs:
14+
15+
GET /api/projects → List user's projects
16+
GET /api/projects/{project_id}/replication → Get replication settings
17+
PATCH /api/projects/{project_id}/replication → Enable logical replication (set enabled: true)
18+
GET /api/projects/{project_id}/branches → List branches
19+
GET /api/projects/{project_id}/branches/{branch_id}/endpoints → List endpoints
20+
GET /api/projects/{project_id}/branches/{branch_id}/databases → List databases
21+
22+
10. Proposed UPDATED Replicator flow:
23+
24+
USER enters their API KEY
25+
GET /api/projects → Show project picker
26+
GET /api/projects/{id}/replication → Check if logical replication is enabled
27+
If not enabled: PATCH /api/projects/{id}/replication with {"enabled": true}
28+
USE the DEFAUTL branch from the project
29+
GET /api/projects/{id}/branches/{bid}/databases → Show database picker
30+
Start replication using the selected database's connection string
31+
Store replication target for sync run so that sync is to the same replication target.
32+

src/commands/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,13 @@
44
pub mod init;
55
pub mod status;
66
pub mod sync;
7+
pub mod target;
78
pub mod validate;
89
pub mod verify;
910

1011
pub use init::init;
1112
pub use status::status;
1213
pub use sync::sync;
14+
pub use target::command as target;
1315
pub use validate::validate;
1416
pub use verify::verify;

0 commit comments

Comments
 (0)