]> CyberLeo.Net >> Repos - FreeBSD/releng/10.0.git/blob - contrib/subversion/subversion/libsvn_wc/wc-checks.sql
- Copy stable/10 (r259064) to releng/10.0 as part of the
[FreeBSD/releng/10.0.git] / contrib / subversion / subversion / libsvn_wc / wc-checks.sql
1 /* wc-checks.sql -- trigger-based checks for the wc-metadata database.
2  *     This is intended for use with SQLite 3
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
12  *
13  *      http://www.apache.org/licenses/LICENSE-2.0
14  *
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
20  *    under the License.
21  * ====================================================================
22  */
23
24
25 -- STMT_VERIFICATION_TRIGGERS
26
27 /* ------------------------------------------------------------------------- */
28
29 CREATE TEMPORARY TRIGGER no_repository_updates BEFORE UPDATE ON repository
30 BEGIN
31   SELECT RAISE(FAIL, 'Updates to REPOSITORY are not allowed.');
32 END;
33
34 /* ------------------------------------------------------------------------- */
35
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))
41 BEGIN
42   SELECT RAISE(FAIL, 'WC DB validity check 01 failed');
43 END;
44
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)
48 BEGIN
49   SELECT RAISE(FAIL, 'WC DB validity check 02 failed');
50 END;
51
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
55 WHEN NOT (
56     (new.op_depth = relpath_depth(new.local_relpath))
57     OR
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))
61   )
62  AND NOT (new.file_external IS NOT NULL AND new.op_depth = 0)
63 BEGIN
64   SELECT RAISE(FAIL, 'WC DB validity check 03 failed');
65 END;
66
67 /* Verify: on every ACTUAL row (except root): a NODES row exists at its
68  * parent path. */
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))
74 BEGIN
75   SELECT RAISE(FAIL, 'WC DB validity check 04 failed');
76 END;
77