Skip to content

Sync Rules Not Filtering Data Based on client params #234

@tejas-codiste

Description

@tejas-codiste

I am trying to sync only the relevant data based on a user_id parameter. However, instead of fetching only the filtered data, the entire database is being synced to the local device.

Expected Behavior

Only the data matching the user_id parameter should be synced to the local database.

Actual Behavior

The entire database is synced, ignoring the filtering rules logic in the sync rules.

PowerSync Sync Rules Configuration

I have defined the following sync rule in the PowerSync console:

bucket_definitions:
  by_user_parameter:
    parameters: SELECT (request.parameters() ->> 'user_id') as user_id
    data:
      - SELECT * FROM creators WHERE creators.user_id = bucket.user_id
      - SELECT * FROM events WHERE events.creator_user = bucket.user_id
      - SELECT attendee.* FROM attendee 
        JOIN events ON attendee.event_id = events.event_id 
        JOIN creators ON events.creator_user = creators.user_id 
        WHERE creators.user_id = bucket.user_id
      - SELECT * FROM pin WHERE pin.user_id = bucket.user_id
      - SELECT device.* FROM device 
        JOIN pin ON device.pin_id = pin.uid 
        JOIN creators ON pin.user_id = creators.user_id 
        WHERE creators.user_id = bucket.user_id
      - SELECT * FROM check_in_logs WHERE user_id = bucket.user_id

Flutter Code for Connecting to PowerSync

currentConnector = SupabaseConnector(db);
db.connect(
    connector: currentConnector!,
    params: {'user_id': user.userId});

This issue prevents implementing user-specific data syncing, which is a core requirement for my application. Any guidance on resolving this would be appreciated.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions