Skip to content

Commit 616f22b

Browse files
committed
index fix
1 parent 80e950e commit 616f22b

6 files changed

Lines changed: 23 additions & 10 deletions

File tree

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/bindings-macro/src/procedure.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,5 +129,7 @@ pub(crate) fn procedure_impl(_args: ProcedureArgs, original_function: &ItemFn) -
129129
Some(<#ret_ty_for_info as spacetimedb::SpacetimeType>::make_type(ts))
130130
}
131131
}
132+
133+
#generate_explicit_names
132134
})
133135
}

crates/bindings/src/rt.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use crate::query_builder::Query;
44
use crate::table::IndexAlgo;
55
use crate::{sys, AnonymousViewContext, IterBuf, ReducerContext, ReducerResult, SpacetimeType, Table, ViewContext};
66
use spacetimedb_lib::bsatn::EncodeError;
7-
use spacetimedb_lib::db::raw_def::v10::{ExplicitNameEntry, ExplicitNames as RawExplicitNames, RawModuleDefV10Builder};
7+
use spacetimedb_lib::db::raw_def::v10::{ExplicitNames as RawExplicitNames, RawModuleDefV10Builder};
88
pub use spacetimedb_lib::db::raw_def::v9::Lifecycle as LifecycleReducer;
99
use spacetimedb_lib::db::raw_def::v9::{RawIndexAlgorithm, TableType, ViewResultHeader};
1010
use spacetimedb_lib::de::{self, Deserialize, DeserializeOwned, Error as _, SeqProductAccess};

crates/lib/src/db/raw_def/v10.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@
77
88
use crate::db::raw_def::v9::{Lifecycle, RawIndexAlgorithm, TableAccess, TableType};
99
use core::fmt;
10-
use spacetimedb_data_structures::map::HashMap;
11-
use spacetimedb_data_structures::small_map::SmallHashMap;
1210
use spacetimedb_primitives::{ColId, ColList};
1311
use spacetimedb_sats::raw_identifier::RawIdentifier;
1412
use spacetimedb_sats::typespace::TypespaceBuilder;

crates/schema/src/def/validate/v10.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,7 @@ impl<'a> ModuleValidatorV10<'a> {
291291
.into_iter()
292292
.map(|index| {
293293
table_validator
294-
.validate_index_def(index.into())
294+
.validate_index_def(index.into(), RawModuleDefVersion::V10)
295295
.map(|index| (index.name.clone(), index))
296296
})
297297
.collect_all_errors::<StrMap<_>>();

crates/schema/src/def/validate/v9.rs

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ impl ModuleValidatorV9<'_> {
211211
.into_iter()
212212
.map(|index| {
213213
table_in_progress
214-
.validate_index_def(index)
214+
.validate_index_def(index, RawModuleDefVersion::V9OrEarlier)
215215
.map(|index| (index.name.clone(), index))
216216
})
217217
.collect_all_errors::<StrMap<_>>();
@@ -1047,16 +1047,20 @@ impl<'a, 'b> TableValidator<'a, 'b> {
10471047
}
10481048

10491049
/// Validate an index definition.
1050-
pub(crate) fn validate_index_def(&mut self, index: RawIndexDefV9) -> Result<IndexDef> {
1050+
pub(crate) fn validate_index_def(
1051+
&mut self,
1052+
index: RawIndexDefV9,
1053+
raw_def_version: RawModuleDefVersion,
1054+
) -> Result<IndexDef> {
10511055
let RawIndexDefV9 {
10521056
name,
1053-
algorithm,
1057+
algorithm: algorithm_raw,
10541058
accessor_name,
10551059
} = index;
10561060

1057-
let name = name.unwrap_or_else(|| generate_index_name(&self.raw_name, self.product_type, &algorithm));
1061+
let name = name.unwrap_or_else(|| generate_index_name(&self.raw_name, self.product_type, &algorithm_raw));
10581062

1059-
let algorithm: Result<IndexAlgorithm> = match algorithm {
1063+
let algorithm: Result<IndexAlgorithm> = match algorithm_raw.clone() {
10601064
RawIndexAlgorithm::BTree { columns } => self
10611065
.validate_col_ids(&name, columns)
10621066
.map(|columns| BTreeAlgorithm { columns }.into()),
@@ -1089,8 +1093,16 @@ impl<'a, 'b> TableValidator<'a, 'b> {
10891093
}),
10901094
algo => unreachable!("unknown algorithm {algo:?}"),
10911095
};
1096+
1097+
let accessor_name = match raw_def_version {
1098+
// In V9, `name`field is used for database internals but `accessor_name` supplied by module is used for client codegen.
1099+
RawModuleDefVersion::V9OrEarlier => accessor_name.map(identifier).transpose(),
1100+
1101+
// In V10, `name` is used both for internal purpose and client codefen.
1102+
RawModuleDefVersion::V10 => identifier(name.clone()).map(Some),
1103+
};
1104+
10921105
let name = self.add_to_global_namespace(name);
1093-
let accessor_name = accessor_name.map(identifier).transpose();
10941106

10951107
let (name, accessor_name, algorithm) = (name, accessor_name, algorithm).combine_errors()?;
10961108

0 commit comments

Comments
 (0)