| 1 | create table AppUser
|
|---|
| 2 | (
|
|---|
| 3 | id serial primary key,
|
|---|
| 4 | first_name varchar(20) not null check ( char_length(first_name) >= 1 ) default 'UNKNOWN',
|
|---|
| 5 | last_name varchar(20) not null check ( char_length(last_name) >= 1 ) default 'USER',
|
|---|
| 6 | email varchar(254) check ( email is null or email ~* '^[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,}$' ),
|
|---|
| 7 | username varchar(30) not null unique,
|
|---|
| 8 | password_hash text not null check (char_length(password_hash) >= 8),
|
|---|
| 9 | date_of_birth date not null check ( date_of_birth >= date '1900-01-01' and date_of_birth <= current_date),
|
|---|
| 10 | phone_number varchar(15) not null check (phone_number ~ '^\+?[0-9]{7,15}$')
|
|---|
| 11 | );
|
|---|
| 12 |
|
|---|
| 13 | create table Dispatcher
|
|---|
| 14 | (
|
|---|
| 15 | user_id int4 primary key references AppUser (id) on update cascade on delete cascade
|
|---|
| 16 | );
|
|---|
| 17 |
|
|---|
| 18 | create table Admin
|
|---|
| 19 | (
|
|---|
| 20 | user_id int4 primary key references AppUser (id) on update cascade on delete cascade
|
|---|
| 21 | );
|
|---|
| 22 |
|
|---|
| 23 | create table DriverLicense
|
|---|
| 24 | (
|
|---|
| 25 | id serial primary key,
|
|---|
| 26 | issue_date date not null check (issue_date >= DATE '1900-01-01' and issue_date <= CURRENT_DATE),
|
|---|
| 27 | expire_date date,
|
|---|
| 28 | license_id varchar(20) not null,
|
|---|
| 29 | check ( expire_date is null or expire_date > issue_date )
|
|---|
| 30 | );
|
|---|
| 31 |
|
|---|
| 32 | create table DriverLicenseCategory
|
|---|
| 33 | (
|
|---|
| 34 | id serial primary key,
|
|---|
| 35 | category_name varchar(5) not null unique
|
|---|
| 36 | );
|
|---|
| 37 | insert into DriverLicenseCategory (category_name)
|
|---|
| 38 | values ('AM'),
|
|---|
| 39 | ('A1'),
|
|---|
| 40 | ('A2'),
|
|---|
| 41 | ('A'),
|
|---|
| 42 | ('B'),
|
|---|
| 43 | ('C1'),
|
|---|
| 44 | ('C'),
|
|---|
| 45 | ('D1'),
|
|---|
| 46 | ('D'),
|
|---|
| 47 | ('BE'),
|
|---|
| 48 | ('C1E'),
|
|---|
| 49 | ('CE'),
|
|---|
| 50 | ('D1E'),
|
|---|
| 51 | ('DE'),
|
|---|
| 52 | ('F'),
|
|---|
| 53 | ('G'),
|
|---|
| 54 | ('T');
|
|---|
| 55 |
|
|---|
| 56 | create table Driver
|
|---|
| 57 | (
|
|---|
| 58 | user_id int4 primary key references AppUser (id) on update cascade on delete cascade,
|
|---|
| 59 | driver_license_id int4 not null references DriverLicense (id) on update cascade on delete restrict,
|
|---|
| 60 | latitude double precision check ( latitude >= -90 and latitude <= 90 ),
|
|---|
| 61 | longitude double precision check ( longitude >= -180 and longitude <= 180 )
|
|---|
| 62 | );
|
|---|
| 63 |
|
|---|
| 64 | create table DriverLicense_DriverLicenseCategory
|
|---|
| 65 | (
|
|---|
| 66 | driver_license_id int4 references DriverLicense (id) on update cascade on delete cascade,
|
|---|
| 67 | driver_license_category_id int4 references DriverLicenseCategory (id) on update cascade on delete restrict,
|
|---|
| 68 | primary key (driver_license_id,
|
|---|
| 69 | driver_license_category_id)
|
|---|
| 70 | );
|
|---|
| 71 |
|
|---|
| 72 | create table FreelanceDriver
|
|---|
| 73 | (
|
|---|
| 74 | driver_user_id integer not null
|
|---|
| 75 | primary key
|
|---|
| 76 | references driver
|
|---|
| 77 | on update cascade on delete cascade,
|
|---|
| 78 | pricing_info_id int4 not null references pricinginfo (id),
|
|---|
| 79 | area_id int4 not null references area (id)
|
|---|
| 80 | );
|
|---|
| 81 |
|
|---|
| 82 | create table Company
|
|---|
| 83 | (
|
|---|
| 84 | id serial primary key,
|
|---|
| 85 | name varchar(50) not null check ( char_length(name) >= 1 and name ~ '^[A-Za-z0-9 &''.-]+$'),
|
|---|
| 86 | date_founded date not null check ( date_founded <= current_date and date_founded >= date '1800-01-01' ),
|
|---|
| 87 | tax_number varchar(20) not null check ( tax_number ~ '^[A-Z0-9]{5,20}$' ),
|
|---|
| 88 | phone_number varchar(15) not null check ( phone_number ~ '^\+?[0-9]{7,15}$' ),
|
|---|
| 89 | email varchar(254) check ( email is null or email ~* '^[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,}$' ),
|
|---|
| 90 | website varchar(255) CHECK ( website is null or website ~* '^(https?:\/\/)?([a-z0-9-]+\.)+[a-z]{2,}(\/.*)?$'),
|
|---|
| 91 | active bool not null default true
|
|---|
| 92 | );
|
|---|
| 93 |
|
|---|
| 94 | create table EmploymentHistory
|
|---|
| 95 | (
|
|---|
| 96 | employee_user_id int4 not null references AppUser (id) on update cascade on delete cascade,
|
|---|
| 97 | start_date date not null check ( start_date <= current_date ),
|
|---|
| 98 | end_date date,
|
|---|
| 99 | company_id int4 not null references Company (id) on update cascade on delete restrict,
|
|---|
| 100 | primary key (employee_user_id,
|
|---|
| 101 | start_date,
|
|---|
| 102 | company_id),
|
|---|
| 103 | check (end_date is null or (end_date > start_date and end_date <= current_date))
|
|---|
| 104 | );
|
|---|
| 105 |
|
|---|
| 106 | create table Area
|
|---|
| 107 | (
|
|---|
| 108 | id serial primary key,
|
|---|
| 109 | latitude double precision not null check ( latitude >= -90 and latitude <= 90 ),
|
|---|
| 110 | longitude double precision not null check ( longitude >= -180 and longitude <= 180 ),
|
|---|
| 111 | radius decimal not null check ( radius > 0 and radius <= 100000), -- in meters, max is 100km
|
|---|
| 112 | name varchar(100) not null check ( (char_length(trim(name)) >= 2) )
|
|---|
| 113 | );
|
|---|
| 114 |
|
|---|
| 115 | create table CurrencyCatalog
|
|---|
| 116 | (
|
|---|
| 117 | id serial primary key,
|
|---|
| 118 | currency varchar(5) not null unique
|
|---|
| 119 | );
|
|---|
| 120 | insert into CurrencyCatalog (currency)
|
|---|
| 121 | values ('USD'), -- US Dollar
|
|---|
| 122 | ('EUR'), -- Euro
|
|---|
| 123 | ('GBP'), -- British Pound
|
|---|
| 124 | ('MKD'), -- Macedonian Denar
|
|---|
| 125 | ('CHF'), -- Swiss Franc
|
|---|
| 126 | ('JPY'), -- Japanese Yen
|
|---|
| 127 | ('CNY'), -- Chinese Yuan
|
|---|
| 128 | ('AUD'), -- Australian Dollar
|
|---|
| 129 | ('CAD'), -- Canadian Dollar
|
|---|
| 130 | ('NZD'), -- New Zealand Dollar
|
|---|
| 131 | ('SEK'), -- Swedish Krona
|
|---|
| 132 | ('NOK'), -- Norwegian Krone
|
|---|
| 133 | ('DKK'), -- Danish Krone
|
|---|
| 134 | ('RSD'), -- Serbian Dinar
|
|---|
| 135 | ('BGN'), -- Bulgarian Lev
|
|---|
| 136 | ('TRY'), -- Turkish Lira
|
|---|
| 137 | ('INR'), -- Indian Rupee
|
|---|
| 138 | ('BRL'), -- Brazilian Real
|
|---|
| 139 | ('ZAR'), -- South African Rand
|
|---|
| 140 | ('SGD'), -- Singapore Dollar
|
|---|
| 141 | ('HKD'), -- Hong Kong Dollar
|
|---|
| 142 | ('KRW'), -- South Korean Won
|
|---|
| 143 | ('MXN'), -- Mexican Peso
|
|---|
| 144 | ('PLN'), -- Polish Zloty
|
|---|
| 145 | ('CZK'), -- Czech Koruna
|
|---|
| 146 | ('HUF'), -- Hungarian Forint
|
|---|
| 147 | ('ILS'), -- Israeli Shekel
|
|---|
| 148 | ('AED'), -- UAE Dirham
|
|---|
| 149 | ('SAR'), -- Saudi Riyal
|
|---|
| 150 | ('THB'); -- Thai Baht
|
|---|
| 151 |
|
|---|
| 152 | create type unit_type as enum ('kilometer', 'minute');
|
|---|
| 153 | create table PricingInfo
|
|---|
| 154 | (
|
|---|
| 155 | id serial primary key,
|
|---|
| 156 | value numeric(19, 2) not null check ( value > 0 ),
|
|---|
| 157 | unit unit_type not null,
|
|---|
| 158 | currency_id int4 not null references CurrencyCatalog (id) on update cascade on delete restrict
|
|---|
| 159 | );
|
|---|
| 160 |
|
|---|
| 161 | create table Company_Area
|
|---|
| 162 | (
|
|---|
| 163 | company_id int4 not null references Company (id) on update cascade on delete cascade,
|
|---|
| 164 | area_id int4 not null references Area (id) on update cascade on delete cascade,
|
|---|
| 165 | pricing_info_id int4 not null references PricingInfo (id) on update cascade on delete restrict,
|
|---|
| 166 | primary key (company_id, area_id)
|
|---|
| 167 | );
|
|---|
| 168 |
|
|---|
| 169 | create table Brand
|
|---|
| 170 | (
|
|---|
| 171 | id serial primary key,
|
|---|
| 172 | name varchar(50) not null check ( char_length(name) >= 1 and name ~ '^[A-Za-z0-9 &''.-]+$'),
|
|---|
| 173 | date_founded date not null check ( date_founded <= current_date and date_founded >= date '1800-01-01' ),
|
|---|
| 174 | phone_number varchar(15) check ( phone_number is null or phone_number ~ '^\+?[0-9]{7,15}$' ),
|
|---|
| 175 | email varchar(254) check ( email is null or email ~* '^[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,}$' )
|
|---|
| 176 | );
|
|---|
| 177 |
|
|---|
| 178 | create table ModelFuelTypeCatalog
|
|---|
| 179 | (
|
|---|
| 180 | id serial primary key,
|
|---|
| 181 | type varchar(20) not null unique check (char_length(trim(type)) > 1)
|
|---|
| 182 | );
|
|---|
| 183 | insert into ModelFuelTypeCatalog (type)
|
|---|
| 184 | values ('Petrol'),
|
|---|
| 185 | ('Diesel'),
|
|---|
| 186 | ('Electric'),
|
|---|
| 187 | ('Hybrid'),
|
|---|
| 188 | ('Plug-in Hybrid'),
|
|---|
| 189 | ('Hydrogen');
|
|---|
| 190 | create table ModelTransmissionCatalog
|
|---|
| 191 | (
|
|---|
| 192 | id serial primary key,
|
|---|
| 193 | transmission varchar(20) not null unique check (char_length(trim(transmission)) > 1)
|
|---|
| 194 | );
|
|---|
| 195 | insert into ModelTransmissionCatalog (transmission)
|
|---|
| 196 | values ('Automatic'),
|
|---|
| 197 | ('Manual');
|
|---|
| 198 |
|
|---|
| 199 | create table Model
|
|---|
| 200 | (
|
|---|
| 201 | id serial primary key,
|
|---|
| 202 | name varchar(50) not null check (char_length(trim(name)) >= 2),
|
|---|
| 203 | engine_capacity_cc decimal check (engine_capacity_cc > 0),
|
|---|
| 204 | body_style varchar(50) check (body_style is null or char_length(trim(body_style)) >= 2),
|
|---|
| 205 | brand_id int4 not null references Brand (id) on update cascade on delete restrict,
|
|---|
| 206 | model_fuel_type_catalog_id int4 not null references ModelFuelTypeCatalog (id) on update cascade on delete restrict,
|
|---|
| 207 | model_transmission_catalog_id int4 not null references ModelTransmissionCatalog (id) on update cascade on delete restrict
|
|---|
| 208 | );
|
|---|
| 209 |
|
|---|
| 210 | create table Vehicle
|
|---|
| 211 | (
|
|---|
| 212 | VIN varchar(17) primary key,
|
|---|
| 213 | passenger_capacity int4 not null check (passenger_capacity > 0 and passenger_capacity <= 50) default 1,
|
|---|
| 214 | year int4 not null check (year > 1950 and year <= extract(year from current_date)),
|
|---|
| 215 | wheelchair_accessible bool not null default false,
|
|---|
| 216 | model_id int4 not null references Model (id) on update cascade on delete restrict,
|
|---|
| 217 | category_id int4 not null references DriverLicenseCategory (id) on update cascade on delete restrict
|
|---|
| 218 | );
|
|---|
| 219 |
|
|---|
| 220 | create table ServiceHistory
|
|---|
| 221 | (
|
|---|
| 222 | id serial primary key,
|
|---|
| 223 | date date not null check ( date <= current_date ),
|
|---|
| 224 | price numeric(19, 2) not null check ( price > 0 ),
|
|---|
| 225 | currency_catalog_id int4 not null references CurrencyCatalog (id) on update cascade on delete restrict,
|
|---|
| 226 | fault_description text,
|
|---|
| 227 | fix_description text,
|
|---|
| 228 | vehicle_VIN varchar(17) references Vehicle (VIN) on update cascade on delete restrict
|
|---|
| 229 | );
|
|---|
| 230 |
|
|---|
| 231 | create table VehicleOwnership
|
|---|
| 232 | (
|
|---|
| 233 | vehicle_VIN varchar(17) not null references Vehicle (VIN) on update cascade on delete restrict,
|
|---|
| 234 | company_id int4 references Company (id) on update cascade on delete set null,
|
|---|
| 235 | freelance_driver_user_id int4 references FreelanceDriver (driver_user_id) on update cascade on delete set null,
|
|---|
| 236 | from_date date not null check ( from_date <= current_date ),
|
|---|
| 237 | to_date date,
|
|---|
| 238 | license_plate varchar(20) check ( license_plate is null or license_plate ~ '^[A-Z0-9-]{1,20}$' ),
|
|---|
| 239 | primary key (vehicle_VIN, from_date),
|
|---|
| 240 | check (to_date is null or to_date > from_date)
|
|---|
| 241 | );
|
|---|
| 242 |
|
|---|
| 243 | create table Registration
|
|---|
| 244 | (
|
|---|
| 245 | id serial primary key,
|
|---|
| 246 | vehicle_VIN varchar(17) not null,
|
|---|
| 247 | registration_date date not null check ( registration_date < current_date ),
|
|---|
| 248 | expiration_date date,
|
|---|
| 249 | vehicle_ownership_from_date date not null,
|
|---|
| 250 | check ( expiration_date is null or expiration_date > registration_date ),
|
|---|
| 251 | foreign key (vehicle_VIN, vehicle_ownership_from_date) references VehicleOwnership (vehicle_VIN, from_date) on update cascade on delete restrict,
|
|---|
| 252 | foreign key (vehicle_VIN) references Vehicle (VIN) on update cascade on delete restrict
|
|---|
| 253 | );
|
|---|
| 254 |
|
|---|
| 255 | create table Customer
|
|---|
| 256 | (
|
|---|
| 257 | user_id int4 primary key references AppUser (id) on update cascade on delete cascade
|
|---|
| 258 | );
|
|---|
| 259 |
|
|---|
| 260 | create table CustomerPreference
|
|---|
| 261 | (
|
|---|
| 262 | id serial primary key,
|
|---|
| 263 | seqno int4 not null check ( seqno > 0 ),
|
|---|
| 264 | customer_user_id int4 not null references Customer (user_id) on update cascade on delete cascade,
|
|---|
| 265 | freelance_driver_user_id int4 references FreelanceDriver (driver_user_id) on update cascade on delete set null,
|
|---|
| 266 | company_id int4 references Company (id) on update cascade on delete set null,
|
|---|
| 267 | check (
|
|---|
| 268 | (freelance_driver_user_id is not null and company_id is null)
|
|---|
| 269 | or
|
|---|
| 270 | (freelance_driver_user_id is null and company_id is not null)
|
|---|
| 271 | ),
|
|---|
| 272 | unique (customer_user_id, seqno)
|
|---|
| 273 | );
|
|---|
| 274 |
|
|---|
| 275 | create type request_status as enum ('pending', 'accepted', 'in_progress', 'completed', 'cancelled');
|
|---|
| 276 | create table Request
|
|---|
| 277 | (
|
|---|
| 278 | id serial primary key,
|
|---|
| 279 | customer_user_id int4 not null references Customer (user_id) on update cascade on delete cascade,
|
|---|
| 280 | start_latitude double precision not null check ( start_latitude >= -90 and start_latitude <= 90 ),
|
|---|
| 281 | start_longitude double precision not null check ( start_longitude >= -180 and start_longitude <= 180 ),
|
|---|
| 282 | end_latitude double precision not null check ( end_latitude >= -90 and end_latitude <= 90 ),
|
|---|
| 283 | end_longitude double precision not null check ( end_longitude >= -180 and end_longitude <= 180 ),
|
|---|
| 284 | timestamp timestamp not null default current_timestamp,
|
|---|
| 285 | number_of_adult_passengers int4 not null default 1 check (number_of_adult_passengers >= 1),
|
|---|
| 286 | number_of_children int4 default 0 check (number_of_children >= 0),
|
|---|
| 287 | status request_status not null default 'pending',
|
|---|
| 288 | female_driver bool not null default false,
|
|---|
| 289 | luggage bool not null default false,
|
|---|
| 290 | luggage_count int4 not null default 0 check ( luggage_count >= 0 ),
|
|---|
| 291 | baby_seat_count int4 not null default 0 check ( baby_seat_count >= 0 )
|
|---|
| 292 | );
|
|---|
| 293 |
|
|---|
| 294 | create table Waypoints
|
|---|
| 295 | (
|
|---|
| 296 | id serial primary key,
|
|---|
| 297 | latitude double precision not null check ( latitude >= -90 and latitude <= 90 ),
|
|---|
| 298 | longitude double precision not null check ( longitude >= -180 and longitude <= 180 ),
|
|---|
| 299 | seqno int4 not null check ( seqno > 0 ),
|
|---|
| 300 | request_id int4 references Request (id) on update cascade on delete cascade,
|
|---|
| 301 | unique (request_id, seqno)
|
|---|
| 302 | );
|
|---|
| 303 |
|
|---|
| 304 | create type offer_status as enum ('pending', 'accepted', 'rejected', 'cancelled', 'completed');
|
|---|
| 305 | create table Offer
|
|---|
| 306 | (
|
|---|
| 307 | id serial primary key,
|
|---|
| 308 | status offer_status NOT NULL default 'pending',
|
|---|
| 309 | created_at timestamp not null default current_timestamp,
|
|---|
| 310 | request_id int4 not null references Request (id) on update cascade on delete restrict,
|
|---|
| 311 | dispatcher_user_id int4 references Dispatcher (user_id) on update cascade on delete set null,
|
|---|
| 312 | driver_user_id int4 references Driver (user_id) on update cascade on delete set null,
|
|---|
| 313 | price numeric(19, 2) not null check ( price > 0 ) default 1,
|
|---|
| 314 | currency_catalog_id int4 references CurrencyCatalog (id) on update cascade on delete restrict,
|
|---|
| 315 | ETA timestamp,
|
|---|
| 316 | customer_user_id int4 references Customer (user_id) on update cascade on delete set null,
|
|---|
| 317 | check ( driver_user_id <> dispatcher_user_id )
|
|---|
| 318 | );
|
|---|
| 319 |
|
|---|
| 320 | create type ride_status as enum ('scheduled', 'in_progress', 'completed', 'cancelled');
|
|---|
| 321 | create table Ride
|
|---|
| 322 | (
|
|---|
| 323 | id serial primary key,
|
|---|
| 324 | start_time timestamp not null default current_timestamp,
|
|---|
| 325 | end_time timestamp,
|
|---|
| 326 | distance_traveled numeric(10, 2) not null default 0 check ( distance_traveled >= 0 ),
|
|---|
| 327 | vehicle_VIN varchar(17) not null references Vehicle (VIN) on update cascade on delete restrict,
|
|---|
| 328 | driver_user_id int4 not null references Driver (user_id) on update cascade on delete restrict,
|
|---|
| 329 | request_id int4 not null references Request (id) on update cascade on delete restrict,
|
|---|
| 330 | status ride_status not null default 'scheduled',
|
|---|
| 331 | offer_id int4 not null references Offer (id) on update cascade on delete restrict,
|
|---|
| 332 | check ( end_time is null or end_time > start_time )
|
|---|
| 333 | );
|
|---|
| 334 |
|
|---|
| 335 | create table Review
|
|---|
| 336 | (
|
|---|
| 337 | id serial primary key,
|
|---|
| 338 | rating numeric(3, 2) not null default 0 check ( rating >= 0 and rating <= 5 ),
|
|---|
| 339 | comment text check ( char_length(comment) <= 1000 ),
|
|---|
| 340 | ride_id int4 not null references Ride (id) on update cascade on delete cascade,
|
|---|
| 341 | customer_user_id int4 not null references Customer (user_id) on update cascade on delete cascade
|
|---|
| 342 | );
|
|---|
| 343 |
|
|---|
| 344 | create table Report
|
|---|
| 345 | (
|
|---|
| 346 | ride_id int4 references Ride (id) on update cascade on delete cascade,
|
|---|
| 347 | customer_user_id int4 references Customer (user_id) on update cascade on delete cascade,
|
|---|
| 348 | message text check ( char_length(message) <= 1000 ),
|
|---|
| 349 | title text check ( char_length(title) <= 1000 ),
|
|---|
| 350 | created_at timestamp not null default current_timestamp,
|
|---|
| 351 | latitude double precision check ( latitude >= -90 and latitude <= 90 ),
|
|---|
| 352 | longitude double precision check ( longitude >= -180 and longitude <= 180 ),
|
|---|
| 353 | reason text check (char_length(reason) <= 500),
|
|---|
| 354 | primary key (ride_id,
|
|---|
| 355 | customer_user_id)
|
|---|
| 356 | );
|
|---|
| 357 |
|
|---|
| 358 | create table ChatMessage
|
|---|
| 359 | (
|
|---|
| 360 | id serial primary key,
|
|---|
| 361 | message text not null check ( char_length(message) > 0 and char_length(message) < 2000),
|
|---|
| 362 | timestamp timestamp not null default current_timestamp,
|
|---|
| 363 | user_id_from int4 references AppUser (id) on update cascade on delete set null,
|
|---|
| 364 | ride_id int4 references Ride (id) on update cascade on delete set null
|
|---|
| 365 | );
|
|---|
| 366 |
|
|---|
| 367 | create table Location
|
|---|
| 368 | (
|
|---|
| 369 | id serial primary key,
|
|---|
| 370 | latitude double precision not null check ( latitude >= -90 and latitude <= 90 ),
|
|---|
| 371 | longitude double precision not null check ( longitude >= -180 and longitude <= 180 ),
|
|---|
| 372 | timestamp timestamp not null,
|
|---|
| 373 | ride_id int4 references Ride (id) on update cascade on delete set null
|
|---|
| 374 | );
|
|---|
| 375 |
|
|---|
| 376 | create table Payment
|
|---|
| 377 | (
|
|---|
| 378 | id serial primary key,
|
|---|
| 379 | completed_ride_id int4 references Ride (id) on update cascade on delete set null,
|
|---|
| 380 | total_amount numeric(19, 2) not null check ( total_amount > 0 ),
|
|---|
| 381 | currency_catalog_id int4 references CurrencyCatalog (id) on update cascade on delete restrict
|
|---|
| 382 | );
|
|---|
| 383 |
|
|---|
| 384 | create type payment_method_type as enum ('CASH','CARD');
|
|---|
| 385 | create table CustomerPayment
|
|---|
| 386 | (
|
|---|
| 387 | customer_user_id int4 not null default -1 references Customer (user_id) on update cascade on delete set default,
|
|---|
| 388 | payment_id int4 not null default -1 references Payment (id) on update cascade on delete set default,
|
|---|
| 389 | amount numeric(19, 2) not null check ( amount > 0 ),
|
|---|
| 390 | currency_catalog_id int4 not null references CurrencyCatalog (id) on update cascade on delete restrict,
|
|---|
| 391 | timestamp timestamp not null default current_timestamp,
|
|---|
| 392 | payment_method payment_method_type,
|
|---|
| 393 | transaction_id varchar(64) unique,
|
|---|
| 394 | primary key (customer_user_id,
|
|---|
| 395 | payment_id)
|
|---|
| 396 | );
|
|---|
| 397 |
|
|---|
| 398 | create table driver_vehicle
|
|---|
| 399 | (
|
|---|
| 400 | id serial primary key,
|
|---|
| 401 | vin_vehicle varchar(17) not null references vehicle (vin) on delete restrict on update cascade,
|
|---|
| 402 | id_driver int not null references driver (user_id) on delete restrict on update cascade,
|
|---|
| 403 | time_from timestamp not null,
|
|---|
| 404 | time_to timestamp
|
|---|
| 405 | ); |
|---|