Skip to content

Commit

Permalink
Adding the improved SQL logic
Browse files Browse the repository at this point in the history
  • Loading branch information
samisa-abeysinghe committed Oct 4, 2022
1 parent 16c8f69 commit aa46cde
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 22 deletions.
2 changes: 1 addition & 1 deletion api/person_data.bal
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ public distinct service class PersonData {
private Person person;

isolated function init(string? name = null, int? person_id = 0, Person? person = null) returns error? {
if(person != null) { // if roganization is provided, then use that and do not load from DB
if(person != null) { // if person is provided, then use that and do not load from DB
self.person = person.cloneReadOnly();
return;
}
Expand Down
16 changes: 11 additions & 5 deletions db/schema/2-avinya_types.sql
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,26 @@ USE avinya_db;
CREATE TABLE IF NOT EXISTS avinya_type (
id INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
active BOOLEAN NOT NULL,
global_type ENUM("Employee", "Customer", "Volunteer", "Applicant", "Team") NOT NULL,
global_type ENUM("Employee", "Customer", "Volunteer", "Applicant", "Organization", "Team") NOT NULL,
name VARCHAR(255),
foundation_type ENUM(
"Advisors",
"Executive",
"Advisor",
"Educator",
"Technology",
"Operations",
"HR",
"Parent",
"Student"
),
focus ENUM(
"Bootcamp",
"Healthcare",
"Information Technology"
"Foundation",
"Vocational-IT",
"Vocational-Healthcare",
"Vocational-Hospitality",
"Operations",
"HR",
"Technology"
),
level INT
);
8 changes: 4 additions & 4 deletions db/schema/3-organization_and_address_tables.sql
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ USE avinya_db;

-- Address
CREATE TABLE IF NOT EXISTS address (
id INT NOT NULL PRIMARY KEY,
id INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
street_address VARCHAR(255) NOT NULL,
phone INT,
city_id INT NOT NULL,
Expand All @@ -11,13 +11,13 @@ CREATE TABLE IF NOT EXISTS address (

-- Organization
CREATE TABLE IF NOT EXISTS organization (
id INT NOT NULL PRIMARY KEY,
id INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
name_en VARCHAR(255) NOT NULL,
name_ta VARCHAR(255),
name_si VARCHAR(255),
phone INT,
address_id INT NOT NULL,
avinya_type INT NOT NULL,
address_id INT,
avinya_type INT,
FOREIGN KEY (address_id) REFERENCES address(id),
FOREIGN KEY (avinya_type) REFERENCES avinya_type(id)
);
Expand Down
36 changes: 24 additions & 12 deletions db/schema/4-person.sql
Original file line number Diff line number Diff line change
@@ -1,13 +1,25 @@
-- USE avinya_db;
USE avinya_db;

-- -- Person
-- CREATE TABLE IF NOT EXISTS person (
-- asgardeo_id VARCHAR(255) NOT NULL PRIMARY KEY,
-- permanent_address INT NOT NULL,
-- mailing_address INT NOT NULL,
-- phone INT,
-- organization INT,
-- FOREIGN KEY (permanent_address) REFERENCES address(id),
-- FOREIGN KEY (mailing_address) REFERENCES address(id),
-- FOREIGN KEY (organization) REFERENCES organization(id),
-- );
-- Person
CREATE TABLE IF NOT EXISTS person (
id INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
preferred_name VARCHAR(512) NOT NULL,
full_name VARCHAR(1024) DEFAULT NULL,
date_of_birth DATE DEFAULT NULL,
sex ENUM ("Male", "Female", "Not Specified") DEFAULT "Not Specified",
asgardeo_id VARCHAR(255) DEFAULT NULL,
permanent_address_id INT DEFAULT NULL,
mailing_address_id INT DEFAULT NULL,
phone INT DEFAULT 0,
organization_id INT DEFAULT NULL,
avinya_type_id INT DEFAULT NULL,
notes VARCHAR(1024) DEFAULT NULL,
nic_no VARCHAR(30) DEFAULT NULL,
passport_no VARCHAR(30) DEFAULT NULL,
id_no VARCHAR(30) DEFAULT NULL,
email VARCHAR(254) DEFAULT NULL,
FOREIGN KEY (permanent_address_id) REFERENCES address(id),
FOREIGN KEY (mailing_address_id) REFERENCES address(id),
FOREIGN KEY (organization_id) REFERENCES organization(id),
FOREIGN KEY (avinya_type_id) REFERENCES avinya_type(id)
);

0 comments on commit aa46cde

Please sign in to comment.