Advertisement
DrMGC

Untitled

Dec 15th, 2020
1,046
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. CREATE SCHEMA route;
  2.  
  3. CREATE SCHEMA station;
  4.  
  5. CREATE SCHEMA train;
  6.  
  7. CREATE SCHEMA ticket;
  8.  
  9. CREATE SCHEMA trip;
  10.  
  11. CREATE SCHEMA auth;
  12.  
  13. CREATE TABLE route.stage (
  14.     route_id INTEGER NOT NULL,
  15.     station_id INTEGER NOT NULL,
  16.     arrival INTERVAL NOT NULL,
  17.     departure INTERVAL NOT NULL,
  18.     PRIMARY KEY (route_id, station_id)
  19. );
  20.  
  21. CREATE TABLE station.station (
  22.     id SERIAL NOT NULL,
  23.     name VARCHAR(64) NOT NULL,
  24.     is_passanger BOOLEAN NOT NULL,
  25.     PRIMARY KEY (id)
  26. );
  27.  
  28. CREATE TABLE train.train (
  29.     id SERIAL NOT NULL,
  30.     name VARCHAR(32) NOT NULL,
  31.     price_multiplier FLOAT DEFAULT '1' NOT NULL,
  32.     PRIMARY KEY (id)
  33. );
  34.  
  35. COMMENT ON COLUMN train.train.price_multiplier IS 'Множитель стоимости на все цены';
  36.  
  37. CREATE TABLE train.wagon_class (
  38.     id SERIAL NOT NULL,
  39.     name VARCHAR(8) NOT NULL,
  40.     seats JSONB NOT NULL,
  41.     seats_schema BYTEA,
  42.     seats_count INTEGER NOT NULL,
  43.     PRIMARY KEY (id)
  44. );
  45.  
  46. CREATE TABLE auth."user" (
  47.     id SERIAL NOT NULL,
  48.     name VARCHAR NOT NULL,
  49.     birthday DATE NOT NULL,
  50.     email VARCHAR(40),
  51.     password_hash VARCHAR(200) NOT NULL,
  52.     created_on TIMESTAMP WITHOUT TIME ZONE DEFAULT now() NOT NULL,
  53.     last_login TIMESTAMP WITHOUT TIME ZONE,
  54.     is_admin BOOLEAN NOT NULL,
  55.     PRIMARY KEY (id),
  56.     UNIQUE (email)
  57. );
  58.  
  59. COMMENT ON COLUMN auth."user".name IS 'Полное имя пользователя';
  60.  
  61. CREATE TABLE route.route (
  62.     id SERIAL NOT NULL,
  63.     name VARCHAR(12) NOT NULL,
  64.     departure_station_id INTEGER NOT NULL,
  65.     arrival_station_id INTEGER NOT NULL,
  66.     PRIMARY KEY (id),
  67.     FOREIGN KEY(arrival_station_id) REFERENCES station.station (id),
  68.     FOREIGN KEY(departure_station_id) REFERENCES station.station (id),
  69.     UNIQUE (name)
  70. );
  71.  
  72. CREATE TABLE train.wagon (
  73.     train_id INTEGER NOT NULL,
  74.     number INTEGER NOT NULL,
  75.     wagon_class_id INTEGER NOT NULL,
  76.     PRIMARY KEY (train_id, number),
  77.     FOREIGN KEY(train_id) REFERENCES train.train (id),
  78.     FOREIGN KEY(wagon_class_id) REFERENCES train.wagon_class (id)
  79. );
  80.  
  81. CREATE TABLE trip.trip (
  82.     id SERIAL NOT NULL,
  83.     name VARCHAR(32) NOT NULL,
  84.     price_multiplier FLOAT DEFAULT '1' NOT NULL,
  85.     departure_date DATE NOT NULL,
  86.     route_id INTEGER NOT NULL,
  87.     train_id INTEGER NOT NULL,
  88.     PRIMARY KEY (id),
  89.     FOREIGN KEY(route_id) REFERENCES route.route (id),
  90.     FOREIGN KEY(train_id) REFERENCES train.train (id)
  91. );
  92.  
  93. COMMENT ON COLUMN trip.trip.price_multiplier IS 'Множитель стоимости на все цены';
  94.  
  95. CREATE TABLE ticket.purchased (
  96.     id SERIAL NOT NULL,
  97.     trip_id INTEGER NOT NULL,
  98.     wagon_number INTEGER NOT NULL,
  99.     seat_number INTEGER NOT NULL,
  100.     departure_id INTEGER NOT NULL,
  101.     arrival_id INTEGER NOT NULL,
  102.     user_id INTEGER NOT NULL,
  103.     puchase_datetime TIMESTAMP WITHOUT TIME ZONE DEFAULT now() NOT NULL,
  104.     PRIMARY KEY (id),
  105.     FOREIGN KEY(arrival_id) REFERENCES station.station (id),
  106.     FOREIGN KEY(departure_id) REFERENCES station.station (id),
  107.     FOREIGN KEY(trip_id) REFERENCES trip.trip (id),
  108.     FOREIGN KEY(user_id) REFERENCES auth."user" (id)
  109. );
  110.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement