Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions crates/registry-breg/src/package.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2835,6 +2835,41 @@ fn additive_migration_plan(
}
}

// PostgreSQL can replace a view only when its existing columns keep their
// positions. An insertion or reordering needs the candidate's exact
// projection, including in the derived views that read the source views.
if previous.entities.iter().any(|(id, prior)| {
candidate.entities().get(id).is_some_and(|current| {
!current
.source_relation
.stored_fields
.starts_with(&prior.source_relation.stored_fields)
})
}) {
let prior_views = previous_ddl
.views
.iter()
.filter(|view| matches!(view.schema.as_str(), "registry_source" | "registry_derived"))
.map(|view| format!("{}.{}", view.schema, quote_identifier(&view.name)))
.collect::<Vec<_>>();
// One RESTRICT drop includes dependencies within the managed set and
// refuses any dependents outside it. The candidate DDL below installs
// source views before derived views.
removed_dependency_statements.push(DdlStatement {
id: "registry.read-views.drop".to_owned(),
kind: DdlStatementKind::View,
sql: format!("DROP VIEW {} RESTRICT", prior_views.join(", ")),
});
for statement in &candidate.ddl().statements {
if statement.kind == DdlStatementKind::View
&& !is_spatial_candidate_view_statement(statement)
{
replacement_statement_ids.remove(&statement.id);
new_statement_ids.insert(statement.id.clone());
}
}
}

let mut statements = removed_dependency_statements;
for statement in &candidate.ddl().statements {
if let Some(entity_id) = table_statement_entity_id(&statement.id) {
Expand Down
Loading
Loading