writeFunctionsHash method
Writes the bundled functions hash into _schema_meta.functions_hash
on the user's Supabase project via PostgREST, using the fetched
service role key so the write bypasses RLS.
This is the bookkeeping step that lets the next sign-in detect whether a newer app build has a newer bundle hash — if so, the Settings screen surfaces a "Dutato updates available" banner.
Implementation
Future<void> writeFunctionsHash({
required String projectRef,
required String serviceRoleKey,
required String hash,
}) async {
final url =
'https://$projectRef.supabase.co/rest/v1/_schema_meta'
'?_singleton=eq.true';
final Response<dynamic> response;
try {
response = await _dio.patch<dynamic>(
url,
data: {'functions_hash': hash},
options: Options(
headers: {
'apikey': serviceRoleKey,
'Authorization': 'Bearer $serviceRoleKey',
'Content-Type': 'application/json',
'Prefer': 'return=minimal',
},
sendTimeout: _timeout,
receiveTimeout: _timeout,
validateStatus: (_) => true,
),
);
} on DioException catch (e) {
throw ProvisioningException(_dioMessage(e, 'writing functions hash'));
}
final status = response.statusCode ?? 0;
if (status >= 200 && status < 300) return;
throw ProvisioningException(
'Failed to record deployed functions hash on the project '
'(HTTP $status). Try again, or use the manual fallback.',
);
}