Update the database according to the migration plan. The update is performed within the transactional context `tx`. NOTE: Manual migration support is predicated on the transactionality of dropping database objects (tables, indexes, etc.). Currently, none of the drop_* methods are transactional. This is safe because the __update__ reducer is no longer supported, and the auto plan guarantees that t
(
stdb: &RelationalDB,
tx: &mut MutTxId,
auth_ctx: AuthCtx,
plan: MigratePlan,
logger: &dyn UpdateLogger,
)
| 125 | // But when implementing manual migrations, we need to make sure that |
| 126 | // drop_* become transactional. |
| 127 | pub fn update_database( |
| 128 | stdb: &RelationalDB, |
| 129 | tx: &mut MutTxId, |
| 130 | auth_ctx: AuthCtx, |
| 131 | plan: MigratePlan, |
| 132 | logger: &dyn UpdateLogger, |
| 133 | ) -> anyhow::Result<UpdateResult> { |
| 134 | let existing_tables = stdb.get_all_tables_mut(tx)?; |
| 135 | |
| 136 | // TODO: consider using `ErrorStream` here. |
| 137 | let old_module_def = plan.old_def(); |
| 138 | for table in existing_tables |
| 139 | .iter() |
| 140 | .filter(|table| table.table_type != StTableType::System && !table.is_view()) |
| 141 | { |
| 142 | let old_def = old_module_def |
| 143 | .table(&table.table_name[..]) |
| 144 | .ok_or_else(|| anyhow::anyhow!("table {} not found in old_module_def", table.table_name))?; |
| 145 | |
| 146 | table.check_compatible(old_module_def, old_def)?; |
| 147 | } |
| 148 | |
| 149 | match plan { |
| 150 | MigratePlan::Manual(plan) => manual_migrate_database(stdb, tx, plan, logger), |
| 151 | MigratePlan::Auto(plan) => auto_migrate_database(stdb, tx, auth_ctx, plan, logger), |
| 152 | } |
| 153 | } |
| 154 | |
| 155 | /// Manually migrate a database. |
| 156 | fn manual_migrate_database( |
searching dependent graphs…