Skip to content

Commit 9a7a9cc

Browse files
committed
remove from RawIndexDefV10
1 parent f287d0f commit 9a7a9cc

9 files changed

Lines changed: 86 additions & 61 deletions

File tree

crates/bindings-typescript/src/lib/autogen/explicit_name_entry_type.ts

Lines changed: 11 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/bindings-typescript/src/lib/autogen/explicit_names_type.ts

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

crates/bindings-typescript/src/lib/autogen/name_mapping_type.ts

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

crates/bindings-typescript/src/lib/autogen/raw_index_def_v_10_type.ts

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

crates/bindings/src/rt.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -722,7 +722,7 @@ pub fn register_table<T: Table>() {
722722
table = table.with_unique_constraint(col);
723723
}
724724
for index in T::INDEXES {
725-
table = table.with_index(index.algo.into(), index.accessor_name, Some(index.index_name));
725+
table = table.with_index(index.algo.into(), index.accessor_name);
726726
}
727727
if let Some(primary_key) = T::PRIMARY_KEY {
728728
table = table.with_primary_key(primary_key);

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

Lines changed: 39 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -106,46 +106,68 @@ pub enum CaseConversionPolicy {
106106
PascalCase,
107107
}
108108

109+
109110
#[derive(Debug, Clone, SpacetimeType)]
110111
#[sats(crate = crate)]
111112
#[cfg_attr(feature = "test", derive(PartialEq, Eq, Ord, PartialOrd))]
112113
#[non_exhaustive]
113-
pub struct ExplicitNameEntry {
114-
/// The original name as written in the raw module definition.
115-
source_name: RawIdentifier,
114+
pub struct NameMapping {
115+
pub source_name: RawIdentifier,
116+
pub canonical_name: RawIdentifier,
117+
}
116118

117-
/// The canonical name after applying case conversion.
118-
canonical_name: RawIdentifier,
119+
#[derive(Debug, Clone, SpacetimeType)]
120+
#[sats(crate = crate)]
121+
#[cfg_attr(feature = "test", derive(PartialEq, Eq, Ord, PartialOrd))]
122+
#[non_exhaustive]
123+
pub enum ExplicitNameEntry {
124+
Table(NameMapping),
125+
Function(NameMapping)
119126
}
120127

121128
#[derive(Debug, Default, Clone, SpacetimeType)]
122129
#[sats(crate = crate)]
123130
#[cfg_attr(feature = "test", derive(PartialEq, Eq, Ord, PartialOrd))]
124131
#[non_exhaustive]
125132
pub struct ExplicitNames {
126-
tables: Vec<ExplicitNameEntry>,
127-
funcs: Vec<ExplicitNameEntry>,
133+
entries: Vec<ExplicitNameEntry>,
128134
}
129135

130136
impl ExplicitNames {
131-
pub fn insert_table(&mut self, source_name: impl Into<RawIdentifier>, canonical_name: impl Into<RawIdentifier>) {
132-
self.tables.push(ExplicitNameEntry {
137+
fn insert(
138+
&mut self,
139+
entry: ExplicitNameEntry,
140+
) {
141+
self.entries.push(entry);
142+
}
143+
144+
pub fn insert_table(
145+
&mut self,
146+
source_name: impl Into<RawIdentifier>,
147+
canonical_name: impl Into<RawIdentifier>,
148+
) {
149+
self.insert(ExplicitNameEntry::Table(NameMapping {
133150
source_name: source_name.into(),
134151
canonical_name: canonical_name.into(),
135-
});
152+
}));
136153
}
137-
pub fn insert_function(&mut self, source_name: impl Into<RawIdentifier>, canonical_name: impl Into<RawIdentifier>) {
138-
self.funcs.push(ExplicitNameEntry {
154+
155+
pub fn insert_function(
156+
&mut self,
157+
source_name: impl Into<RawIdentifier>,
158+
canonical_name: impl Into<RawIdentifier>,
159+
) {
160+
self.insert(ExplicitNameEntry::Function(NameMapping {
139161
source_name: source_name.into(),
140162
canonical_name: canonical_name.into(),
141-
});
163+
}));
142164
}
143165

144166
pub fn merge(&mut self, other: ExplicitNames) {
145-
self.tables.extend(other.tables);
146-
self.funcs.extend(other.funcs);
167+
self.entries.extend(other.entries);
147168
}
148169
}
170+
149171
pub type RawRowLevelSecurityDefV10 = crate::db::raw_def::v9::RawRowLevelSecurityDefV9;
150172

151173
/// The definition of a database table.
@@ -350,15 +372,6 @@ pub struct RawIndexDefV10 {
350372
/// Even though there is ABSOLUTELY NO REASON TO.
351373
pub source_name: Option<RawIdentifier>,
352374

353-
/// name for the index used internally and in client codegen
354-
///
355-
/// This is set the user and should not be assumed to follow
356-
/// any particular format.
357-
///
358-
/// May be set to `None` if this is an auto-generated index for which the user
359-
/// has not supplied a name.
360-
pub name: Option<RawIdentifier>,
361-
362375
/// The algorithm parameters for the index.
363376
pub algorithm: RawIndexAlgorithm,
364377
}
@@ -1128,17 +1141,9 @@ impl RawTableDefBuilderV10<'_> {
11281141
}
11291142

11301143
/// Generates a [RawIndexDefV10] using the supplied `columns`.
1131-
pub fn with_index(
1132-
mut self,
1133-
algorithm: RawIndexAlgorithm,
1134-
accessor_name: impl Into<RawIdentifier>,
1135-
index_name: Option<impl Into<RawIdentifier>>,
1136-
) -> Self {
1137-
let accessor_name = accessor_name.into();
1138-
1144+
pub fn with_index(mut self, algorithm: RawIndexAlgorithm, source_name: impl Into<RawIdentifier>) -> Self {
11391145
self.table.indexes.push(RawIndexDefV10 {
1140-
name: index_name.map(Into::into),
1141-
source_name: Some(accessor_name),
1146+
source_name: Some(source_name.into()),
11421147
algorithm,
11431148
});
11441149
self
@@ -1148,7 +1153,6 @@ impl RawTableDefBuilderV10<'_> {
11481153
pub fn with_index_no_accessor_name(mut self, algorithm: RawIndexAlgorithm) -> Self {
11491154
self.table.indexes.push(RawIndexDefV10 {
11501155
source_name: None,
1151-
name: None,
11521156
algorithm,
11531157
});
11541158
self

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1075,8 +1075,8 @@ impl From<RawIndexDefV10> for RawIndexDefV9 {
10751075
fn from(raw: RawIndexDefV10) -> Self {
10761076
RawIndexDefV9 {
10771077
accessor_name: raw.source_name,
1078-
name: raw.name,
10791078
algorithm: raw.algorithm,
1079+
name: None,
10801080
}
10811081
}
10821082
}

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

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -744,7 +744,6 @@ mod tests {
744744
let schedule_at_type = builder.add_type::<ScheduleAt>();
745745

746746
let red_delicious = AlgebraicValue::Sum(SumValue::new(2, ()));
747-
let none = Option::<&str>::None;
748747

749748
builder
750749
.build_table_with_new_type(
@@ -757,10 +756,10 @@ mod tests {
757756
]),
758757
true,
759758
)
760-
.with_index(btree([1, 2]), "apples_id", none)
761-
.with_index(direct(2), "Apples_count_direct", none)
759+
.with_index(btree([1, 2]), "apples_id")
760+
.with_index(direct(2), "Apples_count_direct")
762761
.with_unique_constraint(2)
763-
.with_index(btree(3), "Apples_type_btree", none)
762+
.with_index(btree(3), "Apples_type_btree")
764763
.with_unique_constraint(3)
765764
.with_default_column_value(2, AlgebraicValue::U16(37))
766765
.with_default_column_value(3, red_delicious.clone())
@@ -784,8 +783,8 @@ mod tests {
784783
.with_unique_constraint(ColId(0))
785784
.with_primary_key(0)
786785
.with_access(TableAccess::Private)
787-
.with_index(btree(0), "bananas_count", none)
788-
.with_index(btree([0, 1, 2]), "bananas_count_id_name", none)
786+
.with_index(btree(0), "bananas_count")
787+
.with_index(btree([0, 1, 2]), "bananas_count_id_name")
789788
.finish();
790789

791790
let deliveries_product_type = builder
@@ -799,7 +798,7 @@ mod tests {
799798
true,
800799
)
801800
.with_auto_inc_primary_key(2)
802-
.with_index(btree(2), "scheduled_id_index", none)
801+
.with_index(btree(2), "scheduled_id_index")
803802
.with_type(TableType::System)
804803
.finish();
805804

@@ -1071,7 +1070,7 @@ mod tests {
10711070
ProductType::from([("b", AlgebraicType::U16), ("a", AlgebraicType::U64)]),
10721071
false,
10731072
)
1074-
.with_index(btree([0, 55]), "bananas_a_b", Option::<&str>::None)
1073+
.with_index(btree([0, 55]), "bananas_a_b")
10751074
.finish();
10761075
let result: Result<ModuleDef> = builder.finish().try_into();
10771076

@@ -1150,7 +1149,7 @@ mod tests {
11501149
ProductType::from([("b", AlgebraicType::U16), ("a", AlgebraicType::U64)]),
11511150
false,
11521151
)
1153-
.with_index(btree([0, 0]), "bananas_b_b", None::<&str>)
1152+
.with_index(btree([0, 0]), "bananas_b_b")
11541153
.finish();
11551154
let result: Result<ModuleDef> = builder.finish().try_into();
11561155

@@ -1232,7 +1231,7 @@ mod tests {
12321231
ProductType::from([("b", AlgebraicType::U16), ("a", AlgebraicType::U64)]),
12331232
true,
12341233
)
1235-
.with_index(hash(0), "bananas_b", None::<&str>)
1234+
.with_index(hash(0), "bananas_b")
12361235
.finish();
12371236
let def: ModuleDef = builder.finish().try_into().unwrap();
12381237
let indexes = def.indexes().collect::<Vec<_>>();
@@ -1270,7 +1269,7 @@ mod tests {
12701269
ProductType::from([("b", AlgebraicType::I32), ("a", AlgebraicType::U64)]),
12711270
false,
12721271
)
1273-
.with_index(direct(0), "bananas_b", None::<&str>)
1272+
.with_index(direct(0), "bananas_b")
12741273
.finish();
12751274
let result: Result<ModuleDef> = builder.finish().try_into();
12761275

@@ -1385,7 +1384,7 @@ mod tests {
13851384
true,
13861385
)
13871386
.with_auto_inc_primary_key(2)
1388-
.with_index(btree(2), "scheduled_id_index", None::<&str>)
1387+
.with_index(btree(2), "scheduled_id_index")
13891388
.with_type(TableType::System)
13901389
.finish();
13911390

@@ -1413,7 +1412,7 @@ mod tests {
14131412
true,
14141413
)
14151414
.with_auto_inc_primary_key(2)
1416-
.with_index(direct(2), "scheduled_id_idx", None::<&str>)
1415+
.with_index(direct(2), "scheduled_id_idx")
14171416
.with_type(TableType::System)
14181417
.finish();
14191418

@@ -1446,8 +1445,8 @@ mod tests {
14461445
true,
14471446
)
14481447
.with_auto_inc_primary_key(2)
1449-
.with_index(direct(2), "scheduled_id_index", None::<&str>)
1450-
.with_index(btree([0, 2]), "nice_index_name", None::<&str>)
1448+
.with_index(direct(2), "scheduled_id_index")
1449+
.with_index(btree([0, 2]), "nice_index_name")
14511450
.with_type(TableType::System)
14521451
.finish();
14531452

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1099,7 +1099,9 @@ impl<'a, 'b> TableValidator<'a, 'b> {
10991099
RawModuleDefVersion::V9OrEarlier => accessor_name.map(identifier).transpose(),
11001100

11011101
// In V10, `name` is used both for internal purpose and client codefen.
1102-
RawModuleDefVersion::V10 => identifier(name.clone()).map(Some),
1102+
RawModuleDefVersion::V10 => {
1103+
identifier(generate_index_name(&self.raw_name, self.product_type, &algorithm_raw)).map(Some)
1104+
}
11031105
};
11041106

11051107
let name = self.add_to_global_namespace(name);

0 commit comments

Comments
 (0)