Skip to content

Commit 7db6da2

Browse files
committed
use SequenceId everywhere
1 parent 462cf27 commit 7db6da2

File tree

5 files changed

+17
-19
lines changed

5 files changed

+17
-19
lines changed

crates/core/src/db/datastore/locking_tx_datastore/mod.rs

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -425,7 +425,7 @@ impl Inner {
425425
&st_sequences_schema(),
426426
);
427427
let row = StSequenceRow {
428-
sequence_id: seq_id.0,
428+
sequence_id: seq_id,
429429
sequence_name: &format!("{}_seq", col.col_name),
430430
table_id: col.table_id,
431431
col_id: col.col_id,
@@ -529,9 +529,7 @@ impl Inner {
529529
seq.value = sequence.allocated + 1;
530530
}
531531

532-
self.sequence_state
533-
.sequences
534-
.insert(SequenceId(sequence.sequence_id), seq);
532+
self.sequence_state.sequences.insert(sequence.sequence_id, seq);
535533
}
536534
Ok(())
537535
}
@@ -659,7 +657,7 @@ impl Inner {
659657
// NOTE: Because st_sequences has a unique index on sequence_name, this will
660658
// fail if the table already exists.
661659
let sequence_row = StSequenceRow {
662-
sequence_id: 0, // autogen'd
660+
sequence_id: SequenceId(0), // autogen'd
663661
sequence_name: seq.sequence_name.as_str(),
664662
table_id: seq.table_id,
665663
col_id: seq.col_id,
@@ -672,7 +670,7 @@ impl Inner {
672670
let row = (&sequence_row).into();
673671
let result = self.insert(ST_SEQUENCES_ID, row)?;
674672
let sequence_row = StSequenceRow::try_from(&result)?;
675-
let sequence_id = SequenceId(sequence_row.sequence_id);
673+
let sequence_id = sequence_row.sequence_id;
676674

677675
let schema = (&sequence_row).into();
678676
self.sequence_state.sequences.insert(sequence_id, Sequence::new(schema));
@@ -908,7 +906,7 @@ impl Inner {
908906
for data_ref in rows {
909907
let row = data_ref.view();
910908
let el = StSequenceRow::try_from(row)?;
911-
self.drop_sequence(SequenceId(el.sequence_id))?;
909+
self.drop_sequence(el.sequence_id)?;
912910
}
913911

914912
// Remove the table's columns from st_columns.
@@ -1198,7 +1196,7 @@ impl Inner {
11981196
if seq_row.col_id != col.col_id {
11991197
continue;
12001198
}
1201-
let sequence_value = self.get_next_sequence_value(SequenceId(seq_row.sequence_id))?;
1199+
let sequence_value = self.get_next_sequence_value(seq_row.sequence_id)?;
12021200
row.elements[col.col_id.idx()] = Self::sequence_value_to_algebraic_value(
12031201
&schema.table_name,
12041202
&col.col_name,
@@ -2164,7 +2162,7 @@ mod tests {
21642162
error::ResultTest,
21652163
ColumnIndexAttribute,
21662164
};
2167-
use spacetimedb_primitives::{IndexId, TableId};
2165+
use spacetimedb_primitives::{IndexId, TableId, SequenceId};
21682166
use spacetimedb_sats::{product, AlgebraicType, AlgebraicValue, ProductValue};
21692167

21702168
fn u32_str_u32(a: u32, b: &str, c: u32) -> ProductValue {
@@ -2387,10 +2385,10 @@ mod tests {
23872385
assert_eq!(
23882386
sequence_rows,
23892387
vec![
2390-
StSequenceRow { sequence_id: 0, sequence_name: "table_id_seq".to_string(), table_id: TableId(0), col_id: ColId(0), increment: 1, start: 6, min_value: 1, max_value: 4294967295, allocated: 4096 },
2391-
StSequenceRow { sequence_id: 1, sequence_name: "sequence_id_seq".to_string(), table_id: TableId(2), col_id: ColId(0), increment: 1, start: 4, min_value: 1, max_value: 4294967295, allocated: 4096 },
2392-
StSequenceRow { sequence_id: 2, sequence_name: "index_id_seq".to_string(), table_id: TableId(3), col_id: ColId(0), increment: 1, start: 6, min_value: 1, max_value: 4294967295, allocated: 4096 },
2393-
StSequenceRow { sequence_id: 3, sequence_name: "constraint_id_seq".to_string(), table_id: TableId(4), col_id: ColId(0), increment: 1, start: 1, min_value: 1, max_value: 4294967295, allocated: 4096 },
2388+
StSequenceRow { sequence_id: SequenceId(0), sequence_name: "table_id_seq".to_string(), table_id: TableId(0), col_id: ColId(0), increment: 1, start: 6, min_value: 1, max_value: 4294967295, allocated: 4096 },
2389+
StSequenceRow { sequence_id: SequenceId(1), sequence_name: "sequence_id_seq".to_string(), table_id: TableId(2), col_id: ColId(0), increment: 1, start: 4, min_value: 1, max_value: 4294967295, allocated: 4096 },
2390+
StSequenceRow { sequence_id: SequenceId(2), sequence_name: "index_id_seq".to_string(), table_id: TableId(3), col_id: ColId(0), increment: 1, start: 6, min_value: 1, max_value: 4294967295, allocated: 4096 },
2391+
StSequenceRow { sequence_id: SequenceId(3), sequence_name: "constraint_id_seq".to_string(), table_id: TableId(4), col_id: ColId(0), increment: 1, start: 1, min_value: 1, max_value: 4294967295, allocated: 4096 },
23942392
]
23952393
);
23962394
let constraints_rows = datastore

crates/core/src/db/datastore/system_tables.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -758,7 +758,7 @@ impl<Name: AsRef<str>> From<&StIndexRow<Name>> for ProductValue {
758758

759759
#[derive(Debug, PartialEq, Eq)]
760760
pub struct StSequenceRow<Name: AsRef<str>> {
761-
pub(crate) sequence_id: u32,
761+
pub(crate) sequence_id: SequenceId,
762762
pub(crate) sequence_name: Name,
763763
pub(crate) table_id: TableId,
764764
pub(crate) col_id: ColId,
@@ -788,7 +788,7 @@ impl<Name: AsRef<str>> StSequenceRow<Name> {
788788
impl<'a> TryFrom<&'a ProductValue> for StSequenceRow<&'a str> {
789789
type Error = DBError;
790790
fn try_from(row: &'a ProductValue) -> Result<StSequenceRow<&'a str>, DBError> {
791-
let sequence_id = row.field_as_u32(StSequenceFields::SequenceId as usize, None)?;
791+
let sequence_id = SequenceId(row.field_as_u32(StSequenceFields::SequenceId as usize, None)?);
792792
let sequence_name = row.field_as_str(StSequenceFields::SequenceName as usize, None)?;
793793
let table_id = TableId(row.field_as_u32(StSequenceFields::TableId as usize, None)?);
794794
let col_id = ColId(row.field_as_u32(StSequenceFields::ColId as usize, None)?);

crates/core/src/db/datastore/traits.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use super::{system_tables::StTableRow, Result};
1313

1414
#[derive(Debug, Clone, PartialEq, Eq)]
1515
pub struct SequenceSchema {
16-
pub(crate) sequence_id: u32,
16+
pub(crate) sequence_id: SequenceId,
1717
pub(crate) sequence_name: String,
1818
pub(crate) table_id: TableId,
1919
pub(crate) col_id: ColId,

crates/core/src/vm.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -518,7 +518,7 @@ pub(crate) mod tests {
518518
use nonempty::NonEmpty;
519519
use spacetimedb_lib::error::ResultTest;
520520
use spacetimedb_lib::relation::{DbTable, FieldName};
521-
use spacetimedb_primitives::TableId;
521+
use spacetimedb_primitives::{TableId, SequenceId};
522522
use spacetimedb_sats::{product, AlgebraicType, ProductType, ProductValue};
523523
use spacetimedb_vm::dsl::*;
524524
use spacetimedb_vm::eval::run_ast;
@@ -748,7 +748,7 @@ pub(crate) mod tests {
748748
p,
749749
ST_SEQUENCES_NAME,
750750
(&StSequenceRow {
751-
sequence_id: 1,
751+
sequence_id: SequenceId(1),
752752
sequence_name: "sequence_id_seq",
753753
table_id: TableId(2),
754754
col_id: ColId(0),

crates/primitives/src/ids.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ impl ColId {
2121
#[repr(transparent)]
2222
pub struct IndexId(pub u32);
2323

24-
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
24+
#[derive(Debug, Copy, Clone, Hash, Eq, PartialEq, Ord, PartialOrd)]
2525
#[repr(transparent)]
2626
pub struct SequenceId(pub u32);
2727

0 commit comments

Comments
 (0)