Skip to content

Commit

Permalink
tmp: does this fix things?
Browse files Browse the repository at this point in the history
  • Loading branch information
eviefp committed Mar 7, 2023
1 parent be03467 commit 67eb496
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 37 deletions.
62 changes: 28 additions & 34 deletions libs/sql-schema-describer/src/postgres.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1099,21 +1099,18 @@ impl<'a> SqlSchemaDescriber<'a> {

let inherited_tables_sql = r#"
SELECT
schemainfo.nspname AS parent_namespace,
tableinfo.relname AS parent_table_name,
schemainfo.nspname AS chnild_namespace,
tableinfo.relname AS chnild_table_name
parent_schemainfo.nspname AS parent_namespace,
parent_tableinfo.relname AS parent_table_name,
child_schemainfo.nspname AS child_namespace,
child_tableinfo.relname AS child_table_name
FROM
pg_class AS parent_tableinfo
INNER JOIN pg_namespace AS parent_schemainfo ON parent_schemainfo.oid = parent_tableinfo.relnamespace
INNER JOIN pg_class AS child_tableinfo
INNER JOIN pg_inherits AS inheritinfo ON parent_tableinfo.oid = inheritinfo.inhparent
INNER JOIN pg_class AS child_tableinfo ON child_tableinfo.oid = inheritinfo.inhrelid
INNER JOIN pg_namespace AS child_schemainfo ON child_schemainfo.oid = child_tableinfo.relnamespace
INNER JOIN pg_inherits AS inheritinfo ON
parent_tableinfo.oid = inheritinfo.inhparent
AND
child_tableinfo.oid = inheritinfo.inhrelid
WHERE schemainfo.nspname = ANY ( $1 )
ORDER BY namespace, table_name
WHERE parent_schemainfo.nspname = ANY ( $1 ) AND child_schemainfo.nspname = ANY ( $1 )
ORDER BY parent_namespace, parent_table_name, child_namespace, child_table_name
"#;

let inherited_rows = self
Expand All @@ -1129,10 +1126,10 @@ ORDER BY namespace, table_name
let mut inheritance_map: HashMap<(String, String), Vec<(String, String)>> = HashMap::new();

for inh in inherited_rows {
let parent_name = inh.get_expect_string("parent_table_name");
let parent_ns = inh.get_expect_string("parent_namespace");
let child_name = inh.get_expect_string("child_table_name");
let parent_name = inh.get_expect_string("parent_table_name");
let child_ns = inh.get_expect_string("child_namespace");
let child_name = inh.get_expect_string("child_table_name");

match inheritance_map.get(&(parent_name.clone(), parent_ns.clone())) {
Some(vec) => {
Expand Down Expand Up @@ -1215,29 +1212,26 @@ ORDER BY namespace, table_name

current_index = Some(index_id);

match inheritance_map.get(&(table_name, namespace)) {
Some(children) => {
for (child_table_name, child_table_namespace) in children {
let child_table_id: TableId =
match table_ids.get(&(child_table_namespace.clone(), child_table_name.clone())) {
Some(id) => *id,
None => continue,
};

let child_index_id = if is_primary_key {
sql_schema.push_primary_key(child_table_id, index_name.clone())
} else if is_unique {
sql_schema.push_unique_constraint(child_table_id, index_name.clone())
} else {
sql_schema.push_index(child_table_id, index_name.clone())
if let Some(children) = inheritance_map.get(&(table_name, namespace)) {
for (child_table_name, child_table_namespace) in children {
let child_table_id: TableId =
match table_ids.get(&(child_table_namespace.clone(), child_table_name.clone())) {
Some(id) => *id,
None => continue,
};
child_current_index.insert(
(child_table_name.to_string(), child_table_namespace.to_string()),
child_index_id,
);
}

let child_index_id = if is_primary_key {
sql_schema.push_primary_key(child_table_id, index_name.clone())
} else if is_unique {
sql_schema.push_unique_constraint(child_table_id, index_name.clone())
} else {
sql_schema.push_index(child_table_id, index_name.clone())
};
child_current_index.insert(
(child_table_name.to_string(), child_table_namespace.to_string()),
child_index_id,
);
}
None => {}
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -207,12 +207,10 @@ CREATE TABLE capitals (
}}
model capitals {{
name String @unique
name String @unique(map: "cities_name_key")
population Float? @db.Real
elevation Int?
state String? @db.Char(2)
@@ignore
}}
/// This table has subclasses and requires additional setup for migrations. Visit https://pris.ly/d/table-inheritance for more info.
Expand Down

0 comments on commit 67eb496

Please sign in to comment.