Skip to content

Commit fbcdc55

Browse files
author
Tapiwa
committed
Migrate Zimpay from Supabase to Appwrite (auth, profiles, transactions)
1 parent 3907953 commit fbcdc55

11 files changed

Lines changed: 531 additions & 12 deletions

add_attributes.ps1

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# Adds all required attributes for profiles and transactions collections
2+
$project = '69e62515000e9e781653'
3+
$key = 'standard_82d94d34809e22342ac2aeda1f6c3f61b12112548ebfcf358ab5d98b4239c9f7d76fab664290734674178d073ac60a478de6f40df491ef7fc926629c989e5e1aee2ec22cd3686e65723e6b9d9883b4ad2e631fda0ce186bfced7ff8983a1843233df115c2614cde9935fed899c5d9f437fcea8732b7b42207b35f7cfea53957e'
4+
$api = 'https://fra.cloud.appwrite.io/v1'
5+
$headers = @{
6+
'X-Appwrite-Project' = $project
7+
'X-Appwrite-Key' = $key
8+
'Content-Type' = 'application/json'
9+
}
10+
11+
# Add attributes to 'profiles' collection
12+
Write-Host "Adding attributes to 'profiles' collection..."
13+
Invoke-RestMethod -Uri "$api/databases/ZimpayDB/collections/profiles/attributes/email" -Method Post -Headers $headers -Body (@{ key='email'; type='string'; size=254; required=$true; array=$false } | ConvertTo-Json)
14+
Invoke-RestMethod -Uri "$api/databases/ZimpayDB/collections/profiles/attributes/full_name" -Method Post -Headers $headers -Body (@{ key='full_name'; type='string'; size=100; required=$true; array=$false } | ConvertTo-Json)
15+
Invoke-RestMethod -Uri "$api/databases/ZimpayDB/collections/profiles/attributes/username" -Method Post -Headers $headers -Body (@{ key='username'; type='string'; size=50; required=$true; array=$false } | ConvertTo-Json)
16+
Invoke-RestMethod -Uri "$api/databases/ZimpayDB/collections/profiles/attributes/phone_number" -Method Post -Headers $headers -Body (@{ key='phone_number'; type='string'; size=32; required=$false; array=$false } | ConvertTo-Json)
17+
Invoke-RestMethod -Uri "$api/databases/ZimpayDB/collections/profiles/attributes/balance" -Method Post -Headers $headers -Body (@{ key='balance'; type='double'; required=$true; array=$false; default=1000 } | ConvertTo-Json)
18+
19+
# Add attributes to 'transactions' collection
20+
Write-Host "Adding attributes to 'transactions' collection..."
21+
Invoke-RestMethod -Uri "$api/databases/ZimpayDB/collections/transactions/attributes/sender_id" -Method Post -Headers $headers -Body (@{ key='sender_id'; type='string'; size=36; required=$true; array=$false } | ConvertTo-Json)
22+
Invoke-RestMethod -Uri "$api/databases/ZimpayDB/collections/transactions/attributes/receiver_id" -Method Post -Headers $headers -Body (@{ key='receiver_id'; type='string'; size=36; required=$true; array=$false } | ConvertTo-Json)
23+
Invoke-RestMethod -Uri "$api/databases/ZimpayDB/collections/transactions/attributes/amount" -Method Post -Headers $headers -Body (@{ key='amount'; type='double'; required=$true; array=$false } | ConvertTo-Json)
24+
Invoke-RestMethod -Uri "$api/databases/ZimpayDB/collections/transactions/attributes/description" -Method Post -Headers $headers -Body (@{ key='description'; type='string'; size=255; required=$false; array=$false } | ConvertTo-Json)
25+
Invoke-RestMethod -Uri "$api/databases/ZimpayDB/collections/transactions/attributes/status" -Method Post -Headers $headers -Body (@{ key='status'; type='string'; size=32; required=$true; array=$false; default='pending' } | ConvertTo-Json)

