Skip to content

Commit

Permalink
Flyway and helper dependecies (#21)
Browse files Browse the repository at this point in the history
* add flyway; lombok, mapper dependencies

* create db structure in migration

* remove redudant credentials from build.gradle
  • Loading branch information
FHToE authored Nov 4, 2020
1 parent a88f3dc commit 5daed2a
Show file tree
Hide file tree
Showing 3 changed files with 233 additions and 1 deletion.
9 changes: 9 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,19 @@ repositories {
}

dependencies {
def mapstruct = "1.3.1.Final"

implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'org.flywaydb:flyway-core'
implementation "org.mapstruct:mapstruct:${mapstruct}"
annotationProcessor "org.mapstruct:mapstruct-processor:${mapstruct}"
testAnnotationProcessor "org.mapstruct:mapstruct-processor:${mapstruct}"

implementation 'io.springfox:springfox-boot-starter:3.0.0'
runtimeOnly 'org.postgresql:postgresql'

testImplementation "com.h2database:h2"
testImplementation('org.springframework.boot:spring-boot-starter-test') {
exclude group: 'org.junit.vintage', module: 'junit-vintage-engine'
}
Expand Down
6 changes: 5 additions & 1 deletion src/main/resources/application.properties
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
#-------------------------
# Database PostgresSQL
#-------------------------
spring.datasource.driver-class-name=org.postgresql.Driver
spring.datasource.url=${DATASOURCE_URL:jdbc:postgresql://localhost:5432/dokazovi}
spring.datasource.username=${DATASOURCE_USER:dokazovi}
spring.datasource.password=${DATASOURCE_PASSWORD:dokazovi}
info.build.version=${BUILD_VERSION:0.0.0}
spring.jackson.serialization.fail-on-empty-beans=false

logging.level.io.swagger.models.parameters.AbstractSerializableParameter=ERROR
logging.level.io.swagger.models.parameters.AbstractSerializableParameter=ERROR
219 changes: 219 additions & 0 deletions src/main/resources/db/migration/V1__init_db.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,219 @@
SET statement_timeout = 0;
SET lock_timeout = 0;
SET idle_in_transaction_session_timeout = 0;
SET client_encoding = 'UTF8';
SET standard_conforming_strings = on;
SELECT pg_catalog.set_config('search_path', '', false);
SET check_function_bodies = false;
SET xmloption = content;
SET client_min_messages = warning;
SET row_security = off;

SET default_tablespace = '';

SET default_table_access_method = heap;

CREATE TYPE public.post_status AS ENUM (
'draft',
'moderation_first_sign',
'moderation_second_sign',
'published',
'archived'
);

ALTER TYPE public.post_status OWNER TO dokazovi;

CREATE TYPE public.source_type AS ENUM (
'profile_image',
'post_image',
'post_video'
);

ALTER TYPE public.source_type OWNER TO dokazovi;

CREATE TYPE public.user_status AS ENUM (
'new',
'active',
'deleted'
);

ALTER TYPE public.user_status OWNER TO dokazovi;

CREATE TABLE public.users (
"user_id" SERIAL PRIMARY KEY,
"email" varchar,
"password" varchar,
"status" public.user_status,
"first_name" varchar,
"last_name" varchar,
"qualification" varchar,
"phone" varchar,
"bio" text,
"created_at" TIMESTAMP DEFAULT (now())
);

ALTER TABLE public.users OWNER TO dokazovi;

CREATE TABLE public.roles (
"role_id" SERIAL PRIMARY KEY,
"role_name" varchar
);

ALTER TABLE public.roles OWNER TO dokazovi;

CREATE TABLE public.roles_users (
"role_id" int,
"user_id" int
);

ALTER TABLE public.roles_users OWNER TO dokazovi;

CREATE TABLE public.regions (
"region_id" SERIAL PRIMARY KEY,
"name" varchar
);

ALTER TABLE public.regions OWNER TO dokazovi;

CREATE TABLE public.institutions (
"institution_id" SERIAL PRIMARY KEY,
"name" varchar,
"region_id" int,
"address" varchar
);

ALTER TABLE public.institutions OWNER TO dokazovi;

CREATE TABLE public.users_institutions (
"user_id" int,
"institution_id" int,
"is_primary" boolean
);

ALTER TABLE public.users_institutions OWNER TO dokazovi;

CREATE TABLE public.tags (
"tag_id" SERIAL PRIMARY KEY,
"tag" varchar
);

ALTER TABLE public.tags OWNER TO dokazovi;

CREATE TABLE public.posts_tags (
"post_id" int,
"tag_id" int
);

ALTER TABLE public.posts_tags OWNER TO dokazovi;

CREATE TABLE public.posts (
"post_id" SERIAL PRIMARY KEY,
"author_id" int,
"direction_id" int,
"type_id" int,
"title" varchar,
"content" text,
"status" public.post_status,
"important" boolean,
"tags" varchar,
"created_at" TIMESTAMP DEFAULT (now()),
"modified_at" TIMESTAMP DEFAULT (now())
);

ALTER TABLE public.posts OWNER TO dokazovi;

CREATE TABLE public.charities (
"charity_id" SERIAL PRIMARY KEY,
"body" text,
"author_id" INT,
"created_at" TIMESTAMP DEFAULT (now()),
"modified_at" TIMESTAMP DEFAULT (now())
);

ALTER TABLE public.charities OWNER TO dokazovi;

CREATE TABLE public.sources (
"source_id" SERIAL PRIMARY KEY,
"type" public.source_type,
"value" varchar
);

ALTER TABLE public.sources OWNER TO dokazovi;

CREATE TABLE public.users_sources (
"user_id" int,
"source_id" int
);

ALTER TABLE public.users_sources OWNER TO dokazovi;

CREATE TABLE public.posts_sources (
"post_id" int,
"source_id" int
);

ALTER TABLE public.posts_sources OWNER TO dokazovi;

CREATE TABLE public.users_directions (
"user_id" int,
"direction_id" int
);

ALTER TABLE public.users_directions OWNER TO dokazovi;

CREATE TABLE public.directions (
"direction_id" SERIAL PRIMARY KEY,
"name" varchar
);

ALTER TABLE public.directions OWNER TO dokazovi;

CREATE TABLE public.posts_directions (
"post_id" int,
"direction_id" int
);

ALTER TABLE public.posts_directions OWNER TO dokazovi;

CREATE TABLE public.post_types (
"type_id" SERIAL PRIMARY KEY,
"name" varchar
);

ALTER TABLE public.post_types OWNER TO dokazovi;

ALTER TABLE public.roles_users ADD FOREIGN KEY (role_id) REFERENCES public.roles(role_id);

ALTER TABLE public.roles_users ADD FOREIGN KEY (user_id) REFERENCES public.users(user_id);

ALTER TABLE public.institutions ADD FOREIGN KEY (region_id) REFERENCES public.regions(region_id);

ALTER TABLE public.users_institutions ADD FOREIGN KEY (user_id) REFERENCES public.users (user_id);

ALTER TABLE public.users_institutions ADD FOREIGN KEY (institution_id) REFERENCES public.institutions (institution_id);

ALTER TABLE public.posts_tags ADD FOREIGN KEY (post_id) REFERENCES public.posts (post_id);

ALTER TABLE public.posts_tags ADD FOREIGN KEY (tag_id) REFERENCES public.tags (tag_id);

ALTER TABLE public.posts ADD FOREIGN KEY (author_id) REFERENCES public.users (user_id);

ALTER TABLE public.posts ADD FOREIGN KEY (type_id) REFERENCES public.post_types (type_id);

ALTER TABLE public.charities ADD FOREIGN KEY (author_id) REFERENCES public.users (user_id);

ALTER TABLE public.users_sources ADD FOREIGN KEY (user_id) REFERENCES public.users (user_id);

ALTER TABLE public.users_sources ADD FOREIGN KEY (source_id) REFERENCES public.sources (source_id);

ALTER TABLE public.posts_sources ADD FOREIGN KEY (post_id) REFERENCES public.posts (post_id);

ALTER TABLE public.posts_sources ADD FOREIGN KEY (source_id) REFERENCES public.sources (source_id);

ALTER TABLE public.users_directions ADD FOREIGN KEY (user_id) REFERENCES public.users (user_id);

ALTER TABLE public.users_directions ADD FOREIGN KEY (direction_id) REFERENCES public.directions (direction_id);

ALTER TABLE public.posts_directions ADD FOREIGN KEY (post_id) REFERENCES public.posts (post_id);

ALTER TABLE public.posts_directions ADD FOREIGN KEY (direction_id) REFERENCES public.directions (direction_id);

0 comments on commit 5daed2a

Please sign in to comment.