Skip to content

Commit ee429f2

Browse files
selvasinghAryan-CC
andauthored
PostgreSQL binding for Spring-Petclinic-Microservices (Azure-Samples#105)
This unit is by Spektra to add PostgreSQL binding for the sample app. --------- Co-authored-by: Aryan-CC <aryan.p@spektrasystems.com>
1 parent ec4f2fb commit ee429f2

File tree

9 files changed

+145
-0
lines changed

9 files changed

+145
-0
lines changed

src/spring-petclinic-customers-service/pom.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,10 @@
5959
<groupId>com.azure.spring</groupId>
6060
<artifactId>spring-cloud-azure-starter-jdbc-mysql</artifactId>
6161
</dependency>
62+
<dependency>
63+
<groupId>com.azure.spring</groupId>
64+
<artifactId>spring-cloud-azure-starter-jdbc-postgresql</artifactId>
65+
</dependency>
6266
<dependency>
6367
<groupId>org.hsqldb</groupId>
6468
<artifactId>hsqldb</artifactId>
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
2+
INSERT INTO types (id, name) VALUES
3+
(1, 'Dog'),
4+
(2, 'Cat'),
5+
(3, 'Bird'),
6+
(4, 'Reptile'),
7+
(5, 'Fish'),
8+
(6, 'Rodent')
9+
ON CONFLICT (id) DO NOTHING;
10+
11+
INSERT INTO owners (id, first_name, last_name, address, city, telephone) VALUES
12+
(1, 'George', 'Franklin', '110 W. Liberty St.', 'Madison', '6085551023'),
13+
(2, 'Betty', 'Davis', '638 Cardinal Ave.', 'Sun Prairie', '6085551749'),
14+
(3, 'Eduardo', 'Rodriquez', '2693 Commerce St.', 'McFarland', '6085558763'),
15+
(4, 'Harold', 'Davis', '563 Friendly St.', 'Windsor', '6085553198'),
16+
(5, 'Peter', 'McTavish', '2387 S. Fair Way', 'Madison', '6085552765'),
17+
(6, 'Jean', 'Coleman', '105 N. Lake St.', 'Monona', '6085552654'),
18+
(7, 'Jeff', 'Black', '1450 Oak Blvd.', 'Monona', '6085555387'),
19+
(8, 'Maria', 'Escobito', '345 Maple St.', 'Madison', '6085557683'),
20+
(9, 'David', 'Schroeder', '2749 Blackhawk Trail', 'Madison', '6085559435'),
21+
(10, 'Carlos', 'Estaban', '2335 Independence La.', 'Waunakee', '6085555487')
22+
ON CONFLICT (id) DO NOTHING;
23+
24+
INSERT INTO pets (id, name, birth_date, type_id, owner_id) VALUES
25+
(1, 'Leo', '2000-09-07', 1, 1),
26+
(2, 'Basil', '2002-08-06', 6, 2),
27+
(3, 'Rosy', '2001-04-17', 2, 3),
28+
(4, 'Jewel', '2000-03-07', 2, 3),
29+
(5, 'Iggy', '2000-11-30', 3, 4),
30+
(6, 'George', '2000-01-20', 4, 5),
31+
(7, 'Samantha', '1995-09-04', 1, 6),
32+
(8, 'Max', '1995-09-04', 1, 6),
33+
(9, 'Lucky', '1999-08-06', 5, 7),
34+
(10, 'Mulligan', '1997-02-24', 2, 8),
35+
(11, 'Freddy', '2000-03-09', 5, 9),
36+
(12, 'Lucky', '2000-06-24', 2, 10),
37+
(13, 'Sly', '2002-06-08', 1, 10)
38+
ON CONFLICT (id) DO NOTHING;
39+
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
2+
CREATE TABLE IF NOT EXISTS types (
3+
id SERIAL PRIMARY KEY,
4+
name VARCHAR(80) NOT NULL,
5+
UNIQUE (name)
6+
);
7+
8+
9+
CREATE TABLE IF NOT EXISTS owners (
10+
id SERIAL PRIMARY KEY,
11+
first_name VARCHAR(30) NOT NULL,
12+
last_name VARCHAR(30) NOT NULL,
13+
address VARCHAR(255) NOT NULL,
14+
city VARCHAR(80) NOT NULL,
15+
telephone VARCHAR(20) NOT NULL
16+
);
17+
18+
19+
CREATE TABLE IF NOT EXISTS pets (
20+
id SERIAL PRIMARY KEY,
21+
name VARCHAR(30) NOT NULL,
22+
birth_date DATE NOT NULL,
23+
type_id INT NOT NULL,
24+
owner_id INT NOT NULL,
25+
FOREIGN KEY (owner_id) REFERENCES owners(id) ON DELETE CASCADE,
26+
FOREIGN KEY (type_id) REFERENCES types(id) ON DELETE CASCADE
27+
);
28+
29+
CREATE INDEX idx_last_name ON owners(last_name);
30+
CREATE INDEX idx_name ON pets(name);

src/spring-petclinic-vets-service/pom.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,10 @@
9393
<groupId>com.azure.spring</groupId>
9494
<artifactId>spring-cloud-azure-starter-jdbc-mysql</artifactId>
9595
</dependency>
96+
<dependency>
97+
<groupId>com.azure.spring</groupId>
98+
<artifactId>spring-cloud-azure-starter-jdbc-postgresql</artifactId>
99+
</dependency>
96100
<dependency>
97101
<groupId>io.micrometer</groupId>
98102
<artifactId>micrometer-registry-prometheus</artifactId>
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
INSERT INTO vets (id, first_name, last_name) VALUES
2+
(1, 'James', 'Carter'),
3+
(2, 'Helen', 'Leary'),
4+
(3, 'Linda', 'Douglas'),
5+
(4, 'Rafael', 'Ortega'),
6+
(5, 'Henry', 'Stevens'),
7+
(6, 'Sharon', 'Jenkins')
8+
ON CONFLICT (id) DO NOTHING;
9+
10+
INSERT INTO specialties (id, name) VALUES
11+
(1, 'radiology'),
12+
(2, 'surgery'),
13+
(3, 'dentistry')
14+
ON CONFLICT (id) DO NOTHING;
15+
16+
INSERT INTO vet_specialties (vet_id, specialty_id) VALUES
17+
(2, 1),
18+
(3, 2),
19+
(3, 3),
20+
(4, 2),
21+
(5, 1)
22+
ON CONFLICT (vet_id, specialty_id) DO NOTHING;
23+
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
2+
CREATE TABLE IF NOT EXISTS vets (
3+
id SERIAL PRIMARY KEY,
4+
first_name VARCHAR(30) NOT NULL,
5+
last_name VARCHAR(30) NOT NULL
6+
);
7+
8+
CREATE INDEX idx_vets_last_name ON vets(last_name);
9+
10+
CREATE TABLE IF NOT EXISTS specialties (
11+
id SERIAL PRIMARY KEY,
12+
name VARCHAR(80) NOT NULL,
13+
UNIQUE (name)
14+
);
15+
16+
CREATE TABLE IF NOT EXISTS vet_specialties (
17+
vet_id INT NOT NULL,
18+
specialty_id INT NOT NULL,
19+
PRIMARY KEY (vet_id, specialty_id),
20+
FOREIGN KEY (vet_id) REFERENCES vets(id) ON DELETE CASCADE,
21+
FOREIGN KEY (specialty_id) REFERENCES specialties(id) ON DELETE CASCADE
22+
);

src/spring-petclinic-visits-service/pom.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,10 @@
7878
<groupId>com.azure.spring</groupId>
7979
<artifactId>spring-cloud-azure-starter-jdbc-mysql</artifactId>
8080
</dependency>
81+
<dependency>
82+
<groupId>com.azure.spring</groupId>
83+
<artifactId>spring-cloud-azure-starter-jdbc-postgresql</artifactId>
84+
</dependency>
8185
<dependency>
8286
<groupId>io.micrometer</groupId>
8387
<artifactId>micrometer-registry-prometheus</artifactId>
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
2+
3+
INSERT INTO visits (id, pet_id, visit_date, description) VALUES
4+
(1, 7, '2010-03-04', 'rabies shot'),
5+
(2, 8, '2011-03-04', 'rabies shot'),
6+
(3, 8, '2009-06-04', 'neutered'),
7+
(4, 7, '2008-09-04', 'spayed')
8+
ON CONFLICT (id) DO NOTHING;
9+
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
2+
3+
4+
CREATE TABLE IF NOT EXISTS visits (
5+
id SERIAL PRIMARY KEY,
6+
pet_id INT NOT NULL,
7+
visit_date DATE,
8+
description VARCHAR(8192),
9+
FOREIGN KEY (pet_id) REFERENCES pets(id) ON DELETE CASCADE
10+
);

0 commit comments

Comments
 (0)