forked from spring-projects/spring-petclinic
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
The postgres user needs to be an owner of the public schema or a superuser in order to execute the schema.sql for database initialization. To avoid that, two changes are required: - use `CREATE TABLE IF NOT EXISTS` in order to idempotently create the necessary tables - handle conflicts when inserting duplicate data This follows the pattern in use by the src/main/resources/db/mysql/{data,schema.sql} files. Authored-by: Shaan Sapra <[email protected]>
- Loading branch information
Showing
2 changed files
with
54 additions
and
64 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,59 +1,53 @@ | ||
INSERT INTO vets VALUES (1, 'James', 'Carter'); | ||
INSERT INTO vets VALUES (2, 'Helen', 'Leary'); | ||
INSERT INTO vets VALUES (3, 'Linda', 'Douglas'); | ||
INSERT INTO vets VALUES (4, 'Rafael', 'Ortega'); | ||
INSERT INTO vets VALUES (5, 'Henry', 'Stevens'); | ||
INSERT INTO vets VALUES (6, 'Sharon', 'Jenkins'); | ||
ALTER SEQUENCE vets_id_seq RESTART WITH 7; | ||
INSERT INTO vets VALUES (1, 'James', 'Carter') ON CONFLICT (id) DO NOTHING; | ||
INSERT INTO vets VALUES (2, 'Helen', 'Leary') ON CONFLICT (id) DO NOTHING; | ||
INSERT INTO vets VALUES (3, 'Linda', 'Douglas') ON CONFLICT (id) DO NOTHING; | ||
INSERT INTO vets VALUES (4, 'Rafael', 'Ortega') ON CONFLICT (id) DO NOTHING; | ||
INSERT INTO vets VALUES (5, 'Henry', 'Stevens') ON CONFLICT (id) DO NOTHING; | ||
INSERT INTO vets VALUES (6, 'Sharon', 'Jenkins') ON CONFLICT (id) DO NOTHING; | ||
|
||
INSERT INTO specialties VALUES (1, 'radiology'); | ||
INSERT INTO specialties VALUES (2, 'surgery'); | ||
INSERT INTO specialties VALUES (3, 'dentistry'); | ||
ALTER SEQUENCE specialties_id_seq RESTART WITH 4; | ||
INSERT INTO specialties VALUES (1, 'radiology') ON CONFLICT (id) DO NOTHING; | ||
INSERT INTO specialties VALUES (2, 'surgery') ON CONFLICT (id) DO NOTHING; | ||
INSERT INTO specialties VALUES (3, 'dentistry') ON CONFLICT (id) DO NOTHING; | ||
|
||
INSERT INTO vet_specialties VALUES (2, 1); | ||
INSERT INTO vet_specialties VALUES (3, 2); | ||
INSERT INTO vet_specialties VALUES (3, 3); | ||
INSERT INTO vet_specialties VALUES (4, 2); | ||
INSERT INTO vet_specialties VALUES (5, 1); | ||
INSERT INTO vet_specialties VALUES (2, 1) ON CONFLICT (vet_id, specialty_id) DO NOTHING; | ||
INSERT INTO vet_specialties VALUES (3, 2) ON CONFLICT (vet_id, specialty_id) DO NOTHING; | ||
INSERT INTO vet_specialties VALUES (3, 3) ON CONFLICT (vet_id, specialty_id) DO NOTHING; | ||
INSERT INTO vet_specialties VALUES (4, 2) ON CONFLICT (vet_id, specialty_id) DO NOTHING; | ||
INSERT INTO vet_specialties VALUES (5, 1) ON CONFLICT (vet_id, specialty_id) DO NOTHING; | ||
|
||
INSERT INTO types VALUES (1, 'cat'); | ||
INSERT INTO types VALUES (2, 'dog'); | ||
INSERT INTO types VALUES (3, 'lizard'); | ||
INSERT INTO types VALUES (4, 'snake'); | ||
INSERT INTO types VALUES (5, 'bird'); | ||
INSERT INTO types VALUES (6, 'hamster'); | ||
ALTER SEQUENCE types_id_seq RESTART WITH 7; | ||
INSERT INTO types VALUES (1, 'cat') ON CONFLICT (id) DO NOTHING; | ||
INSERT INTO types VALUES (2, 'dog') ON CONFLICT (id) DO NOTHING; | ||
INSERT INTO types VALUES (3, 'lizard') ON CONFLICT (id) DO NOTHING; | ||
INSERT INTO types VALUES (4, 'snake') ON CONFLICT (id) DO NOTHING; | ||
INSERT INTO types VALUES (5, 'bird') ON CONFLICT (id) DO NOTHING; | ||
INSERT INTO types VALUES (6, 'hamster') ON CONFLICT (id) DO NOTHING; | ||
|
||
INSERT INTO owners VALUES (1, 'George', 'Franklin', '110 W. Liberty St.', 'Madison', '6085551023'); | ||
INSERT INTO owners VALUES (2, 'Betty', 'Davis', '638 Cardinal Ave.', 'Sun Prairie', '6085551749'); | ||
INSERT INTO owners VALUES (3, 'Eduardo', 'Rodriquez', '2693 Commerce St.', 'McFarland', '6085558763'); | ||
INSERT INTO owners VALUES (4, 'Harold', 'Davis', '563 Friendly St.', 'Windsor', '6085553198'); | ||
INSERT INTO owners VALUES (5, 'Peter', 'McTavish', '2387 S. Fair Way', 'Madison', '6085552765'); | ||
INSERT INTO owners VALUES (6, 'Jean', 'Coleman', '105 N. Lake St.', 'Monona', '6085552654'); | ||
INSERT INTO owners VALUES (7, 'Jeff', 'Black', '1450 Oak Blvd.', 'Monona', '6085555387'); | ||
INSERT INTO owners VALUES (8, 'Maria', 'Escobito', '345 Maple St.', 'Madison', '6085557683'); | ||
INSERT INTO owners VALUES (9, 'David', 'Schroeder', '2749 Blackhawk Trail', 'Madison', '6085559435'); | ||
INSERT INTO owners VALUES (10, 'Carlos', 'Estaban', '2335 Independence La.', 'Waunakee', '6085555487'); | ||
ALTER SEQUENCE owners_id_seq RESTART WITH 11; | ||
INSERT INTO owners VALUES (1, 'George', 'Franklin', '110 W. Liberty St.', 'Madison', '6085551023') ON CONFLICT (id) DO NOTHING; | ||
INSERT INTO owners VALUES (2, 'Betty', 'Davis', '638 Cardinal Ave.', 'Sun Prairie', '6085551749') ON CONFLICT (id) DO NOTHING; | ||
INSERT INTO owners VALUES (3, 'Eduardo', 'Rodriquez', '2693 Commerce St.', 'McFarland', '6085558763') ON CONFLICT (id) DO NOTHING; | ||
INSERT INTO owners VALUES (4, 'Harold', 'Davis', '563 Friendly St.', 'Windsor', '6085553198') ON CONFLICT (id) DO NOTHING; | ||
INSERT INTO owners VALUES (5, 'Peter', 'McTavish', '2387 S. Fair Way', 'Madison', '6085552765') ON CONFLICT (id) DO NOTHING; | ||
INSERT INTO owners VALUES (6, 'Jean', 'Coleman', '105 N. Lake St.', 'Monona', '6085552654') ON CONFLICT (id) DO NOTHING; | ||
INSERT INTO owners VALUES (7, 'Jeff', 'Black', '1450 Oak Blvd.', 'Monona', '6085555387') ON CONFLICT (id) DO NOTHING; | ||
INSERT INTO owners VALUES (8, 'Maria', 'Escobito', '345 Maple St.', 'Madison', '6085557683') ON CONFLICT (id) DO NOTHING; | ||
INSERT INTO owners VALUES (9, 'David', 'Schroeder', '2749 Blackhawk Trail', 'Madison', '6085559435') ON CONFLICT (id) DO NOTHING; | ||
INSERT INTO owners VALUES (10, 'Carlos', 'Estaban', '2335 Independence La.', 'Waunakee', '6085555487') ON CONFLICT (id) DO NOTHING; | ||
|
||
INSERT INTO pets VALUES (1, 'Leo', '2000-09-07', 1, 1); | ||
INSERT INTO pets VALUES (2, 'Basil', '2002-08-06', 6, 2); | ||
INSERT INTO pets VALUES (3, 'Rosy', '2001-04-17', 2, 3); | ||
INSERT INTO pets VALUES (4, 'Jewel', '2000-03-07', 2, 3); | ||
INSERT INTO pets VALUES (5, 'Iggy', '2000-11-30', 3, 4); | ||
INSERT INTO pets VALUES (6, 'George', '2000-01-20', 4, 5); | ||
INSERT INTO pets VALUES (7, 'Samantha', '1995-09-04', 1, 6); | ||
INSERT INTO pets VALUES (8, 'Max', '1995-09-04', 1, 6); | ||
INSERT INTO pets VALUES (9, 'Lucky', '1999-08-06', 5, 7); | ||
INSERT INTO pets VALUES (10, 'Mulligan', '1997-02-24', 2, 8); | ||
INSERT INTO pets VALUES (11, 'Freddy', '2000-03-09', 5, 9); | ||
INSERT INTO pets VALUES (12, 'Lucky', '2000-06-24', 2, 10); | ||
INSERT INTO pets VALUES (13, 'Sly', '2002-06-08', 1, 10); | ||
ALTER SEQUENCE pets_id_seq RESTART WITH 14; | ||
INSERT INTO pets VALUES (1, 'Leo', '2000-09-07', 1, 1) ON CONFLICT (id) DO NOTHING; | ||
INSERT INTO pets VALUES (2, 'Basil', '2002-08-06', 6, 2) ON CONFLICT (id) DO NOTHING; | ||
INSERT INTO pets VALUES (3, 'Rosy', '2001-04-17', 2, 3) ON CONFLICT (id) DO NOTHING; | ||
INSERT INTO pets VALUES (4, 'Jewel', '2000-03-07', 2, 3) ON CONFLICT (id) DO NOTHING; | ||
INSERT INTO pets VALUES (5, 'Iggy', '2000-11-30', 3, 4) ON CONFLICT (id) DO NOTHING; | ||
INSERT INTO pets VALUES (6, 'George', '2000-01-20', 4, 5) ON CONFLICT (id) DO NOTHING; | ||
INSERT INTO pets VALUES (7, 'Samantha', '1995-09-04', 1, 6) ON CONFLICT (id) DO NOTHING; | ||
INSERT INTO pets VALUES (8, 'Max', '1995-09-04', 1, 6) ON CONFLICT (id) DO NOTHING; | ||
INSERT INTO pets VALUES (9, 'Lucky', '1999-08-06', 5, 7) ON CONFLICT (id) DO NOTHING; | ||
INSERT INTO pets VALUES (10, 'Mulligan', '1997-02-24', 2, 8) ON CONFLICT (id) DO NOTHING; | ||
INSERT INTO pets VALUES (11, 'Freddy', '2000-03-09', 5, 9) ON CONFLICT (id) DO NOTHING; | ||
INSERT INTO pets VALUES (12, 'Lucky', '2000-06-24', 2, 10) ON CONFLICT (id) DO NOTHING; | ||
INSERT INTO pets VALUES (13, 'Sly', '2002-06-08', 1, 10) ON CONFLICT (id) DO NOTHING; | ||
|
||
INSERT INTO visits VALUES (1, 7, '2010-03-04', 'rabies shot'); | ||
INSERT INTO visits VALUES (2, 8, '2011-03-04', 'rabies shot'); | ||
INSERT INTO visits VALUES (3, 8, '2009-06-04', 'neutered'); | ||
INSERT INTO visits VALUES (4, 7, '2008-09-04', 'spayed'); | ||
ALTER SEQUENCE visits_id_seq RESTART WITH 5; | ||
INSERT INTO visits VALUES (1, 7, '2010-03-04', 'rabies shot') ON CONFLICT (id) DO NOTHING; | ||
INSERT INTO visits VALUES (2, 8, '2011-03-04', 'rabies shot') ON CONFLICT (id) DO NOTHING; | ||
INSERT INTO visits VALUES (3, 8, '2009-06-04', 'neutered') ON CONFLICT (id) DO NOTHING; | ||
INSERT INTO visits VALUES (4, 7, '2008-09-04', 'spayed') ON CONFLICT (id) DO NOTHING; |
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