| | 1 | |
| | 2 | {{{ |
| | 3 | CREATE TABLE customer ( |
| | 4 | CustomerID integer PRIMARY KEY, |
| | 5 | CustomerName varchar(100), |
| | 6 | CustomerSurName varchar(100), |
| | 7 | Email varchar(100), |
| | 8 | Address varchar(255), |
| | 9 | CustomerContact varchar(20), |
| | 10 | Password varchar(255) NOT NULL |
| | 11 | ); |
| | 12 | |
| | 13 | CREATE TABLE employee ( |
| | 14 | EmployeeID integer PRIMARY KEY, |
| | 15 | EmployeeName varchar(100), |
| | 16 | EmployeeSurName varchar(100), |
| | 17 | Position varchar(100), |
| | 18 | Department varchar(100), |
| | 19 | Email varchar(100), |
| | 20 | Password varchar(100) |
| | 21 | ); |
| | 22 | |
| | 23 | CREATE TABLE product ( |
| | 24 | ProductID integer PRIMARY KEY, |
| | 25 | Model varchar(100), |
| | 26 | Price numeric(10,2), |
| | 27 | LicensePlate varchar(50), |
| | 28 | Status varchar(15) NOT NULL, |
| | 29 | CONSTRAINT product_status_check CHECK (Status IN ('available','sold','rented','maintenance')) |
| | 30 | ); |
| | 31 | |
| | 32 | -- Потоа откако ќе се креираат табелите горе, продолжи со оние што реферираат од нив: |
| | 33 | CREATE TABLE procurement ( |
| | 34 | TransactionID integer PRIMARY KEY, |
| | 35 | EmployeeID integer, |
| | 36 | CustomerID integer, |
| | 37 | ProductID integer, |
| | 38 | ProcurementDate date, |
| | 39 | Quantity integer, |
| | 40 | Status varchar(10) DEFAULT 'Pending', |
| | 41 | Notified boolean DEFAULT FALSE, |
| | 42 | GroupID varchar(255), |
| | 43 | CONSTRAINT procurement_employee_fk FOREIGN KEY (EmployeeID) REFERENCES employee(EmployeeID), |
| | 44 | CONSTRAINT procurement_customer_fk FOREIGN KEY (CustomerID) REFERENCES customer(CustomerID), |
| | 45 | CONSTRAINT procurement_product_fk FOREIGN KEY (ProductID) REFERENCES product(ProductID) |
| | 46 | ); |
| | 47 | |
| | 48 | CREATE TABLE maintenance ( |
| | 49 | MainID integer PRIMARY KEY, |
| | 50 | EmployeeID integer, |
| | 51 | ProductID integer, |
| | 52 | MainDate date, |
| | 53 | Description text, |
| | 54 | Cost numeric(10,2), |
| | 55 | Status varchar(10) DEFAULT 'Pending', |
| | 56 | StartTime timestamp DEFAULT CURRENT_TIMESTAMP, |
| | 57 | EndTime timestamp, |
| | 58 | CONSTRAINT maintenance_status_check CHECK (Status IN ('Pending','Completed')), |
| | 59 | CONSTRAINT maintenance_employee_fk FOREIGN KEY (EmployeeID) REFERENCES employee(EmployeeID), |
| | 60 | CONSTRAINT maintenance_product_fk FOREIGN KEY (ProductID) REFERENCES product(ProductID) |
| | 61 | ); |
| | 62 | |
| | 63 | CREATE TABLE trailer ( |
| | 64 | ProductID integer PRIMARY KEY, |
| | 65 | Capacity numeric(10,2), |
| | 66 | CONSTRAINT trailer_product_fk FOREIGN KEY (ProductID) REFERENCES product(ProductID) |
| | 67 | ); |
| | 68 | |
| | 69 | CREATE TABLE truck ( |
| | 70 | ProductID integer PRIMARY KEY, |
| | 71 | HP integer, |
| | 72 | CONSTRAINT truck_product_fk FOREIGN KEY (ProductID) REFERENCES product(ProductID) |
| | 73 | ); |
| | 74 | |
| | 75 | CREATE TABLE views ( |
| | 76 | CustomerID integer NOT NULL, |
| | 77 | ProductID integer NOT NULL, |
| | 78 | PRIMARY KEY (CustomerID, ProductID), |
| | 79 | CONSTRAINT views_customer_fk FOREIGN KEY (CustomerID) REFERENCES customer(CustomerID), |
| | 80 | CONSTRAINT views_product_fk FOREIGN KEY (ProductID) REFERENCES product(ProductID) |
| | 81 | ); |
| | 82 | |
| | 83 | CREATE TABLE wallet ( |
| | 84 | WalletID serial PRIMARY KEY, |
| | 85 | CustomerID integer NOT NULL, |
| | 86 | Balance numeric(10,2) NOT NULL DEFAULT 0.00, |
| | 87 | CardNumber varchar(16), |
| | 88 | ExpiryDate date, |
| | 89 | CVV varchar(4), |
| | 90 | CardHolderName varchar(100), |
| | 91 | CONSTRAINT wallet_customer_fk FOREIGN KEY (CustomerID) REFERENCES customer(CustomerID) |
| | 92 | ); |
| | 93 | |
| | 94 | CREATE TABLE customerfeedback ( |
| | 95 | FeedbackID integer PRIMARY KEY, |
| | 96 | CustomerID integer, |
| | 97 | ProductID integer, |
| | 98 | Rating integer CHECK (Rating BETWEEN 1 AND 5), |
| | 99 | Comment text, |
| | 100 | FeedbackDate date, |
| | 101 | TransactionID integer, |
| | 102 | CONSTRAINT feedback_customer_fk FOREIGN KEY (CustomerID) REFERENCES customer(CustomerID), |
| | 103 | CONSTRAINT feedback_product_fk FOREIGN KEY (ProductID) REFERENCES product(ProductID), |
| | 104 | CONSTRAINT feedback_transaction_fk FOREIGN KEY (TransactionID) REFERENCES procurement(TransactionID) |
| | 105 | ); |
| | 106 | |
| | 107 | CREATE TABLE procurement_request ( |
| | 108 | RequestID serial PRIMARY KEY, |
| | 109 | CustomerID integer NOT NULL, |
| | 110 | ProductID integer NOT NULL, |
| | 111 | Quantity integer DEFAULT 1, |
| | 112 | RequestedAt timestamp DEFAULT CURRENT_TIMESTAMP, |
| | 113 | Status varchar(10) DEFAULT 'Pending', |
| | 114 | PaymentMethod varchar(20), |
| | 115 | PaymentStatus varchar(10) DEFAULT 'Reserved', |
| | 116 | MonthlyPay numeric(10,2), |
| | 117 | TotalPrice numeric(10,2), |
| | 118 | Duration integer, |
| | 119 | CardID integer, |
| | 120 | TransactionType varchar(10) DEFAULT 'Buy', |
| | 121 | GroupID varchar(36), |
| | 122 | CONSTRAINT procurement_request_customer_fk FOREIGN KEY (CustomerID) REFERENCES customer(CustomerID), |
| | 123 | CONSTRAINT procurement_request_product_fk FOREIGN KEY (ProductID) REFERENCES product(ProductID), |
| | 124 | CONSTRAINT procurement_request_status_check CHECK (Status IN ('Pending','Approved','Rejected')), |
| | 125 | CONSTRAINT procurement_request_paymentstatus_check CHECK (PaymentStatus IN ('Reserved','Charged','Refunded')), |
| | 126 | CONSTRAINT procurement_request_transactiontype_check CHECK (TransactionType IN ('Buy','Rent')) |
| | 127 | ); |
| | 128 | |
| | 129 | CREATE TABLE t_type ( |
| | 130 | TransactionID integer PRIMARY KEY, |
| | 131 | Type varchar(10) NOT NULL, |
| | 132 | Duration integer, |
| | 133 | MonthlyPay numeric(10,2), |
| | 134 | TotalPrice numeric(10,2), |
| | 135 | CONSTRAINT t_type_type_check CHECK (Type IN ('Rent','Buy')), |
| | 136 | CONSTRAINT t_type_transaction_fk FOREIGN KEY (TransactionID) REFERENCES procurement(TransactionID) |
| | 137 | ); |
| | 138 | |
| | 139 | }}} |