1
1
/*
2
2
3
- WallStreet database should store information about brokers, sales groups and its relations .
3
+ User profile database stores information about users and their work profiles .
4
4
5
- Each broker must have a unique username. First and last names are also mandatory .
5
+ Each user has one and only one work profile .
6
6
7
- A sales group is a special group that has its own restrictions. Sale groups are used to organize the work of brokers.
8
- Each group mush have a unique name, transaction type (string), and max transaction amount (a number). All field are
9
- mandatory.
10
-
11
- A sales group can consists of more than one broker, while each broker can be associated with more than one sale group.
7
+ Each user has stored first and last names, email and birthday which are mandatory. Email is a unique value.
8
+ A profile for each user is optional, and consists of optional information: city, job_position, company and education.
9
+ All these fields are regular strings without restrictions.
12
10
13
11
TECH NOTES AND NAMING CONVENTION
14
12
- All tables, columns and constraints are named using "snake case" naming convention
15
- - All table names must be singular (e.g. "user", not "users")
16
- - All tables (except link tables) should have an id of type BIGINT, which is a primary key
17
- - Link tables should have composite primary key, that consists of two other foreign key columns
13
+ - All table names must be plural (e.g. "companies", not "company")
14
+ - All tables (except link tables) should have a single-value identifier of type BIGINT, which is a primary key
18
15
- All primary key, foreign key, and unique constraint should be named according to the naming convention.
19
- - All link tables should have a composite key that consists of two foreign key columns
16
+ - All "1 - optional 1" relations should be handled using the same primary key value for both tables. E.g. child table
17
+ should have a column that stores primary key from a parent table, which is a foreign key and primary key at the same time
20
18
21
- - All primary keys should be named according to the following rule "PK_table_name "
22
- - All foreign keys should be named according to the following rule "FK_table_name_reference_table_name "
23
- - All alternative keys (unique) should be named according to the following rule "UQ_table_name_column_name "
19
+ - All primary keys should be named according to the following rule "table_name_PK "
20
+ - All foreign keys should be named according to the following rule "table_name_reference_table_name_FK "
21
+ - All alternative keys (unique) should be named according to the following rule "table_name_column_name_AK "
24
22
25
23
*/
26
24
27
- CREATE TABLE IF NOT EXISTS broker (
28
- id BIGINT ,
29
- username VARCHAR (255 ) NOT NULL ,
30
- first_name VARCHAR (255 ) NOT NULL ,
31
- last_name VARCHAR (255 ) NOT NULL ,
32
- CONSTRAINT PK_broker PRIMARY KEY (id),
33
- CONSTRAINT UQ_broker_username UNIQUE (username)
34
- );
35
-
36
-
37
- CREATE TABLE IF NOT EXISTS sales_group (
38
- id BIGINT ,
39
- name VARCHAR (255 ) NOT NULL ,
40
- transaction_type VARCHAR (255 ) NOT NULL ,
41
- max_transaction_amount INT NOT NULL ,
42
- CONSTRAINT PK_sales_group PRIMARY KEY (id),
43
- CONSTRAINT UQ_sales_group_name UNIQUE (name)
44
- );
45
-
46
-
47
- CREATE TABLE IF NOT EXISTS broker_sales_group (
48
- broker_id BIGINT NOT NULL ,
49
- sales_group_id BIGINT NOT NULL ,
50
- CONSTRAINT PK_broker_sales_group PRIMARY KEY (broker_id, sales_group_id),
51
- CONSTRAINT FK_broker_sales_group_broker FOREIGN KEY (broker_id) REFERENCES broker,
52
- CONSTRAINT FK_broker_sales_group_sales_group FOREIGN KEY (sales_group_id) REFERENCES sales_group
53
- );
54
-
25
+ -- TODO: implement the SQL according to the description
0 commit comments