coven_database/schema_error.rs
1//! The schema rules checked when a store opens and after it migrates.
2
3/// A schema rule checked on open and after migrating (§9, §15.1).
4#[derive(Clone, Debug, Eq, PartialEq, thiserror::Error)]
5pub enum SchemaError {
6 /// Two namespace declarations share a name (E1).
7 #[error("file namespace {namespace} is declared twice")]
8 DuplicateNamespace {
9 /// The namespace.
10 namespace: String,
11 },
12 /// A synced foreign key does not reference the complete parent primary key (§9.1).
13 #[error("foreign key {table}: {key} must reference the parent's primary key")]
14 ForeignKeyNotPrimaryKey {
15 /// The referencing synced table.
16 table: String,
17 /// The foreign key's columns and referenced table and columns, as SQL.
18 key: String,
19 },
20 /// SET DEFAULT is on a synced table or references one (§9.1).
21 #[error("foreign key {table}: {key} cannot use SET DEFAULT")]
22 SetDefault {
23 /// The referencing table.
24 table: String,
25 /// The foreign key's columns and referenced table and columns, as SQL.
26 key: String,
27 },
28 /// A local foreign key could prevent deletion of a synced row (§9.1).
29 #[error("local reference {table}.{column} must use CASCADE or nullable SET NULL")]
30 LocalChildAction {
31 /// The local child table.
32 table: String,
33 /// The referencing column.
34 column: String,
35 },
36 /// A local foreign key could stop coven updating a synced value in place (§9.1).
37 #[error("local reference {table}.{column} must use ON UPDATE CASCADE or SET NULL")]
38 LocalChildUpdate {
39 /// The local child table.
40 table: String,
41 /// The referencing column.
42 column: String,
43 },
44 /// A declared synced table isn't in the database (E2).
45 #[error("declared synced table {table} is missing")]
46 MissingTable {
47 /// The declared table.
48 table: String,
49 },
50 /// Two declarations name one table (E2).
51 #[error("synced table {table} is declared twice")]
52 DuplicateTable {
53 /// The repeated table.
54 table: String,
55 },
56 /// A synced table's write permission (`owner_only`, `admin_only` or
57 /// neither) changed without a breaking migration to raise the schema
58 /// (§18.3).
59 #[error("synced table {table} changed who may write it without a migration")]
60 WritePermissionChanged {
61 /// The table whose declaration changed.
62 table: String,
63 },
64 /// A table declares both `audience_column` and `audience_from` (E2).
65 #[error("synced table {table} declares two audience sources")]
66 TwoAudiences {
67 /// The declared table.
68 table: String,
69 },
70 /// A synced table's file reference columns changed without a breaking
71 /// migration to raise the schema (§18.1).
72 #[error("synced table {table} changed its file columns without a migration")]
73 FileColumnsChanged {
74 /// The table whose declaration changed.
75 table: String,
76 },
77 /// A column is declared a file reference twice (E2).
78 #[error("file column {table}.{column} is declared twice")]
79 FileColumnRepeated {
80 /// The declared table.
81 table: String,
82 /// The repeated column.
83 column: String,
84 },
85 /// A file reference column is generated, so coven can't write it (E2).
86 #[error("file column {table}.{column} is generated")]
87 FileColumnGenerated {
88 /// The declared table.
89 table: String,
90 /// The generated column.
91 column: String,
92 },
93 /// An SQL foreign key references coven's files table, which only
94 /// declared file columns reference (§17.2, E2). `key` names the
95 /// referencing columns and referenced table and columns as SQL.
96 #[error("{table}'s foreign key {key} references coven_files; declare a file column instead")]
97 FilesForeignKey {
98 /// The table holding the key.
99 table: String,
100 /// The key, as SQL.
101 key: String,
102 },
103 /// A file reference column is also an SQL foreign key (E2).
104 #[error("file column {table}.{column} is also a foreign key")]
105 FileColumnForeignKey {
106 /// The declared table.
107 table: String,
108 /// The column.
109 column: String,
110 },
111 /// A declared file column isn't in the table (E2).
112 #[error("file column {table}.{column} is missing")]
113 FileColumn {
114 /// The declared table.
115 table: String,
116 /// The missing column.
117 column: String,
118 },
119 /// A trigger declared shared isn't on the table (§9.4).
120 #[error("shared trigger {trigger} is missing from {table}")]
121 MissingTrigger {
122 /// The declared table.
123 table: String,
124 /// The missing trigger.
125 trigger: String,
126 },
127 /// A synced table has no primary key (§9.2).
128 #[error("synced table {table} has no primary key")]
129 NoPrimaryKey {
130 /// The declared table.
131 table: String,
132 },
133 /// A primary-key column of a synced or device-local table permits NULL
134 /// (§9.2).
135 #[error("primary-key column {table}.{column} allows NULL")]
136 NullableKey {
137 /// The table.
138 table: String,
139 /// The nullable key column.
140 column: String,
141 },
142 /// A synced key column compares text by a collation other than BINARY (§9.2, D3).
143 #[error(
144 "key column {table}.{column} uses collation {collation}; synced keys compare text by bytes"
145 )]
146 KeyCollation {
147 /// The table holding the key, unique constraint or foreign key.
148 table: String,
149 /// The column, or for an expression term the unique index naming it.
150 column: String,
151 /// The column's or index term's collation.
152 collation: String,
153 },
154 /// SQLite chooses the primary key itself (§9.2).
155 #[error("SQLite generates the primary key of {table}")]
156 GeneratedPrimaryKey {
157 /// The declared table.
158 table: String,
159 },
160 /// An independent key has no text-affinity column to hold its UUID (§9.2).
161 #[error("independent key of {table} has no text-affinity column to hold its UUID")]
162 IndependentKeyNotUuid {
163 /// The declared table.
164 table: String,
165 },
166 /// Declared key columns do not match the table's primary key (E2).
167 #[error("declared key columns differ from the primary key of {table}")]
168 KeyColumns {
169 /// The declared table.
170 table: String,
171 },
172 /// A foreign key includes a generated column (§9.1).
173 #[error("foreign key includes generated column {table}.{column}")]
174 GeneratedForeignKey {
175 /// The synced or local table.
176 table: String,
177 /// The generated referencing column.
178 column: String,
179 },
180 /// SET NULL would put NULL in a NOT NULL column (§9.1).
181 #[error("foreign key action would put NULL in non-null column {table}.{column}")]
182 ImpossibleAction {
183 /// The synced or local table.
184 table: String,
185 /// The non-null referencing column.
186 column: String,
187 },
188 /// SET NULL acts on a primary-key column (§9.1).
189 #[error("foreign key action changes key column {table}.{column}")]
190 PrimaryKeyAction {
191 /// The declared table.
192 table: String,
193 /// The primary-key column.
194 column: String,
195 },
196 /// The audience root column is nullable, is not text, or is generated
197 /// (§15, E2).
198 #[error("audience column {table}.{column} must be non-null text, not generated")]
199 AudienceColumn {
200 /// The declared table.
201 table: String,
202 /// The audience column.
203 column: String,
204 },
205 /// The audience foreign key spans more than one column (§15.1).
206 #[error("audience foreign key of {table} must have one column")]
207 AudienceForeignKeyColumns {
208 /// The declared table.
209 table: String,
210 },
211 /// The audience foreign key does not point into a synced table (§15.1).
212 #[error("audience foreign key {table}.{column} must point into a synced table")]
213 AudienceForeignKeyTarget {
214 /// The declared table.
215 table: String,
216 /// The audience foreign-key column.
217 column: String,
218 },
219 /// The audience foreign key uses SET NULL (§15.1).
220 #[error("audience foreign key {table}.{column} cannot use SET NULL")]
221 AudienceForeignKeyAction {
222 /// The declared table.
223 table: String,
224 /// The audience foreign-key column.
225 column: String,
226 },
227 /// Following audience foreign keys forms a loop (§15.1).
228 #[error("audience inheritance from {table} forms a cycle")]
229 AudienceCycle {
230 /// The table from which the cycle was reached.
231 table: String,
232 },
233 /// A unique constraint or shared key spans audiences (§15.2).
234 #[error("constraint {constraint} of {table} spans audiences")]
235 AudienceConstraint {
236 /// The declared table.
237 table: String,
238 /// The primary key or unique index.
239 constraint: String,
240 },
241 /// A shared trigger lacks WHEN NOT coven_applying() (§9.4).
242 #[error("shared trigger {trigger} on {table} requires WHEN NOT coven_applying()")]
243 SharedTriggerGuard {
244 /// The declared table.
245 table: String,
246 /// The shared trigger.
247 trigger: String,
248 },
249 /// A trigger on `coven_files`, `coven_pins`, `coven_pin_requests`,
250 /// `coven_moves`, `coven_upload_queue`, `coven_pending`,
251 /// `coven_sync_status` or `coven_retry_effect` runs before the change,
252 /// where it could skip or refuse coven's own (§9.4).
253 #[error("trigger {trigger} on {table} must run AFTER the change")]
254 TriggerTiming {
255 /// The trigger.
256 trigger: String,
257 /// The table of coven's it follows.
258 table: String,
259 },
260}