Skip to content

Commit 93b01a8

Browse files
committed
feat(constraints) : adding constraints and descriptive documentation to columns in demo models
1 parent 74bc05a commit 93b01a8

5 files changed

Lines changed: 220 additions & 3 deletions

File tree

projects/demo/models/marts/categorizations/schema.yml

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,47 @@
1+
version: 2
2+
3+
models:
4+
- name: categorizations
5+
schema: "{{ env_var('TARGET_SCHEMA') }}"
6+
description: "Categories and subcategories related to categorizations on the platform"
7+
8+
# Model-level constraints
9+
constraints:
10+
- type: primary_key
11+
columns: [id]
12+
- type: foreign_key
13+
columns: [decidim_category_id]
14+
expression: "{{ target.schema }}.decidim_categories (id)"
15+
- type: foreign_key
16+
columns: [categorizable_id]
17+
expression: "{{ target.schema }}.decidim_proposals (id)"
18+
- type: foreign_key
19+
columns: [categorizable_id]
20+
expression: "{{ target.schema }}.decidim_budgets (id)"
21+
columns:
22+
- name: id
23+
description: "The unique identifier for a categorization"
24+
constraints:
25+
- type: not_null
26+
- type: unique
27+
- type: primary_key
28+
- name: category_name
29+
description: "The name of the category"
30+
- name: child_id
31+
description: "The ID of the child category (if applicable)"
32+
- name: child_name
33+
description: "The name of the child category (if applicable)"
34+
- name: categorizable_id
35+
description: "The ID of the resource being categorized (could be proposal or budget)"
36+
constraints:
37+
- type: not_null
38+
- type: foreign_key
39+
expression: "{{ target.schema }}.decidim_proposals (id)"
40+
- type: not_null
41+
- type: foreign_key
42+
expression: "{{ target.schema }}.decidim_budgets (id)"
43+
- name: categorizable_type
44+
description: "The type of resource being categorized (could be proposal or budget)"
145
unit_tests:
246
- name: testing_that_main_categories_are_properly_processed
347
description: "Checks that main categories has the correct infos "

projects/demo/models/marts/components/schema.yml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,26 @@ version: 2
33
models:
44
- name: components
55
description: "Model representing the components associated with participatory spaces in Decidim."
6+
# model-level constraints
7+
constraints:
8+
- type: primary_key
9+
columns: [id]
10+
- type: foreign_key
11+
columns: [ps_id]
12+
expression: "{{ target.schema }}.participatory_spaces (id)"
13+
- type: foreign_key
14+
columns: [decidim_organization_id]
15+
expression: "{{ target.schema }}.decidim_organizations (id)"
616
columns:
717
- name: id
818
description: "Unique identifier for the component."
919
data_tests:
1020
- not_null
1121
- unique
22+
constraints:
23+
- type: not_null
24+
- type: unique
25+
- type: primary_key
1226
- name: manifest_name
1327
description: "Name of the component's manifest file. The manifest defines the component's configuration and metadata."
1428
data_tests:
@@ -25,6 +39,10 @@ models:
2539
description: "URL for accessing the component."
2640
- name: ps_id
2741
description: "Identifier of the associated participatory space."
42+
constraints:
43+
- type: not_null
44+
- type: foreign_key
45+
expression: "{{ target.schema }}.participatory_spaces (id)"
2846
- name: ps_published_at
2947
description: "Publication date of the participatory space."
3048
- name: ps_title
@@ -43,6 +61,11 @@ models:
4361
description: "Identifier of the Decidim organization."
4462
data_tests:
4563
- not_null
64+
constraints:
65+
- type: not_null
66+
- type: foreign_key
67+
expression: "{{ target.schema }}.decidim_organizations (id)"
68+
4669
- name: organization_host
4770
description: "Host of the Decidim organization."
4871

Lines changed: 49 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,54 @@
11
version: 2
22

