createOrganization method
Implementation
Future<OrganizationModel> createOrganization({
required String name,
required String slug,
}) async {
// Uses a SECURITY DEFINER RPC to atomically insert the org and add the
// caller as owner. A plain INSERT + RETURNING would fail RLS because the
// RETURNING clause is checked against the SELECT policy (is_org_member),
// but the user isn't a member yet at that point.
final response = await _client.rpc(
'create_organization',
params: {'p_name': name, 'p_slug': slug},
);
return OrganizationModel.fromJson(response as Map<String, dynamic>);
}