From 31bbd88c63d9dabb63692fae120f65746a8ab8a2 Mon Sep 17 00:00:00 2001 From: KinTrae Date: Sun, 29 Dec 2024 20:56:32 +0100 Subject: [PATCH] feature: create a mock data script for db and alter post_picture column to add picture_index Task: 8697882t7 --- README.md | 4 +- .../backend/posts/models/PostPicture.java | 4 ++ .../meowhub/backend/InitDataTestConfig.java | 1 + database/scripts/120_create_tables.sql | 1 + database/scripts/500_insert_dictionaries.sql | 4 +- database/scripts/510_insert_mock_data.sql | 68 +++++++++++++++++++ 6 files changed, 79 insertions(+), 3 deletions(-) create mode 100644 database/scripts/510_insert_mock_data.sql diff --git a/README.md b/README.md index 01d6cef..1e4ed44 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,9 @@ Engineering Thesis ## Database For production environment, you need to have an oracle database. -If you don't have a created an oracle database yet, run script `database/install.sql`. +If you didn't create oracle database yet, run script `database/install.sql`. +(run the application to instatiate mock users via SecurityConfig) +For mock data, run script `database/scripts/510_insert_mock_data.sql` on your database - as it is not included in `install.sql` script. ## Profiles diff --git a/backend/src/main/java/meowhub/backend/posts/models/PostPicture.java b/backend/src/main/java/meowhub/backend/posts/models/PostPicture.java index 5b802eb..d609898 100644 --- a/backend/src/main/java/meowhub/backend/posts/models/PostPicture.java +++ b/backend/src/main/java/meowhub/backend/posts/models/PostPicture.java @@ -42,6 +42,10 @@ public class PostPicture { @JoinColumn(name = "PICTURE_ID", nullable = false) private Picture picture; + @NotNull + @Column(name = "PICTURE_INDEX", nullable = false) + private Long index; + @Column(name = "CREATED_AT") private LocalDateTime createdAt; diff --git a/backend/src/test/java/meowhub/backend/InitDataTestConfig.java b/backend/src/test/java/meowhub/backend/InitDataTestConfig.java index 3242f18..66984f5 100644 --- a/backend/src/test/java/meowhub/backend/InitDataTestConfig.java +++ b/backend/src/test/java/meowhub/backend/InitDataTestConfig.java @@ -163,6 +163,7 @@ private void initPosts() { PostPicture postPicture = new PostPicture(); postPicture.setPicture(picture); postPicture.setPost(post3); + postPicture.setIndex(0L); postPictureRepository.save(postPicture); Comment comment1 = new Comment(); diff --git a/database/scripts/120_create_tables.sql b/database/scripts/120_create_tables.sql index 771686e..4de168d 100644 --- a/database/scripts/120_create_tables.sql +++ b/database/scripts/120_create_tables.sql @@ -52,6 +52,7 @@ CREATE TABLE mh_posts.Post_Pictures id varchar2(36) DEFAULT sys_guid() NOT NULL, post_id varchar2(36) NOT NULL, picture_id varchar2(36) NOT NULL, + picture_index number NOT NULL, created_at date NOT NULL, created_by varchar2(36) NOT NULL, modified_at date NULL, diff --git a/database/scripts/500_insert_dictionaries.sql b/database/scripts/500_insert_dictionaries.sql index 8595e98..587514c 100644 --- a/database/scripts/500_insert_dictionaries.sql +++ b/database/scripts/500_insert_dictionaries.sql @@ -2,8 +2,8 @@ ---------------------------------------- || MH_USERS SCHEMA || ---------------------------------------- -- table: mh_users.roles -INSERT INTO mh_users.roles (code, description) VALUES ('USER_ROLE', 'Regular user role with basic permissions'); -INSERT INTO mh_users.roles (code, description) VALUES ('ADMIN_ROLE', 'Admin role with all permissions'); +INSERT INTO mh_users.roles (code, description) VALUES ('ROLE_USER', 'Regular user role with basic permissions'); +INSERT INTO mh_users.roles (code, description) VALUES ('ROLE_ADMIN', 'Admin role with all permissions'); -- table: mh_users.genders INSERT INTO mh_users.genders (code) VALUES ('FEMALE'); diff --git a/database/scripts/510_insert_mock_data.sql b/database/scripts/510_insert_mock_data.sql new file mode 100644 index 0000000..7da419c --- /dev/null +++ b/database/scripts/510_insert_mock_data.sql @@ -0,0 +1,68 @@ + +DECLARE + l_user_id VARCHAR2(36); + l_admin_id VARCHAR2(36); + l_relation_type_friends_id VARCHAR2(36); +BEGIN + --get needed id's + + SELECT id + INTO l_user_id + FROM mh_users.users + WHERE login = 'user1'; + + SELECT id + INTO l_admin_id + FROM mh_users.users + WHERE login = 'admin'; + + SELECT id + INTO l_relation_type_friends_id + FROM mh_user_relations.relation_types + WHERE code = 'FRIENDS'; + +--mh_users.pictures + INSERT INTO mh_users.pictures (id, user_id, picture) + VALUES (1, l_user_id, UTL_RAW.CAST_TO_RAW('9ffdc87faedbe...b27777ce')); -- Skrócona treść pliku + + INSERT INTO mh_users.pictures (id, user_id, picture) + VALUES (2, l_admin_id, UTL_RAW.CAST_TO_RAW('1ffdc87faedbe...b27777ce')); -- Skrócona treść pliku + +--mh_posts.posts + INSERT INTO mh_posts.posts (id, user_id, content_html) VALUES (1, l_user_id, 'Hello world from user - 1'); + INSERT INTO mh_posts.posts (id, user_id, content_html) VALUES (2, l_admin_id, 'Hello world from admin - 1'); + INSERT INTO mh_posts.posts (id, user_id, content_html) VALUES (3, l_admin_id, 'Hello world from admin - 2'); + +--mh_posts.post_pictures + INSERT INTO mh_posts.post_pictures (id, post_id, picture_id, picture_index) VALUES (1, 1, 1, 0); + +--mh_posts.comments + INSERT INTO mh_posts.comments (id, post_id, user_id, answered_comment_id, content) VALUES (1, 3, l_user_id, NULL, 'Nice post'); + INSERT INTO mh_posts.comments (id, post_id, user_id, answered_comment_id, content) VALUES (2, 3, l_user_id, 1, 'Yeah, I agree'); + +--mh_profiles.profiles + INSERT INTO mh_profiles.profiles (id, user_id, profile_details_html) VALUES (1, l_user_id, 'Hello this is my profile'); + INSERT INTO mh_profiles.profiles (id, user_id, profile_details_html) VALUES (2, l_admin_id, 'ADMIN is my name, and this is my profile:D'); + + +--mh_profiles.profile_pictures + INSERT INTO mh_profiles.profile_pictures (id, profile_id, picture_id, picture_index) VALUES (1, 2, 2, 0); + +--mh_profiles.profile_data + INSERT INTO mh_profiles.profile_data (id, code) VALUES (1, 'Urodzony w:'); + INSERT INTO mh_profiles.profile_data (id, code) VALUES (2, 'W relacji:'); + +--mh_profiles.profile_user_data + INSERT INTO mh_profiles.profile_user_data (id, profile_id, profile_data_id, content) + VALUES (1, 1, 1, 'Warszawa'); + + INSERT INTO mh_profiles.profile_user_data (id, profile_id, profile_data_id, content) + VALUES (2, 1, 1, 'Wolny'); + +--mh_user_relations.user_relations + INSERT INTO mh_user_relations.user_relations (id, sender_id, receiver_id, relation_type_id, send_date) + VALUES (1, l_user_id, l_admin_id, l_relation_type_friends_id, TO_TIMESTAMP('2024-12-29 12:00:00', 'YYYY-MM-DD HH24:MI:SS')); + + COMMIT; + +END;