Create a view with an explicit scope and optional named parent. The view's change log starts empty; this only establishes identity.
(
&mut self,
name: &str,
scope: ViewScope,
parent_name: Option<&str>,
)
| 782 | /// |
| 783 | /// The view's change log starts empty; this only establishes identity. |
| 784 | pub fn create_view_with_identity( |
| 785 | &mut self, |
| 786 | name: &str, |
| 787 | scope: ViewScope, |
| 788 | parent_name: Option<&str>, |
| 789 | ) -> Result<(), RepositoryError> { |
| 790 | self.ensure_project_identity(atomic_core::kg::project_id::MintReason::Upgrade)?; |
| 791 | ensure_workspace_dir(&self.dot_dir, name)?; |
| 792 | |
| 793 | let mut txn = self |
| 794 | .pristine |
| 795 | .write_txn() |
| 796 | .map_err(|e| RepositoryError::Database(e.to_string()))?; |
| 797 | |
| 798 | if txn |
| 799 | .get_view(name) |
| 800 | .map_err(|e| RepositoryError::Database(e.to_string()))? |
| 801 | .is_some() |
| 802 | { |
| 803 | return Err(RepositoryError::ViewAlreadyExists { |
| 804 | name: name.to_string(), |
| 805 | }); |
| 806 | } |
| 807 | |
| 808 | let parent_id = match parent_name { |
| 809 | Some(p) => Some( |
| 810 | txn.get_view(p) |
| 811 | .map_err(|e| RepositoryError::Database(e.to_string()))? |
| 812 | .ok_or_else(|| RepositoryError::ViewNotFound { |
| 813 | name: p.to_string(), |
| 814 | })? |
| 815 | .id, |
| 816 | ), |
| 817 | None => None, |
| 818 | }; |
| 819 | |
| 820 | let view = txn |
| 821 | .create_view(name, scope, parent_id) |
| 822 | .map_err(|e| RepositoryError::Database(e.to_string()))?; |
| 823 | super::name_resolution::refresh_name_conflict_caches(&mut txn, view.id)?; |
| 824 | |
| 825 | if txn.kg_writes_enabled()? { |
| 826 | self.project_view_kg(&mut txn)?; |
| 827 | } |
| 828 | |
| 829 | txn.commit() |
| 830 | .map_err(|e| RepositoryError::Database(e.to_string()))?; |
| 831 | |
| 832 | Ok(()) |
| 833 | } |
| 834 | |
| 835 | /// Export a view's complete identity as a [`ViewManifest`]. |
| 836 | /// |