如何从supabase-js客户端访问自定义模式?

Jak*_*aur 16 sql postgresql supabase

我喜欢 Supabase,但我们的团队需要使用 PostgreSQL 提供的模式功能 - 不幸的是,到目前为止我们未能成功地使模式发挥作用。

其他信息:

  • PostgreSQL 14
  • Supabase JS SDK 的最新版本
  • 我们通过 Supabase 的专业计划托管了 SUPABASE

我们已经尝试过:

  1. 我们创建了一个新模式并添加了对所有类型身份验证的访问(为什么全部?我们首先想到身份验证可能存在错误):

    CREATE SCHEMA Brano;
    GRANT USAGE ON SCHEMA Brano TO postgres, anon, authenticated, service_role, dashboard_user;
    
    Run Code Online (Sandbox Code Playgroud)
  2. 通过此设置向 API 公开架构:

    在此输入图像描述

  3. 尝试了以下代码:

    var options = {
        schema: 'brano'
    }
    
    const supabaseUrl = 'supabaseUrl'
    const supabaseKey = 'supabaseKey'
    const supabaseClient = createClient(supabaseUrl, supabaseKey, options);
    
    const { data, error } = await supabaseClient
        .from('test_brano')
        .insert([{
            data: 123
    }]);
    
    Run Code Online (Sandbox Code Playgroud)
  4. 得到这个错误:

    {
        "message":"permission denied for table test_brano",
        "code":"42501",
        "details":null,
        "hint":null
    }
    
    Run Code Online (Sandbox Code Playgroud)

我们尝试阅读的链接和文档(不幸的是我们没有让它以任何方式工作):

我们错过了什么吗?提前致谢!

Man*_*eli 14

除了前两个步骤之外,您还执行了以下操作:

\n
    \n
  1. 授予用途:

    \n
    CREATE SCHEMA Brano;\n\nGRANT USAGE \nON SCHEMA Brano \nTO postgres, anon, authenticated, service_role, dashboard_user;\n\nALTER DEFAULT PRIVILEGES IN SCHEMA brano\nGRANT ALL ON TABLES TO postgres, anon, authenticated, service_role, dashboard_user;\n
    Run Code Online (Sandbox Code Playgroud)\n
  2. \n
  3. 在设置中公开架构

    \n

    在此输入图像描述

    \n
  4. \n
\n

缺少第三步:

\n
    \n
  1. 授予操作能够插入/选择数据:

    \n
    GRANT SELECT, INSERT, UPDATE, DELETE \nON ALL TABLES IN SCHEMA brano \nTO postgres, authenticated, service_role, dashboard_user, anon;\n\nGRANT USAGE, SELECT \nON ALL SEQUENCES IN SCHEMA brano \nTO postgres, authenticated, service_role, dashboard_user, anon;\n
    Run Code Online (Sandbox Code Playgroud)\n
  2. \n
\n

\xe2\x9a\xa0\xef\xb8\x8f 警告 \xe2\x9a\xa0\xef\xb8\x8f

\n

您必须为自定义架构中创建的每个新表再次设置这些授权。

\n

然后您可以像示例中那样调用它:

\n

Supabase JS v2:

\n
    const options = {\n      db: { schema: \'brano\' }\n    };\n    const supabase = createClient(supabaseUrl, SUPABASE_KEY, options)\n    const d = new Date(2018, 11, 24, 10, 33, 30, 0);\n    const { data, error } = await supabase\n      .from(\'test_brano\')\n      .insert([\n        { data: 3, created_at: d }\n      ])\n    console.log(data)\n    if (error) {\n        console.log("error getting results");\n        throw error;\n    }\n
Run Code Online (Sandbox Code Playgroud)\n

Supabase JS v1:

\n
    const options = {\n      schema: \'brano\'\n    }\n    const supabase = createClient(supabaseUrl, SUPABASE_KEY, options)\n    const d = new Date(2018, 11, 24, 10, 33, 30, 0);\n    const { data, error } = await supabase\n      .from(\'test_brano\')\n      .insert([\n        { data: 3, created_at: d }\n      ])\n    console.log(data)\n    if (error) {\n        console.log("error getting results");\n        throw error;\n    }\n
Run Code Online (Sandbox Code Playgroud)\n