feat(drive): start implementation of drive

- add storage.drives
    - prepare migration phase
    - add created_by and updated_by on storage.folders
This commit is contained in:
Edouard Vanbelle
2026-06-18 13:29:41 +02:00
parent 77545aee05
commit eab7a609b9
43 changed files with 2434 additions and 154 deletions
+36
View File
@@ -42,4 +42,40 @@ psql -v ON_ERROR_STOP=1 -c "
ON CONFLICT (username) DO NOTHING;
" >/dev/null
# The OxiCloud server normally provisions a default Personal drive +
# Owner role_grant on user creation via PersonalDriveLifecycleHook
# (D0). This script bypasses that pipeline — it INSERTs directly into
# auth.users — so we mirror the hook's behaviour here. Without it,
# integration test fixtures that hand-roll INSERTs into storage.files
# fail with "drive_id not-null violation" (M3 made the column
# mandatory), and helpers that JOIN auth.users with storage.drives
# return RowNotFound.
echo "[init-schema] provisioning ci-admin's default Personal drive (idempotent)"
psql -v ON_ERROR_STOP=1 <<'SQL' >/dev/null
WITH admin AS (
SELECT id FROM auth.users WHERE username = 'ci-admin'
),
ins_drive AS (
INSERT INTO storage.drives (name, kind, default_for_user, quota_bytes)
SELECT 'Personal', 'personal', admin.id, NULL
FROM admin
WHERE NOT EXISTS (
SELECT 1 FROM storage.drives d WHERE d.default_for_user = admin.id
)
RETURNING id, default_for_user
)
INSERT INTO storage.role_grants
(subject_type, subject_id, resource_type, resource_id, role, granted_by)
SELECT 'user', ins_drive.default_for_user, 'drive', ins_drive.id, 'owner',
ins_drive.default_for_user
FROM ins_drive
WHERE NOT EXISTS (
SELECT 1 FROM storage.role_grants g
WHERE g.subject_type = 'user'
AND g.subject_id = ins_drive.default_for_user
AND g.resource_type = 'drive'
AND g.resource_id = ins_drive.id
);
SQL
echo "[init-schema] done"