Skip to content

Commit

Permalink
db: created additional files and changed users
Browse files Browse the repository at this point in the history
  • Loading branch information
rogacky11 committed Mar 21, 2024
1 parent dc937ed commit 98bb97e
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 37 deletions.
6 changes: 5 additions & 1 deletion docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ services:
networks:
- reasn-network
volumes:
- ./init.sql:/docker-entrypoint-initdb.d/init.sql
- ./initusers.sql:/docker-entrypoint-initdb.d/02_init.sql
- ./init.sql:/docker-entrypoint-initdb.d/01_init.sql
- ./initdata.sql:/docker-entrypoint-initdb.d/03_init.sql
- postgres-data:/var/lib/postgresql/data
env_file:
- .env
Expand All @@ -31,3 +33,5 @@ networks:
volumes:
postgres-data:
pgadmin-data:


39 changes: 3 additions & 36 deletions init.sql
Original file line number Diff line number Diff line change
@@ -1,11 +1,3 @@
CREATE ROLE admin_user WITH LOGIN PASSWORD 'admin_password' SUPERUSER;

CREATE ROLE readonly_user WITH LOGIN PASSWORD 'readonly_password';

GRANT CONNECT ON DATABASE reasn TO readonly_user;
GRANT USAGE ON SCHEMA public TO readonly_user;
GRANT SELECT ON ALL TABLES IN SCHEMA public TO readonly_user;

CREATE TABLE IF NOT EXISTS "event" (
"id" integer PRIMARY KEY,
"name" varchar,
Expand Down Expand Up @@ -114,10 +106,7 @@ CREATE TABLE IF NOT EXISTS "interest" (
"level" integer
);

CREATE TABLE IF NOT EXISTS "xddd" (
"id" integer
);


ALTER TABLE "user" ADD FOREIGN KEY ("role_id") REFERENCES "role" ("id");

ALTER TABLE "event" ADD FOREIGN KEY ("address_id") REFERENCES "address" ("id");
Expand Down Expand Up @@ -158,6 +147,7 @@ ALTER TABLE "event" ADD FOREIGN KEY ("status_id") REFERENCES "status" ("id");

ALTER TABLE "user_interest" ADD FOREIGN KEY ("interest_id") REFERENCES "interest" ("id");


INSERT INTO "role" ("id", "role") VALUES
(1, 'System Analyst'),
(2, 'Project Manager');
Expand All @@ -182,10 +172,7 @@ INSERT INTO "event" ("id", "name", "address_id", "description", "organizer_id",
(1, 'Tech Conference', 1, 'Annual tech conference', 1, '2023-10-01 09:00:00', '2023-10-02 17:00:00', '2023-09-01 08:00:00', '2023-09-01 08:00:00', 'tech-conference', 1),
(2, 'Health Symposium', 2, 'Health and wellness symposium', 2, '2023-11-05 09:00:00', '2023-11-06 17:00:00', '2023-10-05 08:00:00', '2023-10-05 08:00:00', 'health-symposium', 2);


INSERT INTO "participant" ("id", "event_id", "user_id", "status_id") VALUES
(1, 1, 1, 1),
(2, 2, 2, 2);



-- Insert data into "tag"
Expand All @@ -196,23 +183,3 @@ INSERT INTO "tag" ("id", "name") VALUES
INSERT INTO "event_tag" ("event_id", "tag_id") VALUES
(1, 1),
(2, 2);

INSERT INTO "parameter" ("id", "key", "value") VALUES
(1, 'Location', 'Virtual'),
(2, 'SpeakerCount', '5');

INSERT INTO "event_parameter" ("parameter_id", "event_id") VALUES
(1, 1),
(2, 2);

INSERT INTO "comment" ("id", "event_id", "content", "created_at", "user_id") VALUES
(1, 1, 'Looking forward to this!', '2023-09-10', 1),
(2, 2, 'Cant wait to attend!', '2023-10-15', 2);

INSERT INTO "interest" ("id", "name", "level") VALUES
(1, 'Programming', 5),
(2, 'Reading', 4);

INSERT INTO "user_interest" ("user_id", "interest_id") VALUES
(1, 1),
(2, 2);
23 changes: 23 additions & 0 deletions initdata.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
INSERT INTO "participant" ("id", "event_id", "user_id", "status_id") VALUES
(1, 1, 1, 1),
(2, 2, 2, 2);

INSERT INTO "parameter" ("id", "key", "value") VALUES
(1, 'Location', 'Virtual'),
(2, 'SpeakerCount', '5');

INSERT INTO "event_parameter" ("parameter_id", "event_id") VALUES
(1, 1),
(2, 2);

INSERT INTO "comment" ("id", "event_id", "content", "created_at", "user_id") VALUES
(1, 1, 'Looking forward to this!', '2023-09-10', 1),
(2, 2, 'Cant wait to attend!', '2023-10-15', 2);

INSERT INTO "interest" ("id", "name", "level") VALUES
(1, 'Programming', 5),
(2, 'Reading', 4);

INSERT INTO "user_interest" ("user_id", "interest_id") VALUES
(1, 1),
(2, 2);
15 changes: 15 additions & 0 deletions initusers.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
CREATE ROLE admindb WITH LOGIN PASSWORD 'admin_password';

GRANT CONNECT ON DATABASE reasn TO admindb;
GRANT USAGE ON SCHEMA public TO admindb;
GRANT INSERT, SELECT, UPDATE, DELETE ON ALL TABLES IN SCHEMA public TO admindb;
REVOKE ALL ON event_parameter, event_tag, user_interest FROM admindb;


CREATE ROLE userdb WITH LOGIN PASSWORD 'user_password';

GRANT CONNECT ON DATABASE reasn TO userdb;
GRANT SELECT ON ALL TABLES IN SCHEMA public TO userdb;
GRANT SELECT, UPDATE, INSERT, DELETE ON comment, event, address, interest TO userdb;
GRANT SELECT, UPDATE, INSERT ("name", surname, username, "password", email, phone) ON "user" TO userdb

0 comments on commit 98bb97e

Please sign in to comment.