Database - COS-301/graduates GitHub Wiki

Design

1. User

1.2 User Scouting

1.3 User Roles and Permissions

1.4 User Profile

1.4 UserTag Table

1.4.1 Description

Stores the tags of a particular company (Web Development company, Technical Support company, Networking Company, IT Security company,Cloud Services, Other). This allows the user to filter based on the tags of a Company on the Company Explore Page.

1.4.2 Description of Fields

Field Name Description Datatype
user_id Foreign key from the user table, used to identify the company that obtains the tag CUID
tag Type of company - Web Development company, Technical Support company, Networking Company, IT Security company,Cloud Services and Other String?

2. Short

2.1 short Table

2.1.1 Description

Stores the data of all student shorts

2.1.2 Description of Fields

Field Name Description Datatype
short_id Primary key, used to uniquely identify the short. CUID
user_id Foreign key from the user table, used to identify the student that posted the short CUID
description Text that is used as to describe the short String?
link Contains the path to the video uploaded on the server String?
thumbnail Contains the path to the thumbnail uploaded on the server String?
date_posted Stores the date and time of the short creation DateTime
archived Indicates whether the short has been archived. Only non-archived shorts are displayed Boolean

2.2 short_report Table

2.2.1 Description

Stores the data of reported shorts

2.2.2 Description of Fields

Field Name Description Datatype
short_id Foreign key, used to uniquely identify the short. Forms the Primary key with the user_id CUID
user_id Foreign key from the user table, used to identify the student that reported the short. Forms the Primary key with the short_id CUID
reason Contains the reason for the report String?

2.3 short_tag Table

2.3.1 Description

Stores the data for the tags linked to the short

2.3.2 Description of Fields

Field Name Description Datatype
short_id Foreign key, used to uniquely identify the short. Forms the Primary key with the tag CUID
tag Stores the tag linked to the short. Forms the Primary key with the short_id String

3. Notifications

3.1 notifications Table

3.1.1 Description

Stores the data of all user notification types.

3.1.2 Description of Fields

Field Name Description Datatype
id Primary key, used to uniquely identify notification. CUID
user_id_to Foreign key from the user table, used to identify the source(actor) of the notification. (Can be nullable; if null, notification is from the system) CUID
user_id_from Foreign Key from the user table used to identify the destination(notifier) of the notification. CUID
data A JSON Object of varying formats with the relevant information: notification_type, etc. JSON
date Stores the date and time of the notification creation. DateTime
seen Indicates whether the notification has been marked as seen, only unseen notifications will be displayed in the notifications tab. Boolean

4. Blog

4.1 blog Table

4.1.1 Description

Stores the data of blog posts.

4.1.2 Description of Fields

Field Name Description Datatype
id Primary key. Unique ID to identify the blog post String (cuid)
user_id Foreign key from the user table. Unique ID to identify the author of the post String
title The post title to be displayed when viewing String
content The post data String?
date Stores the date and time at which the blog post was created DateTime
archived Indicates whether the post has been archived. Only non-archived blog posts are displayed Boolean

4.2 blog_comment Table

4.2.1 Description

Stores the data of comments made on blog posts.

4.2.2 Description of Fields

Field Name Description Datatype
comment_id Primary Key. Unique ID to identify the comment String (cuid)
blog_id Foreign key from blog table. Used to identify which blog the comment is posted on String
user_id Foreign key from the user table. Used to identify which user posted the comment String
content The comment data String
date Stores the date and time at which the comment was created DateTime

4.3 blog_media Table

4.3.1 Description

Stores information regarding the media used in blog posts.

4.3.2 Description of Fields

Field Name Description Datatype
blog_id Partial Key. Foreign key from blog table. Used to identify which blog the media is used on String
media Partial Key. Identifies the filename of the media String

Standards

Document revision: 1.1

Last modified: 2022/03/12

1. General Standards:

1.1 Naming Convention

Snake case (stylized as snake_case) refers to the style of writing in which each space is replaced by an underscore (_) character and the first letter of each word written in lowercase.

snake_case is used for all names unless specifically stated otherwise in this document for a given naming condition/style.

Additionally abbreviations which are all capital must be considered as lower case words when applying the snake_case rules.

1.1.1 Examples

Original text Snake case
Red Riding Hood red_riding_hood
An HTML file an_html_file
DBM XML dbm_xml

1.1.2 Exceptions

