Skip to content

Commit

Permalink
store: Map more tables across shards
Browse files Browse the repository at this point in the history
This now includes ethereum_networks, copy_state, copy_table_state, and
subgraph_features.

We no longer map subgraph, subgraph_version, and
subgraph_deployment_assignment into the shard_* namespace since these
tables are only maintained in the primary, and are mapped in the
primary_public namespace.
  • Loading branch information
lutter committed Mar 4, 2025
1 parent eacdc22 commit 1508c4d
Showing 1 changed file with 22 additions and 13 deletions.
35 changes: 22 additions & 13 deletions store/postgres/src/connection_pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -206,22 +206,31 @@ impl ForeignServer {
/// Map the `subgraphs` schema from the foreign server `self` into the
/// database accessible through `conn`
fn map_metadata(&self, conn: &mut PgConnection) -> Result<(), StoreError> {
const MAP_TABLES: [(&str, &[&str]); 2] = [
("public", &["ethereum_networks"]),
(
"subgraphs",
&[
"copy_state",
"copy_table_state",
"dynamic_ethereum_contract_data_source",
"subgraph_deployment",
"subgraph_error",
"subgraph_features",
"subgraph_manifest",
"table_stats",
],
),
];
let nsp = Self::metadata_schema(&self.shard);
catalog::recreate_schema(conn, &nsp)?;
let mut query = String::new();
for table_name in [
"subgraph_error",
"dynamic_ethereum_contract_data_source",
"table_stats",
"subgraph_deployment_assignment",
"subgraph",
"subgraph_version",
"subgraph_deployment",
"subgraph_manifest",
] {
let create_stmt =
catalog::create_foreign_table(conn, "subgraphs", table_name, &nsp, &self.name)?;
write!(query, "{}", create_stmt)?;
for (src_nsp, src_tables) in MAP_TABLES {
for src_table in src_tables {
let create_stmt =
catalog::create_foreign_table(conn, src_nsp, src_table, &nsp, &self.name)?;
write!(query, "{}", create_stmt)?;
}
}
Ok(conn.batch_execute(&query)?)
}
Expand Down

0 comments on commit 1508c4d

Please sign in to comment.