feat(api): sync réel — outbox POST /sync/ops idempotente + snapshot GET /sync/permissions (owner V1)
- operations.operation_id/ref_id BIGINT (= id client pending_operations), UNIQUE(device_id, operation_id) idempotente ; migration 000004 corrigée + test
- service/sync.go : ApplyBatch séquentiel (no-op si déjà traitée ; create déjà présent / update/move sur ressource absente / delete absent = no-op) ;
arrêt à la première erreur non-idempotente (NAME_CONFLICT, NOT_FOUND, INVALID_REQUEST) + trace après succès ; ops share/share_link accusées sans état (V1)
- handlers/sync.go : POST /sync/ops → {applied, failed|null} ; GET /sync/permissions?after= → snapshot delta (effectiveAccess owner, cachedAt ms)
- snapshot : repo.ListOwned (delta updated_at en ms, trié) ; index partiel racine (owner_id, name) WHERE parent_id IS NULL
- GET /files sans folderId = racine uniquement (convention useFiles(undefined)) ; tests files_test corrigés (codes d'erreur imbriqués, tailles)
- fix dbtest : ping la connexion maintenance (création de la DB cible possible) — les tests handlers/repo tournent enfin contre PG réel
- tests handlers end-to-end : batch appliqué + retry idempotent, arrêt sur NAME_CONFLICT, delete idempotent, snapshot + delta
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
DROP INDEX IF EXISTS idx_resources_root_name;
|
||||
DROP INDEX IF EXISTS idx_resources_category;
|
||||
DROP INDEX IF EXISTS idx_resources_parent;
|
||||
DROP INDEX IF EXISTS idx_resources_owner;
|
||||
|
||||
@@ -18,4 +18,8 @@ CREATE TABLE resources (
|
||||
|
||||
CREATE INDEX idx_resources_owner ON resources(owner_id) WHERE deleted_at IS NULL;
|
||||
CREATE INDEX idx_resources_parent ON resources(parent_id);
|
||||
CREATE INDEX idx_resources_category ON resources(category) WHERE deleted_at IS NULL;
|
||||
CREATE INDEX idx_resources_category ON resources(category) WHERE deleted_at IS NULL;
|
||||
|
||||
-- Unicité du nom à la racine (NULL ≠ NULL : la contrainte (parent_id,name)
|
||||
-- ne couvre pas parent_id NULL).
|
||||
CREATE UNIQUE INDEX idx_resources_root_name ON resources(owner_id, name) WHERE parent_id IS NULL;
|
||||
@@ -1,9 +1,12 @@
|
||||
CREATE TABLE operations (
|
||||
id BIGSERIAL PRIMARY KEY,
|
||||
device_id TEXT NOT NULL REFERENCES devices(device_id) ON DELETE CASCADE,
|
||||
operation_id TEXT NOT NULL CHECK (operation_id ~ '^[0-9a-f]{32}$'),
|
||||
operation_id BIGINT NOT NULL,
|
||||
op_type TEXT NOT NULL,
|
||||
payload JSONB NOT NULL,
|
||||
ref_type TEXT,
|
||||
ref_id BIGINT,
|
||||
resource_id TEXT,
|
||||
payload JSONB,
|
||||
status TEXT NOT NULL DEFAULT 'applied' CHECK (status IN ('applied', 'failed')),
|
||||
error_code TEXT,
|
||||
applied_at TIMESTAMPTZ DEFAULT NOW(),
|
||||
|
||||
@@ -109,9 +109,20 @@ func TestMigrationsUpDown(t *testing.T) {
|
||||
|
||||
assertHexCheck(t, conn, "devices", "device_id")
|
||||
assertHexCheck(t, conn, "resources", "resource_id")
|
||||
assertHexCheck(t, conn, "operations", "operation_id")
|
||||
assertHexCheck(t, conn, "ocr_jobs", "job_id")
|
||||
|
||||
// operation_id outbox = id client (INTEGER) — cf. docs/api-v1.md §6.1
|
||||
var opType string
|
||||
err = conn.QueryRow(`
|
||||
SELECT data_type FROM information_schema.columns
|
||||
WHERE table_schema = 'public' AND table_name = 'operations' AND column_name = 'operation_id'`).Scan(&opType)
|
||||
if err != nil {
|
||||
t.Fatalf("operation_id type: %v", err)
|
||||
}
|
||||
if opType != "bigint" {
|
||||
t.Errorf("operation_id attendu bigint, got %s", opType)
|
||||
}
|
||||
|
||||
var resourceTypeCheck int
|
||||
err = conn.QueryRow(`
|
||||
SELECT COUNT(*) FROM pg_constraint c
|
||||
|
||||
Reference in New Issue
Block a user