diff --git a/polling-app-server/pom.xml b/polling-app-server/pom.xml
index 87339364..b77bca8b 100644
--- a/polling-app-server/pom.xml
+++ b/polling-app-server/pom.xml
@@ -68,6 +68,12 @@
spring-security-test
test
+
+
+ com.h2database
+ h2
+ runtime
+
diff --git a/polling-app-server/src/main/java/com/example/polls/config/SecurityConfig.java b/polling-app-server/src/main/java/com/example/polls/config/SecurityConfig.java
index 431fa64f..98c4d573 100644
--- a/polling-app-server/src/main/java/com/example/polls/config/SecurityConfig.java
+++ b/polling-app-server/src/main/java/com/example/polls/config/SecurityConfig.java
@@ -92,11 +92,14 @@ protected void configure(HttpSecurity http) throws Exception {
.permitAll()
.antMatchers(HttpMethod.GET, "/api/polls/**", "/api/users/**")
.permitAll()
+ .antMatchers("/h2-console/**")
+ .permitAll()
.anyRequest()
.authenticated();
// Add our custom JWT security filter
http.addFilterBefore(jwtAuthenticationFilter(), UsernamePasswordAuthenticationFilter.class);
-
+ // Allow H2-console
+ http.headers().frameOptions().sameOrigin();
}
}
\ No newline at end of file
diff --git a/polling-app-server/src/main/resources/application.properties b/polling-app-server/src/main/resources/application.properties
old mode 100644
new mode 100755
index 1863936e..cba388a7
--- a/polling-app-server/src/main/resources/application.properties
+++ b/polling-app-server/src/main/resources/application.properties
@@ -3,10 +3,11 @@ server.port= 8080
server.compression.enabled=true
## Spring DATASOURCE (DataSourceAutoConfiguration & DataSourceProperties)
-spring.datasource.url= jdbc:mysql://localhost:3306/polling_app?useSSL=false&serverTimezone=UTC&useLegacyDatetimeCode=false
-spring.datasource.username= root
-spring.datasource.password= callicoder
-
+# spring.datasource.url= jdbc:mysql://localhost:3306/polling_app?useSSL=false&serverTimezone=UTC&useLegacyDatetimeCode=false
+# spring.datasource.username= root
+# spring.datasource.password= callicoder
+# Enabling H2 Console
+spring.h2.console.enabled=true
## Hibernate Properties
# The SQL dialect makes Hibernate generate better SQL for the chosen database
@@ -18,6 +19,7 @@ logging.level.org.hibernate.SQL= DEBUG
# Initialize the datasource with available DDL and DML scripts
spring.datasource.initialization-mode=always
+#spring.datasource.data=classpath:/db/migration/V1__schema.sql,classpath:/db/migration/V2__default_roles.sql
## Jackson Properties
spring.jackson.serialization.WRITE_DATES_AS_TIMESTAMPS= false
diff --git a/polling-app-server/src/main/resources/data.sql b/polling-app-server/src/main/resources/data.sql
index 9d393b4c..1d970d4c 100644
--- a/polling-app-server/src/main/resources/data.sql
+++ b/polling-app-server/src/main/resources/data.sql
@@ -1,2 +1,4 @@
-INSERT IGNORE INTO roles(name) VALUES('ROLE_USER');
-INSERT IGNORE INTO roles(name) VALUES('ROLE_ADMIN');
\ No newline at end of file
+--INSERT IGNORE INTO roles(name) VALUES('ROLE_USER');
+--INSERT IGNORE INTO roles(name) VALUES('ROLE_ADMIN');
+INSERT INTO roles(name) VALUES('ROLE_USER');
+INSERT INTO roles(name) VALUES('ROLE_ADMIN');
\ No newline at end of file
diff --git a/polling-app-server/src/main/resources/db/migration/V1__schema.sql b/polling-app-server/src/main/resources/db/migration/V1__schema.sql
index 404b4f94..093bc718 100644
--- a/polling-app-server/src/main/resources/db/migration/V1__schema.sql
+++ b/polling-app-server/src/main/resources/db/migration/V1__schema.sql
@@ -1,3 +1,4 @@
+--DROP TABLE IF EXISTS `users`;
CREATE TABLE `users` (
`id` bigint(20) NOT NULL AUTO_INCREMENT,
`name` varchar(40) NOT NULL,
@@ -11,7 +12,7 @@ CREATE TABLE `users` (
UNIQUE KEY `uk_users_email` (`email`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
-
+--DROP TABLE IF EXISTS `roles`;
CREATE TABLE `roles` (
`id` bigint(20) NOT NULL AUTO_INCREMENT,
`name` varchar(60) NOT NULL,
@@ -19,17 +20,17 @@ CREATE TABLE `roles` (
UNIQUE KEY `uk_roles_name` (`name`)
) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8;
-
+--DROP TABLE IF EXISTS `user_roles`;
CREATE TABLE `user_roles` (
`user_id` bigint(20) NOT NULL,
`role_id` bigint(20) NOT NULL,
PRIMARY KEY (`user_id`,`role_id`),
- KEY `fk_user_roles_role_id` (`role_id`),
+-- KEY `fk_user_roles_role_id` (`role_id`),
CONSTRAINT `fk_user_roles_role_id` FOREIGN KEY (`role_id`) REFERENCES `roles` (`id`),
CONSTRAINT `fk_user_roles_user_id` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
-
+--DROP TABLE IF EXISTS `polls`;
CREATE TABLE `polls` (
`id` bigint(20) NOT NULL AUTO_INCREMENT,
`question` varchar(140) NOT NULL,
@@ -41,17 +42,17 @@ CREATE TABLE `polls` (
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
-
+--DROP TABLE IF EXISTS `choices`;
CREATE TABLE `choices` (
`id` bigint(20) NOT NULL AUTO_INCREMENT,
`text` varchar(40) NOT NULL,
`poll_id` bigint(20) NOT NULL,
PRIMARY KEY (`id`),
- KEY `fk_choices_poll_id` (`poll_id`),
+-- KEY `fk_choices_poll_id` (`poll_id`),
CONSTRAINT `fk_choices_poll_id` FOREIGN KEY (`poll_id`) REFERENCES `polls` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
-
+--DROP TABLE IF EXISTS `votes`;
CREATE TABLE `votes` (
`id` bigint(20) NOT NULL AUTO_INCREMENT,
`user_id` bigint(20) NOT NULL,
@@ -60,9 +61,9 @@ CREATE TABLE `votes` (
`created_at` timestamp DEFAULT CURRENT_TIMESTAMP,
`updated_at` timestamp DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY (`id`),
- KEY `fk_votes_user_id` (`user_id`),
- KEY `fk_votes_poll_id` (`poll_id`),
- KEY `fk_votes_choice_id` (`choice_id`),
+-- KEY `fk_votes_user_id` (`user_id`),
+-- KEY `fk_votes_poll_id` (`poll_id`),
+-- KEY `fk_votes_choice_id` (`choice_id`),
CONSTRAINT `fk_votes_user_id` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`),
CONSTRAINT `fk_votes_poll_id` FOREIGN KEY (`poll_id`) REFERENCES `polls` (`id`),
CONSTRAINT `fk_votes_choice_id` FOREIGN KEY (`choice_id`) REFERENCES `choices` (`id`)
diff --git a/polling-app-server/src/main/resources/db/migration/V2__default_roles.sql b/polling-app-server/src/main/resources/db/migration/V2__default_roles.sql
index 9d393b4c..1d970d4c 100644
--- a/polling-app-server/src/main/resources/db/migration/V2__default_roles.sql
+++ b/polling-app-server/src/main/resources/db/migration/V2__default_roles.sql
@@ -1,2 +1,4 @@
-INSERT IGNORE INTO roles(name) VALUES('ROLE_USER');
-INSERT IGNORE INTO roles(name) VALUES('ROLE_ADMIN');
\ No newline at end of file
+--INSERT IGNORE INTO roles(name) VALUES('ROLE_USER');
+--INSERT IGNORE INTO roles(name) VALUES('ROLE_ADMIN');
+INSERT INTO roles(name) VALUES('ROLE_USER');
+INSERT INTO roles(name) VALUES('ROLE_ADMIN');
\ No newline at end of file