The general conventions for name construction must be followed except where the standard defines a different naming convention.

Constants are written with all Uppercase letters but are still separated by an underscore.

1.2 Spelling

Spelling mistakes are not acceptable; when in doubt, check a dictionary, use a spell-checker, or ask someone knowledgeable.

Be consistent throughout a document. Do not mix British and US English within a single document. Always set your spellchecker accordingly.

1.3 Name Choices

Names of variables, functions, types, files, and directories must be meaningful and descriptive.
Abbreviations may be used if it is commonly recognized. Longer names are preferred above short unclear names.

1.4 File naming convention

Name source files following the convention defined in the table below.

File type Name template Example
sql [name].sql user_profile.sql

All sql files must be contained in a single directory unless stated otherwise.

There may never be two files with the same name, even if they are in separate directories.

File names must start with the most general use and end with the most specific use.

1.4.1 Example

truck_payload_volume
user_profile_information

1.5 Comments

1.5.1 Doxygen comments

1.5.1.1 Doxygen Block comments

Doxygen comment blocks must start with /*! and end with */. Every line in-between must start with a left-aligned *. Doxygen commands and text must be indented with one tab space. Tab aligns the arguments that follow the Doxygen commands. You may also start a new paragraph (blank line) starting with * to add a detailed description, alternatively use the @details command. Also, leave blank lines for paragraph breaks. The first line must be a brief description starting with @brief.

1.5.1.2 Doxygen Single line comments

Doxygen single-line comments must start with a //! followed by a space.

1.5.1.3 Doxygen inline comments

Doxygen single-line comments must start with a //! followed by a space.

1.5.2 File comments

Start each file with the path from the project's directory to the file using forward slashes. On the next line supply the copyright notice.

1.5.2.1 Example

// Path/To/File.sql

// Copyrighted (C) 2022 University Of Pretoria

1.5.2 Todo comments

// TODO: [name surname] description

1.5.3 FIXME comments

// FIXME: [name surname] description

1.6 Structure

Code or comments are not allowed to go off-screen for a standard 1920x1080p monitor unless otherwise stated or it breaks convention.

2. Schema Standards:

2.1 Schema naming convention

Schema names follow the general naming convention and must be descriptive and meaningful.

All schemas should be contained in a single directory unless stated otherwise by another more recognized convention.

2.2 Record ID’s

CUID’s will be used for identifying records.

Collision-resistant ids optimized for horizontal scaling and binary search lookup performance.

cuid() returns a short random string with some collision-busting measures. Safe to use as HTML element ID's, and unique server-side record lookups.

3. Sql and Postgresql Standards:

3.1 Naming conventions

3.1.1 Variable and Parameter names

All parameters must be aligned if they are on separate lines.

Function and variable names follow the general naming convention and must be descriptive and meaningful.

3.1.2 Function names

Function names follow the general naming convention and must be descriptive and meaningful.
There must be no space between the function name and the opening parenthesis.
Leading and trailing spaces inside the parentheses are not allowed.
The return type must always be on the same line as the function name.

3.1.2.1 Global scope functions

Global functions should start with an uppercase letter and still follow snake case conventions for the rest of the name.

3.1.2.2 Local scope functions

Local functions should start with a lowercase letter and still follow snake case conventions for the rest of the name.

3.2 Formatting conventions

3.2.1 Curly braces

Curly braces must appear on a line by themselves and line up with each other and the control structure keyword to which they belong.

3.2.2 Tabs

A tab spacing of 4 must be used for indentation. Tabs must use the tab character and not spaces. Text editors must be set up appropriately so that tabs are handled correctly as most editors allow both options and the text editor defaults may not use the tab character.

3.2.3 Spaces

When formatting expressions that contain operators (e.g. +, -, <, =, etc), there must be spaces between all binary operators and their arguments and no space between a unary operator and its argument.

3.2.3.1 Examples
x = 0;

4 * ((x + y) + (z - 5));

3.3 Structure

3.3.1 Schema definition

All related data in a relation should be in columns separated by tab characters.

4. Sql Standards

4.1 Formatting conventions

4.1.1 Keywords

All keywords should be uppercase and at the start of a new line.

4.1.1.1 Exceptions

The keyword ‘AS’.

4.2 Aliases

All relation aliases should be descriptive and prefixed with the relation they originate from.

5. Postgresql Standards

5.1 Formatting conventions

⚠️ **GitHub.com Fallback** ⚠️