create_appwrite_attributes.ps1

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
# Reliable attribute creation for Appwrite Collections (Windows PowerShell)
2+
# USAGE: Fill in $apiEndpoint, $projectId, $apiKey, $databaseId, and collection IDs below
3+
# Run in PowerShell from this script's folder.
4+
5+
$apiEndpoint = "https://YOUR_REGION.cloud.appwrite.io/v1" # Set to your Appwrite API endpoint
6+
$projectId = "YOUR_PROJECT_ID"
7+
$apiKey = "YOUR_SECRET_API_KEY"
8+
$databaseId = "YOUR_DATABASE_ID"
9+
10+
# Map of collection IDs and attribute groups (customize as needed)
11+
$collections = @{
12+
"profiles_collection_id" = @(
13+
@{ key = "username"; type = "string"; size = 64; required = $true; unique = $true; array = $false },
14+
@{ key = "full_name"; type = "string"; size = 128; required = $true; array = $false },
15+
@{ key = "email"; type = "email"; required = $true; unique = $true; array = $false },
16+
@{ key = "balance"; type = "float"; required = $true; array = $false; default = 0.0 }
17+
);
18+
"transactions_collection_id" = @(
19+
@{ key = "from_user"; type = "string"; size = 64; required = $true; array = $false },
20+
@{ key = "to_user"; type = "string"; size = 64; required = $true; array = $false },
21+
@{ key = "amount"; type = "float"; required = $true; array = $false },
22+
@{ key = "timestamp"; type = "datetime"; required = $true; array = $false },
23+
@{ key = "status"; type = "enum"; required = $true; array = $false; elements = @("pending", "completed", "failed") },
24+
@{ key = "reference"; type = "string"; size = 32; required = $false; array = $false }
25+
);
26+
}
27+
28+
# Helper: attribute type -> endpoint path
29+
$endpoints = @{
30+
"string" = "/attributes/string";
31+
"email" = "/attributes/email";
32+
"float" = "/attributes/float";
33+
"datetime" = "/attributes/datetime";
34+
"enum" = "/attributes/enum";
35+
}
36+
37+
Write-Host "Starting attribute creation..."
38+
39+
foreach ($collectionId in $collections.Keys) {
40+
$attributes = $collections[$collectionId]
41+
foreach ($attr in $attributes) {
42+
$type = $attr.type
43+
$endpointSuffix = $endpoints[$type]
44+
$url = "$apiEndpoint/databases/$databaseId/collections/$collectionId$endpointSuffix"
45+
46+
# Payload creation
47+
$payload = @{
48+
key = $attr.key
49+
required = $attr.required
50+
array = $attr.array
51+
}
52+
if ($type -eq "string") { $payload.size = $attr.size }
53+
if ($type -eq "enum") { $payload.elements = $attr.elements }
54+
if ($type -eq "float" -and $attr.ContainsKey('default')) { $payload.default = $attr.default }
55+
if ($attr.ContainsKey('unique')) { $payload.unique = $attr.unique }
56+
57+
$payloadJson = $payload | ConvertTo-Json -Compress
58+
$tmpFile = "_appwriteattr_$($collectionId)_$($attr.key).json"
59+
Set-Content -Encoding UTF8 -Path $tmpFile -Value $payloadJson
60+
61+
Write-Host "Creating [$($attr.key)] on collection [$collectionId]..."
62+
$curlArgs = @(
63+
'-X', 'POST',
64+
$url,
65+
'-H', "Content-Type: application/json",
66+
'-H', "X-Appwrite-Project: $projectId",
67+
'-H', "X-Appwrite-Key: $apiKey",
68+
'-d', "@$tmpFile"
69+
)
70+
$result = & curl @curlArgs 2>&1
71+
Write-Host $result
72+
Remove-Item $tmpFile
73+
Start-Sleep -Seconds 1 # Give Appwrite time between calls, recommended by docs
74+
}
75+
}
76+
77+
Write-Host "All attributes attempted. Check your Appwrite Console or verify via API."

create_appwrite_schema.ps1

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# PowerShell script to create ZimpayDB and necessary collections in Appwrite
2+
$project = '69e62515000e9e781653'
3+
$key = 'standard_82d94d34809e22342ac2aeda1f6c3f61b12112548ebfcf358ab5d98b4239c9f7d76fab664290734674178d073ac60a478de6f40df491ef7fc926629c989e5e1aee2ec22cd3686e65723e6b9d9883b4ad2e631fda0ce186bfced7ff8983a1843233df115c2614cde9935fed899c5d9f437fcea8732b7b42207b35f7cfea53957e'
4+
$api = 'https://fra.cloud.appwrite.io/v1'
5+
6+
$headers = @{
7+
'X-Appwrite-Project' = $project
8+
'X-Appwrite-Key' = $key
9+
'Content-Type' = 'application/json'
10+
}
11+
12+
# Database already exists, skip creation
13+
14+
# 2. Create 'profiles' collection
15+
Write-Host "Creating 'profiles' collection..."
16+
$permissionsProfiles = @(
17+
'read("any")',
18+
'create("any")',
19+
'update("users")',
20+
'delete("users")'
21+
)
22+
$bodyProfiles = @{ collectionId='profiles'; name='profiles'; permissions=$permissionsProfiles } | ConvertTo-Json
23+
Invoke-RestMethod -Uri "$api/databases/ZimpayDB/collections" -Method Post -Headers $headers -Body $bodyProfiles
24+
25+
# 3. Create 'transactions' collection
26+
Write-Host "Creating 'transactions' collection..."
27+
$permissionsTransactions = @(
28+
'read("any")',
29+
'create("users")'
30+
)
31+
$bodyTransactions = @{ collectionId='transactions'; name='transactions'; permissions=$permissionsTransactions } | ConvertTo-Json
32+
Invoke-RestMethod -Uri "$api/databases/ZimpayDB/collections" -Method Post -Headers $headers -Body $bodyTransactions

package-lock.json

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

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@
1414
},
1515
"dependencies": {
1616
"@supabase/supabase-js": "^2.89.0",
17+
"appwrite": "^24.2.0",
1718
"libphonenumber-js": "^1.12.33",
19+
"node-appwrite": "^24.0.0",
1820
"react": "^19.2.0",
1921
"react-dom": "^19.2.0",
2022
"react-router-dom": "^7.11.0"

0 commit comments

Comments
 (0)