33
models:
4-
- name: forms_answers
5-
description: "Table gathering all types of answers (long, short, optional, sorting and matrix). "
4+
- name: form_answers
5+
description: "Table gathering all types of answers (short, long, optional, sorting, matrix, and file answers) submitted to forms."
6+
# Model-level constraints
7+
constraints:
8+
- type: primary_key
9+
columns: [decidim_user_id]
10+
- type: foreign_key
11+
columns: [decidim_questionnaire_id]
12+
expression: "{{ target.schema }}.forms (id)"
13+
- type: foreign_key
14+
columns: [decidim_component_id]
15+
expression: "{{ target.schema }}.components (id)"
616
columns:
17+
- name: decidim_user_id
18+
description: "The ID of the user who submitted the answer"
19+
constraints:
20+
- type: not_null
21+
- type: unique
22+
- type: primary_key
23+
- name: session_token
24+
description: "Session token for tracking the user's session"
25+
- name: position
26+
description: "The position of the answer in the form"
27+
- name: decidim_questionnaire_id
28+
description: "The ID of the form/questionnaire to which this answer belongs"
29+
constraints:
30+
- type: not_null
31+
- type: foreign_key
32+
expression: "{{ target.schema }}.forms (id)"
33+
- name: ip_hash
34+
description: "IP hash for tracking the user's IP address"
35+
- name: question_type
36+
description: "The type of the question (e.g., short, long, matrix)"
37+
- name: question_title
38+
description: "The title of the question being answered"
39+
- name: answer
40+
description: "The answer given by the user"
41+
- name: sub_matrix_question
42+
description: "The question for a sub-matrix (if applicable)"
43+
- name: custom_body
44+
description: "Custom text associated with the answer (if applicable)"
45+
- name: sorting_position
46+
description: "The sorting position of the answer (sorting-type questions only)"
47+
- name: form_title
48+
description: "The title of the form/questionnaire"
749
- name: sorting_points
8-
description: "In order to evaluate the weight of the sorting answers, points are given to the answer according to its sorting position."
50+
description: "Calculated sorting points based on the sorting position"
51+
- name: created_at
52+
description: "Timestamp of when the answer was created"
53+
- name: author_status
54+
description: "Status of the author "

projects/demo/models/marts/meetings/schema.yml

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,87 @@ models:
22
- name: meetings
33
schema: "{{ env_var('TARGET_SCHEMA') }}"
44
description: "Every meeting published on the platform"
5+
# model-level constraints
6+
constraints:
7+
- type: primary_key
8+
columns: [id]
9+
- type: foreign_key
10+
columns: [decidim_component_id]
11+
expression: "{{ target.schema }}.components (id)"
12+
- type: foreign_key
13+
columns: [decidim_scope_id]
14+
expression: "{{ target.schema }}.decidim_scopes (id)"
15+
- type: foreign_key
16+
columns: [decidim_author_id]
17+
expression: "{{ target.schema }}.decidim_users (id)"
518
columns:
619
- name: id
720
description: "The unique identifier for a meeting"
21+
data_tests:
22+
- not_null
23+
- unique
24+
constraints:
25+
- type: not_null
26+
- type: unique
27+
- type: primary_key
28+
- name: title
29+
description: "The title of the meeting"
30+
data_tests:
31+
- not_null
32+
constraints:
33+
- type: not_null
34+
- name: description
35+
description: "A brief description of the meeting"
36+
- name: address
37+
description: "The physical or virtual address of the meeting"
38+
- name: attendees_count
39+
description: "The total number of attendees at the meeting"
40+
- name: created_at
41+
description: "The timestamp when the meeting was created"
42+
data_tests:
43+
- not_null
44+
constraints:
45+
- type: not_null
46+
- name: decidim_scope_id
47+
description: "The identifier of the scope this meeting belongs to"
48+
constraints:
49+
- type: not_null
50+
- type: foreign_key
51+
expression: "{{ target.schema }}.decidim_scopes (id)"
52+
- name: decidim_component_id
53+
description: "The identifier of the component associated with the meeting"
54+
constraints:
55+
- type: not_null
56+
- type: foreign_key
57+
expression: "{{ target.schema }}.components (id)"
58+
- name: start_time
59+
description: "The start time of the meeting"
60+
- name: end_time
61+
description: "The end time of the meeting"
62+
- name: registration_url
63+
description: "URL for registration for the meeting"
64+
- name: type_of_meeting
65+
description: "The type/category of the meeting"
66+
- name: translated_type_of_meeting
67+
description: "The translated type of the meeting"
68+
- name: private_meeting
69+
description: "Indicates if the meeting is private"
70+
- name: decidim_author_id
71+
description: "The ID of the author or organizer of the meeting"
72+
constraints:
73+
- type: not_null
74+
- type: foreign_key
75+
expression: "{{ target.schema }}.decidim_users (id)"
76+
- name: resource_type
77+
description: "The type of resource related to the meeting"
78+
- name: meeting_url
79+
description: "The URL to access the meeting"
80+
- name: categories
81+
description: "Categories associated with the meeting"
82+
- name: sub_categories
83+
description: "Subcategories associated with the meeting"
84+
- name: categorizations
85+
description: "The full categorization data (raw) for the meeting"
886
unit_tests:
987
- name: test_url_concatenation
1088
description: "Check URL concatenation logic"

