-
Notifications
You must be signed in to change notification settings - Fork 876
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Handles container restarts for already initialized postgresql database
- Loading branch information
Showing
2 changed files
with
24 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,102 +1,75 @@ | ||
-- Create tables only if they don't exist | ||
CREATE TABLE IF NOT EXISTS vets ( | ||
id SERIAL, | ||
id SERIAL PRIMARY KEY, | ||
first_name VARCHAR(30), | ||
last_name VARCHAR(30), | ||
CONSTRAINT pk_vets PRIMARY KEY (id) | ||
last_name VARCHAR(30) | ||
); | ||
|
||
CREATE INDEX IF NOT EXISTS idx_vets_last_name ON vets (last_name); | ||
|
||
ALTER SEQUENCE vets_id_seq RESTART WITH 100; | ||
|
||
|
||
CREATE TABLE IF NOT EXISTS specialties ( | ||
id SERIAL, | ||
name VARCHAR(80), | ||
CONSTRAINT pk_specialties PRIMARY KEY (id) | ||
id SERIAL PRIMARY KEY, | ||
name VARCHAR(80) | ||
); | ||
|
||
CREATE INDEX IF NOT EXISTS idx_specialties_name ON specialties (name); | ||
|
||
ALTER SEQUENCE specialties_id_seq RESTART WITH 100; | ||
|
||
|
||
CREATE TABLE IF NOT EXISTS vet_specialties ( | ||
vet_id INT NOT NULL, | ||
specialty_id INT NOT NULL, | ||
FOREIGN KEY (vet_id) REFERENCES vets(id), | ||
FOREIGN KEY (specialty_id) REFERENCES specialties(id), | ||
CONSTRAINT unique_ids UNIQUE (vet_id,specialty_id) | ||
UNIQUE (vet_id, specialty_id) | ||
); | ||
|
||
|
||
|
||
CREATE TABLE IF NOT EXISTS types ( | ||
id SERIAL, | ||
name VARCHAR(80), | ||
CONSTRAINT pk_types PRIMARY KEY (id) | ||
id SERIAL PRIMARY KEY, | ||
name VARCHAR(80) | ||
); | ||
|
||
CREATE INDEX IF NOT EXISTS idx_types_name ON types (name); | ||
|
||
ALTER SEQUENCE types_id_seq RESTART WITH 100; | ||
|
||
CREATE TABLE IF NOT EXISTS owners ( | ||
id SERIAL, | ||
id SERIAL PRIMARY KEY, | ||
first_name VARCHAR(30), | ||
last_name VARCHAR(30), | ||
address VARCHAR(255), | ||
city VARCHAR(80), | ||
telephone VARCHAR(20), | ||
CONSTRAINT pk_owners PRIMARY KEY (id) | ||
telephone VARCHAR(20) | ||
); | ||
|
||
CREATE INDEX IF NOT EXISTS idx_owners_last_name ON owners (last_name); | ||
|
||
ALTER SEQUENCE owners_id_seq RESTART WITH 100; | ||
|
||
|
||
CREATE TABLE IF NOT EXISTS pets ( | ||
id SERIAL, | ||
id SERIAL PRIMARY KEY, | ||
name VARCHAR(30), | ||
birth_date DATE, | ||
type_id INT NOT NULL, | ||
owner_id INT NOT NULL, | ||
FOREIGN KEY (owner_id) REFERENCES owners(id), | ||
FOREIGN KEY (type_id) REFERENCES types(id), | ||
CONSTRAINT pk_pets PRIMARY KEY (id) | ||
FOREIGN KEY (type_id) REFERENCES types(id) | ||
); | ||
|
||
CREATE INDEX IF NOT EXISTS idx_pets_name ON pets (name); | ||
|
||
ALTER SEQUENCE pets_id_seq RESTART WITH 100; | ||
|
||
|
||
CREATE TABLE IF NOT EXISTS visits ( | ||
id SERIAL, | ||
id SERIAL PRIMARY KEY, | ||
pet_id INT NOT NULL, | ||
visit_date DATE, | ||
description VARCHAR(255), | ||
FOREIGN KEY (pet_id) REFERENCES pets(id), | ||
CONSTRAINT pk_visits PRIMARY KEY (id) | ||
FOREIGN KEY (pet_id) REFERENCES pets(id) | ||
); | ||
|
||
ALTER SEQUENCE visits_id_seq RESTART WITH 100; | ||
|
||
CREATE TABLE IF NOT EXISTS users ( | ||
username VARCHAR(20) NOT NULL , | ||
password VARCHAR(20) NOT NULL , | ||
enabled boolean NOT NULL DEFAULT true , | ||
CONSTRAINT pk_users PRIMARY KEY (username) | ||
username VARCHAR(20) NOT NULL PRIMARY KEY, | ||
password VARCHAR(20) NOT NULL, | ||
enabled BOOLEAN NOT NULL DEFAULT true | ||
); | ||
|
||
CREATE TABLE IF NOT EXISTS roles ( | ||
id SERIAL, | ||
username varchar(20) NOT NULL, | ||
role varchar(20) NOT NULL, | ||
CONSTRAINT pk_roles PRIMARY KEY (id), | ||
FOREIGN KEY (username) REFERENCES users (username) | ||
); | ||
|
||
ALTER TABLE roles ADD CONSTRAINT uni_username_role UNIQUE (role,username); | ||
ALTER SEQUENCE roles_id_seq RESTART WITH 100; | ||
id SERIAL PRIMARY KEY, | ||
username VARCHAR(20) NOT NULL, | ||
role VARCHAR(20) NOT NULL, | ||
FOREIGN KEY (username) REFERENCES users (username), | ||
UNIQUE (role, username) | ||
); |