1 /* wc-checks.sql -- trigger-based checks for the wc-metadata database.
2 * This is intended for use with SQLite 3
4 * ====================================================================
5 * Licensed to the Apache Software Foundation (ASF) under one
6 * or more contributor license agreements. See the NOTICE file
7 * distributed with this work for additional information
8 * regarding copyright ownership. The ASF licenses this file
9 * to you under the Apache License, Version 2.0 (the
10 * "License"); you may not use this file except in compliance
11 * with the License. You may obtain a copy of the License at
13 * http://www.apache.org/licenses/LICENSE-2.0
15 * Unless required by applicable law or agreed to in writing,
16 * software distributed under the License is distributed on an
17 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
18 * KIND, either express or implied. See the License for the
19 * specific language governing permissions and limitations
21 * ====================================================================
25 -- STMT_VERIFICATION_TRIGGERS
27 /* ------------------------------------------------------------------------- */
29 CREATE TEMPORARY TRIGGER no_repository_updates BEFORE UPDATE ON repository
31 SELECT RAISE(FAIL, 'Updates to REPOSITORY are not allowed.');
34 /* ------------------------------------------------------------------------- */
36 /* Verify: on every NODES row: parent_relpath is parent of local_relpath */
37 CREATE TEMPORARY TRIGGER validation_01 BEFORE INSERT ON nodes
38 WHEN NOT ((new.local_relpath = '' AND new.parent_relpath IS NULL)
39 OR (relpath_depth(new.local_relpath)
40 = relpath_depth(new.parent_relpath) + 1))
42 SELECT RAISE(FAIL, 'WC DB validity check 01 failed');
45 /* Verify: on every NODES row: its op-depth <= its own depth */
46 CREATE TEMPORARY TRIGGER validation_02 BEFORE INSERT ON nodes
47 WHEN NOT new.op_depth <= relpath_depth(new.local_relpath)
49 SELECT RAISE(FAIL, 'WC DB validity check 02 failed');
52 /* Verify: on every NODES row: it is an op-root or it has a parent with the
53 sames op-depth. (Except when the node is a file external) */
54 CREATE TEMPORARY TRIGGER validation_03 BEFORE INSERT ON nodes
56 (new.op_depth = relpath_depth(new.local_relpath))
58 (EXISTS (SELECT 1 FROM nodes
59 WHERE wc_id = new.wc_id AND op_depth = new.op_depth
60 AND local_relpath = new.parent_relpath))
62 AND NOT (new.file_external IS NOT NULL AND new.op_depth = 0)
64 SELECT RAISE(FAIL, 'WC DB validity check 03 failed');
67 /* Verify: on every ACTUAL row (except root): a NODES row exists at its
69 CREATE TEMPORARY TRIGGER validation_04 BEFORE INSERT ON actual_node
70 WHEN NOT (new.local_relpath = ''
71 OR EXISTS (SELECT 1 FROM nodes
72 WHERE wc_id = new.wc_id
73 AND local_relpath = new.parent_relpath))
75 SELECT RAISE(FAIL, 'WC DB validity check 04 failed');