· 7 years ago · Dec 12, 2018, 09:56 AM
1--liquibase formatted sql
2--changeset aleksandra.kopera:3
3CREATE TABLE hotels(
4 id BIGINT PRIMARY KEY,
5 name VARCHAR (255) NOT NULL UNIQUE,
6 street_and_number VARCHAR (255) NOT NULL,
7 city VARCHAR (120) NOT NULL,
8 postal_code VARCHAR (10) NOT NULL,
9 phone_number VARCHAR (40)
10);
11
12CREATE TABLE hotel_employees (
13 hotel_id BIGINT NOT NULL REFERENCES hotels(id) ON DELETE CASCADE,
14 user_id BIGINT NOT NULL REFERENCES users(id) ON DELETE CASCADE,
15 PRIMARY KEY (hotel_id, user_id)
16);
17
18CREATE INDEX idx_hotel_name ON hotels(name);
19CREATE INDEX idx_city ON hotels(city);
20CREATE INDEX idx_street_and_number ON hotels(street_and_number);
21CREATE INDEX idx_postal_code ON hotels(postal_code);
22CREATE INDEX idx_hotel_employees_id ON hotel_employees(hotel_id);
23
24
25INSERT INTO hotels(id,name,street_and_number,city,postal_code,phone_number)
26VALUES ((SELECT nextval('hibernate_sequence')),'hotel','test 3','Krakow','12-222','123456789');
27
28--rollback delete from hotels where name = 'hotel';
29--rollback drop index if exists idx_hotel_name;
30--rollback drop index if exists idx_city;
31--rollback drop index if exists idx_street_and_number;
32--rollback drop index if exists idx_postal_code;
33--rollback drop index if exists idx_hotel_employees_id;
34--rollback drop table hotel_employees;
35--rollback drop table hotel;