risingwave_frontend/catalog/system_catalog/rw_catalog/
rw_schemas.rs

1// Copyright 2025 RisingWave Labs
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7//     http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15use risingwave_common::types::Fields;
16use risingwave_frontend_macro::system_catalog;
17
18use crate::catalog::OwnedByUserCatalog;
19use crate::catalog::system_catalog::{SysCatalogReaderImpl, get_acl_items};
20use crate::error::Result;
21
22#[derive(Fields)]
23struct RwSchema {
24    #[primary_key]
25    id: i32,
26    name: String,
27    owner: i32,
28    acl: Vec<String>,
29}
30
31#[system_catalog(table, "rw_catalog.rw_schemas")]
32fn read_rw_schema_info(reader: &SysCatalogReaderImpl) -> Result<Vec<RwSchema>> {
33    let catalog_reader = reader.catalog_reader.read_guard();
34    let schemas = catalog_reader.iter_schemas(&reader.auth_context.database)?;
35    let user_reader = reader.user_info_reader.read_guard();
36    let users = user_reader.get_all_users();
37    let username_map = user_reader.get_user_name_map();
38
39    Ok(schemas
40        .map(|schema| RwSchema {
41            id: schema.id().as_i32_id(),
42            name: schema.name(),
43            owner: schema.owner() as i32,
44            acl: get_acl_items(schema.id(), false, &users, username_map),
45        })
46        .collect())
47}