Migra da Appwrite
Sposta un progetto Appwrite in Aurabase senza reimpostare le password degli utenti: mappa le raccolte su tabelle dedicate PostgreSQL 18 (o un progetto NoSQL con motore MongoDB dedicato), importa hash Argon2id/bcrypt tramite aura.authAdmin.importUsers() e sostituisci le autorizzazioni del documento con PostgreSQL RLS.
Risposta rapida#
Per migrare da Appwrite a Aurabase, esporta le tue raccolte Appwrite tramite Appwrite Server SDK (node-appwrite), caricale in un dedicato PostgreSQL 18 progetto (o in un progetto dedicato Progetto --engine mongodb se desideri raccolte JSON senza schema tramite aura.nosql), importa in batch gli utenti Appwrite con aura.authAdmin.importUsers() (gli hash predefiniti di Appwrite Argon2id e bcrypt funzionano senza password reimposta) e tradurre le regole Permission.read(Role.user()) in policy di sicurezza a livello di riga PostgreSQL.
Mappatura dei componenti#
| Appwrite | Aurabase equivalente | Migration notes |
|---|---|---|
| Appwrite Database e raccolte | Dedicato PostgreSQL 18 o --engine mongodb Progetto NoSQL | Scegli Postgres 18 per SQL relazionale, join, RLS & pgvector; scegli --engine mongodb per documenti JSON flessibili |
Autorizzazioni documento (Role.user(), Role.team()) | Nativo PostgreSQL RLS (auth.uid(), JWT affermazioni) | Valutato all'interno di Postgres su REST, Realtime CDC e MCP |
Appwrite Aut. (argon2 / bcrypt) | Aurabase Autenticazione (OAuth 2.1, Passkey, TOTP MFA) | Gli hash Argon2id e bcrypt vengono importati direttamente (fino a 1.000 utenti/batch) |
| Appwrite Memoria | Sovrano S3 Deposito (SeaweedFS) | S3-bucket compatibili con URL firmati, trasformazioni di immagini e per percorso RLS |
| Appwrite Funzioni | Edge Functions (Deno/TypeScript o WASM) | Porta su standard Deno.serve() e distribuisci con aura functions deploy |
| Appwrite Tempo reale | Aurabase Tempo reale (WebSocket/SSE + NATS CDC) | Postgres CDC con filtro per colonna, Presenza e Trasmissione |
1. Scegli PostgreSQL 18 rispetto al motore NoSQL#
I percorsi Aurabase /v1/nosql esistono solo su un progetto creato con --engine mongodb (aura projects create my-app --engine mongodb). Un progetto PostgreSQL 18 standard utilizza tabelle SQL + jsonb colonne + PostgREST. Scegli PostgreSQL 18 se desideri join, chiavi esterne rigorose, pgvector e SQL completo RLS; scegli motore MongoDB solo se la tua app fa molto affidamento su raccolte BSON/JSON senza schema e pipeline di aggregazione.
2. Esporta e carica raccolte Appwrite#
Utilizza node-appwrite per impaginare ogni raccolta (Query.limit(100) + Query.cursorAfter) e caricare le righe in batch in Aurabase:
import { Client, Databases, Query } from 'node-appwrite'
import { createClient } from '@aurabase/aurabase-js'
const appwrite = new Client()
.setEndpoint(process.env.APPWRITE_ENDPOINT!)
.setProject(process.env.APPWRITE_PROJECT_ID!)
.setKey(process.env.APPWRITE_API_KEY!)
const databases = new Databases(appwrite)
const aura = createClient(
process.env.NEXT_PUBLIC_AURABASE_URL!,
process.env.AURABASE_SERVICE_ROLE_KEY!,
)
async function migrateCollection(databaseId: string, collectionId: string, targetTable: string) {
let cursor: string | undefined
while (true) {
const queries = [Query.limit(100), ...(cursor ? [Query.cursorAfter(cursor)] : [])]
const page = await databases.listDocuments(databaseId, collectionId, queries)
if (page.documents.length === 0) break
const rows = page.documents.map(({ $id, $createdAt, $updatedAt, $permissions, $databaseId, $collectionId, ...fields }) => ({
legacy_id: $id,
created_at: $createdAt,
updated_at: $updatedAt,
...fields,
}))
const { error } = await aura.from(targetTable).insert(rows)
if (error) throw new Error(`Insert failed on ${targetTable}: ${error.message}`)
cursor = page.documents[page.documents.length - 1].$id
if (page.documents.length < 100) break
}
}3. Importa utenti Appwrite senza reimpostazione della password#
Le moderne istanze Appwrite hanno hash le password con Argon2id ($argon2id$v=19$...) o bcrypt ($2a$/$2b$/$2y$). Entrambi sono accettati in modo nativo da aura.authAdmin.importUsers() (fino a 1.000 utenti per batch; gli hash bcrypt si aggiornano automaticamente ad Argon2id al primo accesso):
import { Client, Users, Query } from 'node-appwrite'
import { createClient } from '@aurabase/aurabase-js'
const appwrite = new Client()
.setEndpoint(process.env.APPWRITE_ENDPOINT!)
.setProject(process.env.APPWRITE_PROJECT_ID!)
.setKey(process.env.APPWRITE_API_KEY!)
const usersApi = new Users(appwrite)
const aura = createClient(
process.env.NEXT_PUBLIC_AURABASE_URL!,
process.env.AURABASE_SERVICE_ROLE_KEY!,
)
let cursor: string | undefined
while (true) {
const queries = [Query.limit(100), ...(cursor ? [Query.cursorAfter(cursor)] : [])]
const page = await usersApi.list(queries)
if (page.users.length === 0) break
const batch = page.users
.filter((u) => Boolean(u.email))
.map((u) => ({
email: u.email,
emailVerified: u.emailVerification,
...(u.password && /^\$(argon2id|2[aby])\$/.test(u.password) ? { passwordHash: u.password } : {}),
...(u.name ? { name: u.name } : {}),
userMetadata: { legacy_appwrite_id: u.$id, prefs: u.prefs },
}))
const { data, error } = await aura.authAdmin.importUsers(batch)
if (error) throw new Error(`User import failed: ${error.message}`)
console.log(`Imported batch: created=${data.created} skipped=${data.skipped} errors=${data.errors}`)
cursor = page.users[page.users.length - 1].$id
if (page.users.length < 100) break
}Se gli account Appwrite precedenti utilizzavano sha256, md5 o scrypt, ometti passwordHash quando chiami importUsers() in modo che l'account venga comunque creato in modo pulito, quindi consenti a tali utenti di accedere con un Magic Link o un flusso di reimpostazione della password.
4. Converti i permessi Appwrite in PostgreSQL RLS#
| Appwrite Autorizzazione | Equivalente Aurabase PostgreSQL RLS |
|---|---|
Permission.read(Role.any()) | FOR SELECT TO aura_anon, aura_authenticated USING (true) |
Permission.read(Role.users()) | FOR SELECT TO aura_authenticated USING (true) |
Permission.read(Role.user(userId)) | FOR SELECT TO aura_authenticated USING (user_id = auth.uid()) |
Permission.write(Role.user(userId)) | FOR ALL TO aura_authenticated USING (user_id = auth.uid()) WITH CHECK (user_id = auth.uid()) |
Permission.read(Role.team(teamId)) | USING (EXISTS (SELECT 1 FROM team_members tm WHERE tm.team_id = rows.team_id AND tm.user_id = auth.uid())) |
ALTER TABLE documents ENABLE ROW LEVEL SECURITY;
CREATE POLICY documents_owner_all ON documents
FOR ALL TO aura_authenticated
USING (user_id = auth.uid())
WITH CHECK (user_id = auth.uid());5. Migrare le chiamate di archiviazione, funzioni e SDK#
- Archiviazione: scarica i file con
storage.getFileDownload(bucketId, fileId)da Appwrite e caricali su Aurabase conaura.storage.from(bucket).upload(path, buffer, { contentType }). - Funzioni: converte il punto di ingresso
({ req, res }) => res.json(...)di Appwrite nel Web standardDeno.serve(async (req) => Response.json(...))e distribuisce tramiteaura functions deploy. - SDK client:
// PRIMA (Appwrite)
// const res = attendono databases.listDocuments(DB_ID, 'attività', [Query.equal('status', 'open')])
// DOPO (Aurabase)
const { data: tasks, error } = await aura
.from('tasks')
.select('*')
.eq('status', 'open')ID, team e insidie comuni#
- Appwrite
$idvs. Postgres UUID: gli ID Appwrite sono stringhe alfanumeriche di 20 caratteri (ID.unique()), non UUID RFC 4122. Archivia il vecchio$idin una colonnalegacy_id text UNIQUEdurante la migrazione dei riferimenti esterni o mantieniid text PRIMARY KEYsulle tabelle migrate. - Appwrite Teams: modella i team in modo esplicito con le tabelle
teams+team_members(team_id, user_id, role)e applica l'accesso con un singolo controllo indicizzato RLSEXISTS(vedi RBAC multi-tenant). - Array di autorizzazioni a livello di documento: invece di duplicare gli array di autorizzazioni su ogni riga, normalizza la proprietà (
user_id,team_id,is_public) in colonne indicizzate in modo che PostgreSQL possa utilizzare gli indici B-tree all'interno delle policy RLS.
Per andare oltre#
- Aurabase contro Appwrite
Confronto architetturale: Rust + Postgres 18 vs PHP/Swoole + MariaDB.
- Importazione utente in blocco
Importa fino a 1.000 utenti Argon2id/bcrypt per batch.
- Archivio documenti NoSQL
Utilizza --engine mongodb per raccolte JSON flessibili.
- RBAC multi-tenant
Sostituisci Appwrite Teams con ruoli SQL e RLS.