supabase / supabase-flutter

Flutter integration for Supabase. This package makes it simple for developers to build secure and scalable products.
https://supabase.com/
MIT License
661 stars 154 forks source link

Dynamic database schema #887

Closed pedromassango closed 2 months ago

pedromassango commented 2 months ago

It would be great for Supabase to give us the ability to create dynamic schemas for apps that support dynamic subdomains.

dshukertjr commented 2 months ago

@pedromassango Could you explain more about what exactly you mean by "dynamic schema" and what exactly the use cases are?

pedromassango commented 2 months ago

When running the following code, I want Supabase to create a new schema called brand-new-schema (if it doesn't exist) and use it for all my write/read operations.

Our product have multiple clients (each client has a large set of data), and we're trying to find a way to improve DB operations and isolate their data by saving it in separate schemas.

  await Supabase.initialize(
    url: supabaseUrl,
    anonKey: supabaseAnonKey,
    debug: kDebugMode,
    postgrestOptions: PostgrestClientOptions(
      schema: 'brand-new-schema'
    )
  );
dshukertjr commented 2 months ago

@pedromassango That is not how schema is designed to be used in Postgres. You shouldn't have an enormously large number of schemas in your database.

You might want to look into views or partitioning.

There are many solutions out there already for how to solve scaling problems for Postgres as Postgres has been around for so long, and many large enterprises use it. Whatever issue is that you are facing, you should be able to find a solution that will fit your use case if you do some research instead of trying to come up with a solution of your own.