Database Tables - CSSWENGS18Group9/DB-Poultry GitHub Wiki
Flock
The Flock
table has three columns:
Flock_ID
(PK), it is set as aSERIAL
type to allow for auto-incrementing the PK.Starting_Count
, it is anINTEGER
with the constraint that it is not zero, negative, or null. This defines the total number of chickens in the Flock at the start. This value is not updated and does not change for the entire lifetime of the column.Starting_Date
, is a uniqueDATE
that is also not null. This defines the date when theFlock
was received by DB Poultry. TheStarting_Date
is unique since there is only oneFlock
in the farm at a time.
Below is the database definition of the table:
CREATE TABLE
Flock (
Flock_ID SERIAL PRIMARY KEY,
Starting_Count INTEGER CHECK (Starting_Count > 0) NOT NULL,
Starting_Date DATE UNIQUE NOT NULL
);
Flock_Details
The Flock_Details
table has five columns:
Flock_Details_ID
(PK; usually abbreviated asfd_ID
), it is set as aSERIAL
type to allow for auto-incrementing the PK.Flock_ID
, is an integer FK pointing to theFlock
thisFlock_Details
table belongs to.FD_Date
, is a uniqueDATE
that is also not null. This defines the date when theFlock_Details
was recorded. This date is unique as there can only be oneFlock_Details
per day; that is, they can only record theFlock_Details
once a day.Depleted_Count
, is anINTEGER
with the constraint that it is non-negative. This defines how many chickens died during that day. This value is not updated and does not change for the entire lifetime of the column.
Special specifications regarding the insertion of
Flock_Details
is discussed in detail in Maintaining Integrity ->Flock_Details
.
Below is the database definition of the table:
CREATE TABLE
Flock_Details (
Flock_Details_ID SERIAL PRIMARY KEY,
Flock_ID INTEGER NOT NULL,
FD_Date DATE UNIQUE NOT NULL,
Depleted_Count INTEGER CHECK (Depleted_Count >= 0),
FOREIGN KEY (Flock_ID) REFERENCES Flock (Flock_ID) ON DELETE CASCADE
);
Supply_Record
The Supply_Record
has six columns:
Supply_ID
(PK; usually abbreviated assr_ID
), it is set asSERIAL
to allow for auto-incrementing the PK.Supply_Type_ID
, it is an integer FK pointing to aSupply_Type
column, this denotes what type of supply thisSupply_Record
is tracking.Added
, is a numerical value that takes any value in the range[0, 999999999]
with four points of precision. Denotes how much of that supply was added (given by partner businesses, bought, among others).Consumed
, is a numerical value that takes any value in the range[0, 999999999]
with four points of precision. Denotes how much of that supply were consumed or used.Retrieved
is a Boolean value that denotes if the remaining (unused) supplies were given back (retrieved by) the partner business.
CREATE TABLE
Supply_Record (
Supply_ID SERIAL PRIMARY KEY,
Supply_Type_ID INT NOT NULL,
SR_Date DATE,
Added NUMERIC(9, 4),
Consumed NUMERIC(9, 4),
Retrieved BOOLEAN,
FOREIGN KEY (Supply_Type_ID) REFERENCES Supply_Type (Supply_Type_ID) ON DELETE CASCADE
);
Supply_Type
The Supply_Type
allows for dynamically typing a Supply_Record
; it allows the user to add a new Supply_Type
when needed. The Supply_Type
has three columns:
Sypply_Type_ID
(PK; usually abbreviated asst_ID
), it is set as aSERIAL
to allow for auto-incrementing the PK.Supply_Name
is aTEXT
field that denotes the type of supply (e.g., Feed, Medicine, among others). This value is not updated and does not change for the entire lifetime of the column. EachSupply_Name
is unique; that is, for everySupply_Type
in the database, that is only for a single supply. For instance, if we have aSupply_Type
with the name "Rice" and another with the name "Chicken Feed" then for every data insert that is a chicken feed, every data insert of chicken feed will be using theSupply_Type
with the name "Chicken Feed"Unit
is aVARCHAR(12)
field that denotes the unit of measurement used (S.I. units cm or ml; discrete units like sacks or bottles). This value is not updated and does not change for the entire lifetime of the column.
CREATE TABLE
Supply_Type (
Supply_Type_ID SERIAL PRIMARY KEY,
Supply_Name TEXT UNIQUE NOT NULL CHECK (Supply_Name <> ''),
Unit VARCHAR(12) NOT NULL CHECK (Unit <> '')
);