Skip to content

Commit

Permalink
WIP: Allow cyclic AlgebraicTypes.
Browse files Browse the repository at this point in the history
  • Loading branch information
kazimuth committed Sep 6, 2024
1 parent d537e92 commit 01df119
Show file tree
Hide file tree
Showing 3 changed files with 502 additions and 218 deletions.
15 changes: 4 additions & 11 deletions crates/schema/src/def/validate/v8.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ fn upgrade_table(
) -> RawTableDefV9 {
// First, generate all the various things that are needed.
// This is the hairiest part of v8.
let generated_indexes = table.schema.generated_indexes().collect::<Vec<_>>();
let generated_constraints = table.schema.generated_constraints().collect::<Vec<_>>();
let generated_sequences = table.schema.generated_sequences().collect::<Vec<_>>();

Expand All @@ -96,13 +95,7 @@ fn upgrade_table(
check_all_column_defs(product_type_ref, columns, &table_name, typespace, extra_errors);

// Now we're ready to go through the various definitions and upgrade them.
let indexes = convert_all(
indexes
.into_iter()
.map(|idx| (idx, false))
.chain(generated_indexes.into_iter().map(|idx| (idx, true))),
|(idx, is_generated)| upgrade_index(idx, is_generated),
);
let indexes = convert_all(indexes, upgrade_index);
let sequences = convert_all(sequences.into_iter().chain(generated_sequences), upgrade_sequence);
let schedule = upgrade_schedule(scheduled, &table_name);

Expand Down Expand Up @@ -223,7 +216,7 @@ fn check_column(
}

/// Upgrade an index.
fn upgrade_index(index: RawIndexDefV8, is_generated: bool) -> RawIndexDefV9 {
fn upgrade_index(index: RawIndexDefV8) -> RawIndexDefV9 {
let RawIndexDefV8 {
index_name,
is_unique: _, // handled by generated_constraints
Expand All @@ -237,7 +230,7 @@ fn upgrade_index(index: RawIndexDefV8, is_generated: bool) -> RawIndexDefV9 {
};
// The updated bindings macros will correctly distinguish between accessor name and index name as specified in the
// ABI stability proposal. The old macros don't make this distinction, so we just reuse the name for them.
let accessor_name = if is_generated { None } else { Some(index_name.clone()) };
let accessor_name = Some(index_name.clone());
RawIndexDefV9 {
name: index_name.clone(),
// Set the accessor name to be the same as the index name.
Expand Down Expand Up @@ -285,7 +278,7 @@ fn upgrade_constraint(
data: RawConstraintDataV9::Unique(RawUniqueConstraintDataV9 { columns }),
})
} else {
// other constraints are implemented by `generated_indexes` and `generated_sequences`.
// other constraints are implemented by `generated_sequences`.
// Note that `Constraints::unset` will not trigger any of the preceding branches, so will be ignored.
// This is consistent with the original `TableSchema::from_(raw_)def`, which also ignored `Constraints::unset`.
None
Expand Down
Loading

0 comments on commit 01df119

Please sign in to comment.