Skip to content

Commit

Permalink
removed unnecessary uuid for vet_specialties
Browse files Browse the repository at this point in the history
  • Loading branch information
mosbat committed Sep 26, 2024
1 parent b725d7c commit 180f67a
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 17 deletions.
4 changes: 4 additions & 0 deletions src/main/resources/db/h2/schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,12 @@ ALTER TABLE vet_specialties ADD CONSTRAINT fk_vet_specialties_specialties FOREIG

CREATE TABLE types (
id INTEGER GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY,
uuid UUID DEFAULT RANDOM_UUID() NOT NULL UNIQUE, -- Added UUID
name VARCHAR(80)
);
CREATE INDEX types_name ON types (name);

-- Add UUID to owners table
CREATE TABLE owners (
id INTEGER GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY,
uuid UUID DEFAULT RANDOM_UUID() NOT NULL UNIQUE, -- Added UUID
Expand All @@ -46,6 +48,7 @@ CREATE TABLE owners (
);
CREATE INDEX owners_last_name ON owners (last_name);

-- Add UUID to pets table
CREATE TABLE pets (
id INTEGER GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY,
uuid UUID DEFAULT RANDOM_UUID() NOT NULL UNIQUE, -- Added UUID
Expand All @@ -58,6 +61,7 @@ ALTER TABLE pets ADD CONSTRAINT fk_pets_owners FOREIGN KEY (owner_id) REFERENCES
ALTER TABLE pets ADD CONSTRAINT fk_pets_types FOREIGN KEY (type_id) REFERENCES types (id);
CREATE INDEX pets_name ON pets (name);

-- Add UUID to visits table
CREATE TABLE visits (
id INTEGER GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY,
uuid UUID DEFAULT RANDOM_UUID() NOT NULL UNIQUE, -- Added UUID
Expand Down
10 changes: 5 additions & 5 deletions src/main/resources/db/mysql/data.sql
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ INSERT IGNORE INTO specialties (id, name, uuid) VALUES (1, 'radiology', '0a6d743
INSERT IGNORE INTO specialties (id, name, uuid) VALUES (2, 'surgery', 'e3a10a00-4567-4c98-89ba-d7bb3e9a999a');
INSERT IGNORE INTO specialties (id, name, uuid) VALUES (3, 'dentistry', '1a78df21-5678-4b5a-ae13-88f72065b4b1');

INSERT IGNORE INTO vet_specialties (vet_id, specialty_id, uuid) VALUES (2, 1, 'ecb2f7b9-789a-4d2e-8c6b-51254c3f9d2c');
INSERT IGNORE INTO vet_specialties (vet_id, specialty_id, uuid) VALUES (3, 2, '1f91f6b9-890b-4e6f-92c7-98254a5e3d42');
INSERT IGNORE INTO vet_specialties (vet_id, specialty_id, uuid) VALUES (3, 3, '6c023456-9b5b-40d1-96fc-d3543b6e5f24');
INSERT IGNORE INTO vet_specialties (vet_id, specialty_id, uuid) VALUES (4, 2, '74ab9db9-9bfc-44b1-897c-54f35c2c4f65');
INSERT IGNORE INTO vet_specialties (vet_id, specialty_id, uuid) VALUES (5, 1, '59ba1d9e-123c-4c3b-bc78-9e44efc1a523');
INSERT IGNORE INTO vet_specialties (vet_id, specialty_id, uuid) VALUES (2, 1);
INSERT IGNORE INTO vet_specialties (vet_id, specialty_id, uuid) VALUES (3, 2);
INSERT IGNORE INTO vet_specialties (vet_id, specialty_id, uuid) VALUES (3, 3);
INSERT IGNORE INTO vet_specialties (vet_id, specialty_id, uuid) VALUES (4, 2);
INSERT IGNORE INTO vet_specialties (vet_id, specialty_id, uuid) VALUES (5, 1);

INSERT IGNORE INTO types (id, name, uuid) VALUES (1, 'cat', '9a7b1789-5678-4c23-b90c-ef3f82c3bcde');
INSERT IGNORE INTO types (id, name, uuid) VALUES (2, 'dog', '3b8a2a12-4567-4c56-bb12-d3b50efc23b2');
Expand Down
1 change: 0 additions & 1 deletion src/main/resources/db/mysql/schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ CREATE TABLE IF NOT EXISTS specialties (

CREATE TABLE IF NOT EXISTS vet_specialties (
vet_id INT(4) UNSIGNED NOT NULL,
uuid CHAR(36) NOT NULL DEFAULT (UUID()) UNIQUE,
specialty_id INT(4) UNSIGNED NOT NULL,
FOREIGN KEY (vet_id) REFERENCES vets(id),
FOREIGN KEY (specialty_id) REFERENCES specialties(id),
Expand Down
20 changes: 10 additions & 10 deletions src/main/resources/db/postgres/data.sql
Original file line number Diff line number Diff line change
Expand Up @@ -34,24 +34,24 @@ INSERT INTO specialties (name, uuid)
SELECT 'dentistry', gen_random_uuid()
WHERE NOT EXISTS (SELECT * FROM specialties WHERE name='dentistry');

INSERT INTO vet_specialties (vet_id, specialty_id, uuid)
VALUES (2, 1, gen_random_uuid())
INSERT INTO vet_specialties (vet_id, specialty_id)
VALUES (2, 1)
ON CONFLICT (vet_id, specialty_id) DO NOTHING;

INSERT INTO vet_specialties (vet_id, specialty_id, uuid)
VALUES (3, 2, gen_random_uuid())
INSERT INTO vet_specialties (vet_id, specialty_id)
VALUES (3, 2)
ON CONFLICT (vet_id, specialty_id) DO NOTHING;

INSERT INTO vet_specialties (vet_id, specialty_id, uuid)
VALUES (3, 3, gen_random_uuid())
INSERT INTO vet_specialties (vet_id, specialty_id)
VALUES (3, 3)
ON CONFLICT (vet_id, specialty_id) DO NOTHING;

INSERT INTO vet_specialties (vet_id, specialty_id, uuid)
VALUES (4, 2, gen_random_uuid())
INSERT INTO vet_specialties (vet_id, specialty_id)
VALUES (4, 2)
ON CONFLICT (vet_id, specialty_id) DO NOTHING;

INSERT INTO vet_specialties (vet_id, specialty_id, uuid)
VALUES (5, 1, gen_random_uuid())
INSERT INTO vet_specialties (vet_id, specialty_id)
VALUES (5, 1)
ON CONFLICT (vet_id, specialty_id) DO NOTHING;

INSERT INTO types (name, uuid)
Expand Down
1 change: 0 additions & 1 deletion src/main/resources/db/postgres/schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ CREATE INDEX ON specialties (name);
CREATE TABLE IF NOT EXISTS vet_specialties (
vet_id INT NOT NULL REFERENCES vets (id),
specialty_id INT NOT NULL REFERENCES specialties (id),
uuid UUID DEFAULT gen_random_uuid() UNIQUE,
UNIQUE (vet_id, specialty_id)
);

Expand Down

0 comments on commit 180f67a

Please sign in to comment.