Skip to content

Commit 02d0d12

Browse files
committed
store: Move has_causality_region to manifest, rename to entities_with_causality_region
1 parent faaf8f4 commit 02d0d12

File tree

10 files changed

+48
-38
lines changed

10 files changed

+48
-38
lines changed

core/src/subgraph/registrar.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -642,7 +642,7 @@ async fn create_subgraph_version<C: Blockchain, S: SubgraphStore>(
642642
let deployment = DeploymentCreate::new(raw_string, &manifest, start_block)
643643
.graft(base_block)
644644
.debug(debug_fork)
645-
.has_causality_region(needs_causality_region);
645+
.entities_with_causality_region(needs_causality_region);
646646

647647
deployment_store
648648
.create_subgraph_deployment(

graph/src/data/subgraph/schema.rs

+14-7
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,6 @@ pub struct DeploymentCreate {
107107
pub graft_base: Option<DeploymentHash>,
108108
pub graft_block: Option<BlockPtr>,
109109
pub debug_fork: Option<DeploymentHash>,
110-
pub has_causality_region: BTreeSet<EntityType>,
111110
}
112111

113112
impl DeploymentCreate {
@@ -117,12 +116,11 @@ impl DeploymentCreate {
117116
start_block: Option<BlockPtr>,
118117
) -> Self {
119118
Self {
120-
manifest: SubgraphManifestEntity::new(raw_manifest, source_manifest),
119+
manifest: SubgraphManifestEntity::new(raw_manifest, source_manifest, Vec::new()),
121120
start_block: start_block.cheap_clone(),
122121
graft_base: None,
123122
graft_block: None,
124123
debug_fork: None,
125-
has_causality_region: BTreeSet::new(),
126124
}
127125
}
128126

@@ -139,8 +137,12 @@ impl DeploymentCreate {
139137
self
140138
}
141139

142-
pub fn has_causality_region(mut self, has_causality_region: BTreeSet<EntityType>) -> Self {
143-
self.has_causality_region = has_causality_region;
140+
pub fn entities_with_causality_region(
141+
mut self,
142+
entities_with_causality_region: BTreeSet<EntityType>,
143+
) -> Self {
144+
self.manifest.entities_with_causality_region =
145+
entities_with_causality_region.into_iter().collect();
144146
self
145147
}
146148
}
@@ -166,7 +168,6 @@ pub struct SubgraphDeploymentEntity {
166168
pub reorg_count: i32,
167169
pub current_reorg_depth: i32,
168170
pub max_reorg_depth: i32,
169-
pub has_causality_region: Vec<EntityType>,
170171
}
171172

172173
#[derive(Debug)]
@@ -177,17 +178,23 @@ pub struct SubgraphManifestEntity {
177178
pub features: Vec<String>,
178179
pub schema: String,
179180
pub raw_yaml: Option<String>,
181+
pub entities_with_causality_region: Vec<EntityType>,
180182
}
181183

182184
impl SubgraphManifestEntity {
183-
pub fn new(raw_yaml: String, manifest: &super::SubgraphManifest<impl Blockchain>) -> Self {
185+
pub fn new(
186+
raw_yaml: String,
187+
manifest: &super::SubgraphManifest<impl Blockchain>,
188+
entities_with_causality_region: Vec<EntityType>,
189+
) -> Self {
184190
Self {
185191
spec_version: manifest.spec_version.to_string(),
186192
description: manifest.description.clone(),
187193
repository: manifest.repository.clone(),
188194
features: manifest.features.iter().map(|f| f.to_string()).collect(),
189195
schema: manifest.schema.document.clone().to_string(),
190196
raw_yaml: Some(raw_yaml),
197+
entities_with_causality_region,
191198
}
192199
}
193200

Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
alter table subgraphs.subgraph_deployment drop column has_causality_region;
1+
alter table subgraphs.subgraph_manifest drop column entities_with_causality_region;
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
alter table subgraphs.subgraph_deployment add column has_causality_region text[] not null default array[]::text[];
1+
alter table subgraphs.subgraph_manifest add column entities_with_causality_region text[] not null default array[]::text[];

store/postgres/src/catalog.rs

+10-7
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ pub struct Catalog {
186186
pub use_bytea_prefix: bool,
187187

188188
/// Set of tables which have an explicit causality region column.
189-
pub(crate) has_causality_region: BTreeSet<EntityType>,
189+
pub(crate) entities_with_causality_region: BTreeSet<EntityType>,
190190
}
191191

192192
impl Catalog {
@@ -195,7 +195,7 @@ impl Catalog {
195195
conn: &PgConnection,
196196
site: Arc<Site>,
197197
use_bytea_prefix: bool,
198-
has_causality_region: Vec<EntityType>,
198+
entities_with_causality_region: Vec<EntityType>,
199199
) -> Result<Self, StoreError> {
200200
let text_columns = get_text_columns(conn, &site.namespace)?;
201201
let use_poi = supports_proof_of_indexing(conn, &site.namespace)?;
@@ -204,12 +204,15 @@ impl Catalog {
204204
text_columns,
205205
use_poi,
206206
use_bytea_prefix,
207-
has_causality_region: has_causality_region.into_iter().collect(),
207+
entities_with_causality_region: entities_with_causality_region.into_iter().collect(),
208208
})
209209
}
210210

211211
/// Return a new catalog suitable for creating a new subgraph
212-
pub fn for_creation(site: Arc<Site>, has_causality_region: BTreeSet<EntityType>) -> Self {
212+
pub fn for_creation(
213+
site: Arc<Site>,
214+
entities_with_causality_region: BTreeSet<EntityType>,
215+
) -> Self {
213216
Catalog {
214217
site,
215218
text_columns: HashMap::default(),
@@ -218,7 +221,7 @@ impl Catalog {
218221
// DDL generation creates indexes for prefixes of bytes columns
219222
// see: attr-bytea-prefix
220223
use_bytea_prefix: true,
221-
has_causality_region,
224+
entities_with_causality_region,
222225
}
223226
}
224227

@@ -227,14 +230,14 @@ impl Catalog {
227230
/// connection is definitely not available, such as in unit tests
228231
pub fn for_tests(
229232
site: Arc<Site>,
230-
has_causality_region: BTreeSet<EntityType>,
233+
entities_with_causality_region: BTreeSet<EntityType>,
231234
) -> Result<Self, StoreError> {
232235
Ok(Catalog {
233236
site,
234237
text_columns: HashMap::default(),
235238
use_poi: false,
236239
use_bytea_prefix: true,
237-
has_causality_region,
240+
entities_with_causality_region,
238241
})
239242
}
240243

store/postgres/src/deployment.rs

+12-12
Original file line numberDiff line numberDiff line change
@@ -87,10 +87,6 @@ table! {
8787
current_reorg_depth -> Integer,
8888
max_reorg_depth -> Integer,
8989
firehose_cursor -> Nullable<Text>,
90-
91-
// Entity types that have a `causality_region` column.
92-
// Names stored as present in the schema, not in snake case.
93-
has_causality_region -> Array<Text>,
9490
}
9591
}
9692

@@ -121,6 +117,10 @@ table! {
121117
start_block_number -> Nullable<Integer>,
122118
start_block_hash -> Nullable<Binary>,
123119
raw_yaml -> Nullable<Text>,
120+
121+
// Entity types that have a `causality_region` column.
122+
// Names stored as present in the schema, not in snake case.
123+
entities_with_causality_region -> Array<Text>,
124124
}
125125
}
126126

@@ -776,15 +776,15 @@ pub(crate) fn health(conn: &PgConnection, id: DeploymentId) -> Result<SubgraphHe
776776
.map_err(|e| e.into())
777777
}
778778

779-
pub(crate) fn has_causality_region(
779+
pub(crate) fn entities_with_causality_region(
780780
conn: &PgConnection,
781781
id: DeploymentId,
782782
) -> Result<Vec<EntityType>, StoreError> {
783-
use subgraph_deployment as d;
783+
use subgraph_manifest as sm;
784784

785-
d::table
786-
.filter(d::id.eq(id))
787-
.select(d::has_causality_region)
785+
sm::table
786+
.filter(sm::id.eq(id))
787+
.select(sm::entities_with_causality_region)
788788
.get_result(conn)
789789
.map_err(|e| e.into())
790790
}
@@ -931,15 +931,15 @@ pub fn create_deployment(
931931
features,
932932
schema,
933933
raw_yaml,
934+
entities_with_causality_region,
934935
},
935936
start_block,
936937
graft_base,
937938
graft_block,
938939
debug_fork,
939-
has_causality_region,
940940
} = deployment;
941941
let earliest_block_number = start_block.as_ref().map(|ptr| ptr.number).unwrap_or(0);
942-
let has_causality_region = Vec::from_iter(has_causality_region.into_iter());
942+
let entities_with_causality_region = Vec::from_iter(entities_with_causality_region.into_iter());
943943

944944
let deployment_values = (
945945
d::id.eq(site.id),
@@ -957,7 +957,6 @@ pub fn create_deployment(
957957
d::graft_block_hash.eq(b(&graft_block)),
958958
d::graft_block_number.eq(n(&graft_block)),
959959
d::debug_fork.eq(debug_fork.as_ref().map(|s| s.as_str())),
960-
d::has_causality_region.eq(has_causality_region),
961960
);
962961

963962
let graph_node_version_id = GraphNodeVersion::create_or_get(conn)?;
@@ -976,6 +975,7 @@ pub fn create_deployment(
976975
m::start_block_hash.eq(b(&start_block)),
977976
m::start_block_number.eq(start_block.as_ref().map(|ptr| ptr.number)),
978977
m::raw_yaml.eq(raw_yaml),
978+
m::entities_with_causality_region.eq(entities_with_causality_region),
979979
);
980980

981981
if exists && replace {

store/postgres/src/deployment_store.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,8 @@ impl DeploymentStore {
174174
let exists = deployment::exists(&conn, &site)?;
175175

176176
// Create (or update) the metadata. Update only happens in tests
177-
let has_causality_region = deployment.has_causality_region.clone();
177+
let entities_with_causality_region =
178+
deployment.manifest.entities_with_causality_region.clone();
178179
if replace || !exists {
179180
deployment::create_deployment(&conn, &site, deployment, exists, replace)?;
180181
};
@@ -188,7 +189,7 @@ impl DeploymentStore {
188189
&conn,
189190
site.clone(),
190191
schema,
191-
has_causality_region,
192+
entities_with_causality_region.into_iter().collect(),
192193
)?;
193194
// See if we are grafting and check that the graft is permissible
194195
if let Some(base) = graft_base {

store/postgres/src/detail.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,6 @@ pub struct DeploymentDetail {
6565
current_reorg_depth: i32,
6666
max_reorg_depth: i32,
6767
firehose_cursor: Option<String>,
68-
has_causality_region: Vec<EntityType>,
6968
}
7069

7170
#[derive(Queryable, QueryableByName)]
@@ -340,6 +339,7 @@ struct StoredSubgraphManifest {
340339
start_block_number: Option<i32>,
341340
start_block_hash: Option<Bytes>,
342341
raw_yaml: Option<String>,
342+
entities_with_causality_region: Vec<EntityType>,
343343
}
344344

345345
impl From<StoredSubgraphManifest> for SubgraphManifestEntity {
@@ -351,6 +351,7 @@ impl From<StoredSubgraphManifest> for SubgraphManifestEntity {
351351
features: value.features,
352352
schema: value.schema,
353353
raw_yaml: value.raw_yaml,
354+
entities_with_causality_region: value.entities_with_causality_region,
354355
}
355356
}
356357
}
@@ -415,7 +416,6 @@ impl TryFrom<StoredDeploymentEntity> for SubgraphDeploymentEntity {
415416
reorg_count: detail.reorg_count,
416417
current_reorg_depth: detail.current_reorg_depth,
417418
max_reorg_depth: detail.max_reorg_depth,
418-
has_causality_region: detail.has_causality_region,
419419
})
420420
}
421421
}

store/postgres/src/relational.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,7 @@ impl Layout {
315315
&id_types,
316316
i as u32,
317317
catalog
318-
.has_causality_region
318+
.entities_with_causality_region
319319
.contains(&EntityType::from(obj_type.clone())),
320320
)
321321
})
@@ -409,9 +409,9 @@ impl Layout {
409409
conn: &PgConnection,
410410
site: Arc<Site>,
411411
schema: &Schema,
412-
has_causality_region: BTreeSet<EntityType>,
412+
entities_with_causality_region: BTreeSet<EntityType>,
413413
) -> Result<Layout, StoreError> {
414-
let catalog = Catalog::for_creation(site.cheap_clone(), has_causality_region);
414+
let catalog = Catalog::for_creation(site.cheap_clone(), entities_with_causality_region);
415415
let layout = Self::new(site, schema, catalog)?;
416416
let sql = layout
417417
.as_ddl()
@@ -1389,7 +1389,7 @@ impl LayoutCache {
13891389

13901390
fn load(conn: &PgConnection, site: Arc<Site>) -> Result<Arc<Layout>, StoreError> {
13911391
let (subgraph_schema, use_bytea_prefix) = deployment::schema(conn, site.as_ref())?;
1392-
let has_causality_region = deployment::has_causality_region(conn, site.id)?;
1392+
let has_causality_region = deployment::entities_with_causality_region(conn, site.id)?;
13931393
let catalog = Catalog::load(conn, site.clone(), use_bytea_prefix, has_causality_region)?;
13941394
let layout = Arc::new(Layout::new(site.clone(), &subgraph_schema, catalog)?);
13951395
layout.refresh(conn, site)

store/postgres/src/subgraph_store.rs

-1
Original file line numberDiff line numberDiff line change
@@ -627,7 +627,6 @@ impl SubgraphStoreInner {
627627
graft_base: Some(src.deployment.clone()),
628628
graft_block: Some(block),
629629
debug_fork: deployment.debug_fork,
630-
has_causality_region: deployment.has_causality_region.into_iter().collect(),
631630
};
632631

633632
let graft_base = self.layout(&src.deployment)?;

0 commit comments

Comments
 (0)