Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature: create a mock data script for db #93

Merged
merged 1 commit into from
Dec 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
1 change: 1 addition & 0 deletions database/scripts/120_create_tables.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions database/scripts/500_insert_dictionaries.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
68 changes: 68 additions & 0 deletions database/scripts/510_insert_mock_data.sql
Original file line number Diff line number Diff line change
@@ -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;
Loading