Skip to content

Commit

Permalink
Merge pull request #536 from supabase/or/rls_fkey_nullability_fix
Browse files Browse the repository at this point in the history
RLS fkey nullability fix
  • Loading branch information
imor authored Jun 28, 2024
2 parents 5218009 + 9d2258d commit 9c41cce
Show file tree
Hide file tree
Showing 5 changed files with 527 additions and 0 deletions.
3 changes: 3 additions & 0 deletions sql/load_sql_context.sql
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ select
'local_table_meta', jsonb_build_object(
'oid', pf.conrelid::int,
'name', pa_local.relname::text,
'is_rls_enabled', pa_local.relrowsecurity,
'schema', pa_local.relnamespace::regnamespace::text,
'column_names', (
select
Expand All @@ -163,6 +164,7 @@ select
'referenced_table_meta', jsonb_build_object(
'oid', pf.confrelid::int,
'name', pa_referenced.relname::text,
'is_rls_enabled', pa_referenced.relrowsecurity,
'schema', pa_referenced.relnamespace::regnamespace::text,
'column_names', (
select
Expand Down Expand Up @@ -234,6 +236,7 @@ select
'name', pc.relname::text,
'relkind', pc.relkind::text,
'reltype', pc.reltype::int,
'is_rls_enabled', pc.relrowsecurity,
'schema', schemas_.name,
'schema_oid', pc.relnamespace::int,
'comment', pg_catalog.obj_description(pc.oid, 'pg_class'),
Expand Down
1 change: 1 addition & 0 deletions src/graphql.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1958,6 +1958,7 @@ impl NodeType {
.columns
.iter()
.any(|c| &c.name == colname && c.is_not_null)
&& !fkey.referenced_table_meta.is_rls_enabled
}) {
__Type::NonNull(NonNullType {
type_: Box::new(type_),
Expand Down
4 changes: 4 additions & 0 deletions src/sql_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -425,6 +425,7 @@ pub struct ForeignKeyTableInfo {
// The table's actual name
pub name: String,
pub schema: String,
pub is_rls_enabled: bool,
pub column_names: Vec<String>,
}

Expand Down Expand Up @@ -503,6 +504,7 @@ pub struct Table {
pub schema: String,
pub columns: Vec<Arc<Column>>,
pub comment: Option<String>,
pub is_rls_enabled: bool,
pub relkind: String, // r = table, v = view, m = mat view, f = foreign table
pub reltype: u32,
pub permissions: TablePermissions,
Expand Down Expand Up @@ -660,12 +662,14 @@ impl Context {
oid: table.oid,
name: table.name.clone(),
schema: table.schema.clone(),
is_rls_enabled: table.is_rls_enabled,
column_names: directive_fkey.local_columns.clone(),
},
referenced_table_meta: ForeignKeyTableInfo {
oid: referenced_t.oid,
name: referenced_t.name.clone(),
schema: referenced_t.schema.clone(),
is_rls_enabled: table.is_rls_enabled,
column_names: directive_fkey.foreign_columns.clone(),
},
directives: ForeignKeyDirectives {
Expand Down
Loading

0 comments on commit 9c41cce

Please sign in to comment.