Skip to content

Commit c3b3a42

Browse files
committed
Add db connection, migration and create tables user and station
1 parent 4998f6e commit c3b3a42

File tree

7 files changed

+162
-1
lines changed

7 files changed

+162
-1
lines changed

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,7 @@ build/
3131

3232
### VS Code ###
3333
.vscode/
34+
35+
### Fichier properties ###
36+
*.properties
37+
src/main/resources/application.properties

pom.xml

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,19 @@
5454
<artifactId>spring-boot-starter-test</artifactId>
5555
<scope>test</scope>
5656
</dependency>
57-
</dependencies>
57+
<dependency>
58+
<groupId>org.postgresql</groupId>
59+
<artifactId>postgresql</artifactId>
60+
</dependency>
61+
<dependency>
62+
<groupId>org.flywaydb</groupId>
63+
<artifactId>flyway-core</artifactId>
64+
</dependency>
65+
<dependency>
66+
<groupId>org.flywaydb</groupId>
67+
<artifactId>flyway-database-postgresql</artifactId>
68+
</dependency>
69+
</dependencies>
5870

5971
<build>
6072
<plugins>
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
package fr.host_dcode.vlib.model;
2+
3+
4+
import jakarta.persistence.Entity;
5+
import jakarta.persistence.GeneratedValue;
6+
import jakarta.persistence.GenerationType;
7+
import jakarta.persistence.Id;
8+
9+
import java.time.LocalDateTime;
10+
11+
@Entity
12+
public class Station {
13+
14+
@Id
15+
@GeneratedValue(strategy = GenerationType.AUTO)
16+
private int id;
17+
private String name;
18+
private String station_code;
19+
private double latitude;
20+
private double longitude;
21+
private String address;
22+
private String city;
23+
private String description;
24+
private LocalDateTime last_update;
25+
26+
27+
public Station(){}
28+
29+
public Station(String name, String stationCode, double latitude, double longitude, String description) {
30+
this.name = name;
31+
this.station_code = stationCode;
32+
this.latitude = latitude;
33+
this.longitude = longitude;
34+
this.description = description;
35+
}
36+
37+
public String getStationCode(){
38+
return this.station_code;
39+
}
40+
41+
public String getName(){
42+
return this.name;
43+
}
44+
45+
public void setName(String name){
46+
this.name = name;
47+
}
48+
49+
public String getDescription(){
50+
return this.description;
51+
}
52+
53+
public void setDescription(String description){
54+
this.description = description;
55+
}
56+
public Double getLatitude(){
57+
return this.latitude;
58+
}
59+
public Double getLongitude(){
60+
return this.longitude;
61+
}
62+
63+
public String getAddress(){
64+
return this.address;
65+
}
66+
67+
private void setAddress(String address){
68+
this.address = address;
69+
}
70+
71+
72+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
package fr.host_dcode.vlib.model;
2+
3+
public enum Status {
4+
User,
5+
Admin
6+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
package fr.host_dcode.vlib.model;
2+
3+
import jakarta.persistence.*;
4+
5+
import java.time.LocalDateTime;
6+
7+
@Entity
8+
@Table(name = "users")
9+
public class User {
10+
11+
@Id
12+
@GeneratedValue(strategy = GenerationType.AUTO)
13+
private int id;
14+
private String email;
15+
private String password;
16+
private Status status;
17+
private LocalDateTime created_at;
18+
19+
20+
public User(){}
21+
22+
public User(String email, String password){
23+
this.email = email;
24+
this.password = password;
25+
}
26+
27+
public String getEmail(){
28+
return this.email;
29+
}
30+
31+
public Status getStatus(){
32+
return this.status;
33+
}
34+
35+
36+
37+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,12 @@
11
spring.application.name=vlib
2+
spring.datasource.url=jdbc:postgresql://185.166.39.209:5432/vlib_db
3+
spring.datasource.username=vlibadmin
4+
spring.datasource.password=cLX1fgz27ravjV2BE1MxbS1w8uBU9en2B4fUssQC
5+
6+
spring.jpa.hibernate.ddl-auto=none
7+
spring.jpa.show-sql=true
8+
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.PostgreSQLDialect
9+
10+
11+
spring.flyway.enabled=true
12+
spring.flyway.locations=classpath:db/migration
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
CREATE TABLE users (
2+
id SERIAL PRIMARY KEY,
3+
email VARCHAR(50) NOT NULL,
4+
password VARCHAR(200) NOT NULL,
5+
status VARCHAR(20) NOT NULL,
6+
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
7+
);
8+
9+
CREATE TABLE station (
10+
id SERIAL PRIMARY KEY,
11+
name VARCHAR(100) NOT NULL,
12+
station_code VARCHAR(20) NOT NULL,
13+
latitude DECIMAL(9,6) NOT NULL,
14+
longitude DECIMAL(9,6) NOT NULL,
15+
address VARCHAR(100),
16+
city VARCHAR(20),
17+
description VARCHAR(300),
18+
last_update TIMESTAMP DEFAULT CURRENT_TIMESTAMP
19+
)

0 commit comments

Comments
 (0)