projects/demo/models/marts/proposals/schema.yml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,32 @@ version: 2
44
models:
55
- name: proposals
66
description: "Every proposal that has been created on your Decidim instance, including accepted, pending, rejected and withdrawn proposals. Does not include hidden (moderation) and unpublished proposals (i.e. linked to either an unpublished participatory process or an unpublished component)."
7+
# Model-level constraints
8+
constraints:
9+
- type: foreign_key
10+
columns: [decidim_participatory_space_id]
11+
expression: "{{ target.schema }}.participatory_spaces (id)" # Foreign key reference to participatory_spaces table
12+
- type: foreign_key
13+
columns: [decidim_component_id]
14+
expression: "{{ target.schema }}.components (id)" # Foreign key reference to components table
15+
- type: foreign_key
16+
columns: [first_author_id]
17+
expression: "{{ target.schema }}.users (id)" # Foreign key reference to users table
718
columns:
819
- name: id
920
description: "Unique identifier for the proposal"
1021
tests:
1122
- unique
1223
- not_null
24+
constraints:
25+
- type: unique
26+
- type: not_null
1327
- name: decidim_participatory_space_id
1428
description: "Identifier for the participatory space where the proposal was created"
29+
constraints:
30+
- type: not_null
31+
- type: foreign_key
32+
expression: "{{ target.schema }}.participatory_spaces (id)" # Foreign key reference to participatory_spaces table
1533
- name: decidim_participatory_space_slug
1634
description: "Slug for the participatory space where the proposal was created"
1735
- name: decidim_scope_name
@@ -26,6 +44,10 @@ models:
2644
description: "URL link to the proposal on the Decidim platform"
2745
- name: decidim_component_id
2846
description: "Identifier for the component within which the proposal was created"
47+
constraints:
48+
- type: not_null
49+
- type: foreign_key
50+
expression: "{{ target.schema }}.components (id)" # Foreign key reference to components table
2951
- name: created_at
3052
description: "Timestamp when the proposal was created"
3153
- name: published_at
@@ -38,6 +60,10 @@ models:
3860
description: "Array of IDs of the authors of the proposal"
3961
- name: first_author_id
4062
description: "ID of the first author of the proposal"
63+
constraints:
64+
- type: not_null
65+
- type: foreign_key
66+
expression: "{{ target.schema }}.users (id)" # Foreign key reference to users table
4167
- name: address
4268
description: "Address related to the proposal, if any"
4369
- name: categories

0 commit comments

Comments
 (0)