From edc9fb80b94b7a92a4b15720b226a787b9836a65 Mon Sep 17 00:00:00 2001 From: Danila Mororozv Date: Fri, 12 Feb 2021 18:47:11 +0300 Subject: [PATCH] add flyway migration-v1; add hibernate mapping --- backend_module/Docker-compose.yml | 34 ++++---- backend_module/pom.xml | 19 ++++- .../backend_module/model/DatePoint.java | 80 +++++++++++++++++++ .../natlex/backend_module/model/Point.java | 63 +++++++++++++++ .../com/natlex/backend_module/model/User.java | 59 ++++++++++++++ .../src/main/resources/application.properties | 5 ++ .../db/migration/V0001__Create_tables.sql | 20 +++++ 7 files changed, 262 insertions(+), 18 deletions(-) create mode 100644 backend_module/src/main/java/com/natlex/backend_module/model/DatePoint.java create mode 100644 backend_module/src/main/java/com/natlex/backend_module/model/Point.java create mode 100644 backend_module/src/main/java/com/natlex/backend_module/model/User.java create mode 100644 backend_module/src/main/resources/db/migration/V0001__Create_tables.sql diff --git a/backend_module/Docker-compose.yml b/backend_module/Docker-compose.yml index 1c16450..0296bed 100644 --- a/backend_module/Docker-compose.yml +++ b/backend_module/Docker-compose.yml @@ -1,27 +1,31 @@ version: '3.5' +networks: + lan: + driver: bridge services: - mysql: + docker-mysql: image: mysql:8 + command: --default-authentication-plugin=mysql_native_password restart: always - hostname: localhost ports: - - 5432:5432 + - '3308:3306' + volumes: + - mysql-data:/var/lib/mysql environment: - MYSQL_ROOT_PASSWORD: rootpass - MYSQL_USER: testuser - MYSQL_PASSWORD: testpass - MYSQL_DB: teste - server: + MYSQL_ROOT_PASSWORD: password + MYSQL_DATABASE: test_db + MYSQL_USER: root + MYSQL_PASSWORD: password + networks: + - lan + docker-server: image: spring-mysql build: context: ./ dockerfile: Dockerfile + networks: + - lan depends_on: - - mysql + - docker-mysql ports: - - 8080:8080 - environment: - - DATABASE_HOST=localhost - - DATABASE_USER=testuser - - DATABASE_NAME=teste - - DATABASE_PORT=5432 + - '8091:8091' diff --git a/backend_module/pom.xml b/backend_module/pom.xml index 773914f..0c24971 100644 --- a/backend_module/pom.xml +++ b/backend_module/pom.xml @@ -21,11 +21,11 @@ org.springframework.boot - spring-boot-starter-web + spring-boot-starter-data-jpa - org.flywaydb - flyway-core + org.springframework.boot + spring-boot-starter-web @@ -33,6 +33,19 @@ mysql-connector-java runtime + + + org.flywaydb + flyway-core + 5.2.4 + + + + org.projectlombok + lombok + true + + org.springframework.boot spring-boot-starter-test diff --git a/backend_module/src/main/java/com/natlex/backend_module/model/DatePoint.java b/backend_module/src/main/java/com/natlex/backend_module/model/DatePoint.java new file mode 100644 index 0000000..0c05235 --- /dev/null +++ b/backend_module/src/main/java/com/natlex/backend_module/model/DatePoint.java @@ -0,0 +1,80 @@ +package com.natlex.backend_module.model; + +import javax.persistence.*; +import java.util.Date; + +@Entity +@Table (name = "DatePoint") +public class DatePoint { + + @Id + @GeneratedValue(strategy = GenerationType.AUTO) + @Column(nullable = false) + private Long id; + + private String description; + private String photo; + private Date date; + private String links; + private Long point_id; + + public DatePoint(Long id, String description, String photo, Date date, String links, Long point_id) { + this.id = id; + this.description = description; + this.photo = photo; + this.date = date; + this.links = links; + this.point_id = point_id; + } + + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + + public String getDescription() { + return description; + } + + public void setDescription(String description) { + this.description = description; + } + + public String getPhoto() { + return photo; + } + + public void setPhoto(String photo) { + this.photo = photo; + } + + public Date getDate() { + return date; + } + + public void setDate(Date date) { + this.date = date; + } + + public String getLinks() { + return links; + } + + public void setLinks(String links) { + this.links = links; + } + + public Long getPoint_id() { + return point_id; + } + + public void setPoint_id(Long point_id) { + this.point_id = point_id; + } + + public DatePoint() { + } +} diff --git a/backend_module/src/main/java/com/natlex/backend_module/model/Point.java b/backend_module/src/main/java/com/natlex/backend_module/model/Point.java new file mode 100644 index 0000000..02c51e1 --- /dev/null +++ b/backend_module/src/main/java/com/natlex/backend_module/model/Point.java @@ -0,0 +1,63 @@ +package com.natlex.backend_module.model; + +import javax.persistence.*; + +@Entity + +@Table (name = "Point") +public class Point { + + @Id + @GeneratedValue(strategy = GenerationType.AUTO) + @Column(nullable = false) + private Long id; + + @Column(name = "coordinates", nullable = false) + private org.springframework.data.geo.Point coordinates; + + private int count; + private String adress; + + public Point() { + } + + public Point(Long id, org.springframework.data.geo.Point coordinates, int count, String adress) { + this.id = id; + this.coordinates = coordinates; + this.count = count; + this.adress = adress; + } + + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + + public org.springframework.data.geo.Point getCoordinates() { + return coordinates; + } + + public void setCoordinates(org.springframework.data.geo.Point coordinates) { + this.coordinates = coordinates; + } + + public int getCount() { + return count; + } + + public void setCount(int count) { + this.count = count; + } + + public String getAdress() { + return adress; + } + + public void setAdress(String adress) { + this.adress = adress; + } + +} diff --git a/backend_module/src/main/java/com/natlex/backend_module/model/User.java b/backend_module/src/main/java/com/natlex/backend_module/model/User.java new file mode 100644 index 0000000..2c35b80 --- /dev/null +++ b/backend_module/src/main/java/com/natlex/backend_module/model/User.java @@ -0,0 +1,59 @@ +package com.natlex.backend_module.model; + +import javax.persistence.*; + +@Entity +@Table (name = "User") +public class User { + + @Id + @GeneratedValue(strategy = GenerationType.AUTO) + @Column(nullable = false) + private Long id; + + private String email; + private boolean inAdmin; + private String authData; + + public User() { + } + + public User(Long id, String email, boolean inAdmin, String authData) { + this.id = id; + this.email = email; + this.inAdmin = inAdmin; + this.authData = authData; + } + + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + + public String getEmail() { + return email; + } + + public void setEmail(String email) { + this.email = email; + } + + public boolean isInAdmin() { + return inAdmin; + } + + public void setInAdmin(boolean inAdmin) { + this.inAdmin = inAdmin; + } + + public String getAuthData() { + return authData; + } + + public void setAuthData(String authData) { + this.authData = authData; + } +} diff --git a/backend_module/src/main/resources/application.properties b/backend_module/src/main/resources/application.properties index 8b13789..2a011d9 100644 --- a/backend_module/src/main/resources/application.properties +++ b/backend_module/src/main/resources/application.properties @@ -1 +1,6 @@ +#spring.datasource.url=jdbc:mysql://docker-mysql:3308/test_db?createDatabaseIfNotExist=true&autoReconnect=true&useSSL=false +spring.datasource.username=root +spring.datasource.password=password +spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver +spring.datasource.url=jdbc:mysql://127.0.0.1:3306/test_db?serverTimezone=Europe/Moscow&autoReconnect=true&useSSL=false diff --git a/backend_module/src/main/resources/db/migration/V0001__Create_tables.sql b/backend_module/src/main/resources/db/migration/V0001__Create_tables.sql new file mode 100644 index 0000000..ee5c62a --- /dev/null +++ b/backend_module/src/main/resources/db/migration/V0001__Create_tables.sql @@ -0,0 +1,20 @@ +CREATE TABLE Point (id INT AUTO_INCREMENT NOT NULL, + coordinates POINT NOT NULL, + count INT, + adress VARCHAR(200), + PRIMARY KEY(id)); + +CREATE TABLE DatePoint (id INT AUTO_INCREMENT NOT NULL, + description VARCHAR(300), + photo VARCHAR(300), + date DATE, + links VARCHAR(200), + point_id INT, + PRIMARY KEY (id), + FOREIGN KEY (point_id) REFERENCES Point(id)); + +CREATE TABLE User (id INT AUTO_INCREMENT NOT NULL, + email VARCHAR(200), + inAdmin BOOL, + authData VARCHAR(300), + PRIMARY KEY (id)); \ No newline at end of file