forked from dbt-labs/dbt-core
-
Notifications
You must be signed in to change notification settings - Fork 0
/
sample.schema.yml
74 lines (61 loc) · 2.04 KB
/
sample.schema.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# This configuration file specifies constraints that should (ideally)
# be true about your data models. The constraints can be tested using
# the `dbt test --schema` command. When that command is executed, dbt
# will compile this schema.yml file to a series of SQL statements and
# validate that the specified constraints hold against your data.
# A dbt project can contain any number of schema.yml files. Moreover,
# schema.yml files can be placed anywhere within the `models` directory
# of your dbt project.
# There are four types of schema validations:
# - Not null
# - Unique
# - Referential integrity
# - Field in list of accepted values
# A schema.yml file should specify constraints for one or more models.
# These constraints should adhere to the following structure:
# [model-name]:
# constraints:
# not_null:
# - [field or expression]
# - [field or expression]
# ...
#
# unique:
# - [field or expression]
# - [field or expression]
# ...
#
# relationships:
# - {from: [field], to: [other-model], field: [other-field]}
# ...
#
# accepted_values:
# - {field: [field or expression], values: ['valid', 'values', 'here']}
# ...
#
# Below is an example of some schema constraints defined for fictitious models.
#
people:
constraints:
# check number of times these fields are null (should be 0)
not_null:
- id
- account_id
- name
# count number of non-unique `id` fields (should be 0)
unique:
- id
# count number of rows where `people.account_id` points to a nonexistent `accounts.id` (should be 0)
# Note: the 'accounts' model needs to be `ref`d here
relationships:
- {from: account_id, to: ref('accounts'), field: id}
accounts:
constraints:
# count number of rows where a value is not in the given accepted values
accepted_values:
- {field: tier, values: ['paid', 'free']}
not_null:
- id
- domain
unique:
- id