uqa_engine/capabilities/
relation_removal.rs1use crate::Engine;
9use uqa_execution::schema::removal::entry::{
10 DomainRemovalWrite, DropStatementBindings, ForeignServerRemovalWrite, SchemaRemovalWrite,
11};
12use uqa_execution::schema::removal::{
13 RelationRemovalContext, RelationRemovalEvents, RelationRemovalLocks, RelationRemovalPrivileges,
14 RelationRemovalTransactions, RelationRemovalViews, RelationRemovalWrite,
15};
16use uqa_sql::{
17 catalog::resolution::RelationResolution, schema::removal::RelationDropCatalog, SQLError,
18 SQLResult,
19};
20
21impl DropStatementBindings for Engine {
22 fn with_foreign_server_removal_write(
23 &self,
24 write: ForeignServerRemovalWrite<'_>,
25 ) -> Result<SQLResult, SQLError> {
26 self.with_implicit_definition_transaction(|engine| {
27 write(&engine.foreign_server_removal_context())
28 })
29 }
30 fn with_schema_removal_write(
31 &self,
32 write: SchemaRemovalWrite<'_>,
33 ) -> Result<SQLResult, SQLError> {
34 self.with_implicit_definition_transaction(|engine| write(&engine.schema_removal_context()))
35 }
36 fn with_domain_removal_write(
37 &self,
38 write: DomainRemovalWrite<'_>,
39 ) -> Result<SQLResult, SQLError> {
40 self.with_implicit_definition_transaction(|engine| write(&engine.domain_removal_context()))
41 }
42 fn with_relation_removal_inputs(
43 &self,
44 run: RelationRemovalWrite<'_>,
45 ) -> Result<SQLResult, SQLError> {
46 run(&self.relation_removal_context())
47 }
48}
49
50impl Engine {
51 pub(crate) fn relation_removal_context(&self) -> RelationRemovalContext<'_> {
52 RelationRemovalContext {
53 deletion: self,
54 catalog: self,
55 tables: self.table_removal_context(),
56 privileges: self,
57 views: self,
58 sequences: self,
59 identities: self,
60 locks: self,
61 transactions: self,
62 notices: self.query_runtime_view().notices,
63 indexes: self.index_removal_context(),
64 }
65 }
66}
67impl RelationDropCatalog for Engine {
68 fn resolve_relation_kind(&self, name: &str) -> Result<RelationResolution, SQLError> {
69 self.resolve_visible_relation_kind(name)
70 }
71 fn resolve_age_label_relation_name(&self, name: &str) -> Result<Option<String>, SQLError> {
72 uqa_execution::catalog::projection::resolve_age_label_relation_name(
73 &self.catalog_execution(),
74 name,
75 )
76 }
77}
78impl RelationRemovalPrivileges for Engine {
79 fn ensure_table_drop_authority(&self, table: &str) -> Result<(), SQLError> {
80 Engine::ensure_table_drop_authority(self, table)
81 }
82 fn ensure_foreign_table_drop_authority(&self, table: &str) -> Result<(), SQLError> {
83 Engine::ensure_foreign_table_drop_authority(self, table)
84 }
85}
86impl RelationRemovalEvents for Engine {
87 fn ensure_no_pending_trigger_events(&self, table: &str, action: &str) -> Result<(), SQLError> {
88 Engine::ensure_no_pending_trigger_events(self, table, action)
89 }
90}
91impl RelationRemovalViews for Engine {
92 fn lock_dependent_views(&self, names: &[String]) -> Result<(), SQLError> {
93 uqa_execution::schema::view_removal::locking::lock_dependent_views(self, self, names)
94 .map(|_| ())
95 }
96 fn ensure_view_drop_authority(&self, name: &str) -> Result<(), SQLError> {
97 uqa_execution::schema::view_removal::ensure_view_drop_authorities(
98 &self.view_removal_context(),
99 &[name.to_string()],
100 )
101 }
102}
103
104impl RelationRemovalLocks for Engine {
105 fn lock_exclusive(&self, table: &str) -> Result<(), SQLError> {
106 self.lock_relation(table, crate::row_locks::RelationLockMode::AccessExclusive)
107 }
108}
109impl RelationRemovalTransactions for Engine {
110 fn with_relation_write(&self, write: RelationRemovalWrite<'_>) -> Result<SQLResult, SQLError> {
111 self.with_implicit_definition_transaction(|engine| {
112 write(&engine.relation_removal_context())
113 })
114 }
115}