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

add flyway to handle migrations #145

Merged
merged 2 commits into from
Aug 15, 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
12 changes: 11 additions & 1 deletion skill-tree/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>3.1.2</version>
<version>3.3.2</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.RDS</groupId>
Expand Down Expand Up @@ -114,6 +114,16 @@
<version>5.3.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.flywaydb</groupId>
<artifactId>flyway-core</artifactId>
<version>10.17.1</version>
</dependency>
<dependency>
<groupId>org.flywaydb</groupId>
<artifactId>flyway-mysql</artifactId>
<version>10.17.1</version>
</dependency>
</dependencies>
<dependencyManagement>
<dependencies>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
@Table(name = "endorsements")
public class Endorsement extends TrackedProperties {
@Id
@GeneratedValue
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "id")
private Integer id;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
@Table(name = "skills")
public class Skill extends TrackedProperties {
@Id
@GeneratedValue
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "id")
private Integer id;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
@Table(name = "user_skills")
public class UserSkills {
@Id
@GeneratedValue(strategy = GenerationType.UUID)
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "id")
private String id;

Expand Down
6 changes: 3 additions & 3 deletions skill-tree/src/main/resources/application.properties
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
spring.datasource.url=jdbc:mysql://${MYSQL_HOST:localhost}:${MYSQL_PORT:3306}/${DB_NAME}
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MySQL8Dialect
spring.datasource.username=${MYSQL_DB_USERNAME}
spring.datasource.password=${MYSQL_DB_PASSWORD}
spring.jpa.hibernate.ddl-auto=${DB_DDL_POLICY}
spring.flyway.enabled=true
spring.flyway.locations=classpath:db/migrations
spring.jpa.show-sql=true
jwt.rds.public.key=${RDS_PUBLIC_KEY}
API_V1_PREFIX=/api/v1
spring.datasource.version=8.1.0
management.endpoints.web.exposure.include=health,info,metrics
logging.level.root=ERROR
# If no value received from env default is dev
Expand Down
40 changes: 40 additions & 0 deletions skill-tree/src/main/resources/db/migrations/V1__initial_setup.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
-- Skills table
CREATE TABLE `skills` (
`id` int NOT NULL AUTO_INCREMENT,
`created_at` datetime(6) NOT NULL,
`deleted_at` datetime(6) DEFAULT NULL,
`is_deleted` tinyint(1) NOT NULL DEFAULT '0',
`updated_at` datetime(6) DEFAULT NULL,
`created_by` varchar(255) NOT NULL,
`name` varchar(255) NOT NULL,
yesyash marked this conversation as resolved.
Show resolved Hide resolved
`skill_type` enum('ATOMIC') NOT NULL,
`updated_by` varchar(255) DEFAULT NULL,
PRIMARY KEY (`id`),
UNIQUE (`name`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;

-- Endorsements table
CREATE TABLE `endorsements` (
`id` int NOT NULL AUTO_INCREMENT,
`created_at` datetime(6) NOT NULL,
`deleted_at` datetime(6) DEFAULT NULL,
`is_deleted` tinyint(1) NOT NULL DEFAULT '0',
`updated_at` datetime(6) DEFAULT NULL,
`endorse_id` varchar(255) NOT NULL,
`endorser_id` varchar(255) NOT NULL,
`message` text NOT NULL,
`skill_id` int NOT NULL,
PRIMARY KEY (`id`),
CONSTRAINT `fk_endorsements_skill_id` FOREIGN KEY (`skill_id`) REFERENCES `skills` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;

-- User skills table
CREATE TABLE `user_skills` (
`id` int NOT NULL AUTO_INCREMENT,
`status` enum('APPROVED','PENDING','REJECTED') NOT NULL,
`user_id` varchar(255) NOT NULL,
`skill_id` int NOT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `unique_user_skills` (`user_id`, `skill_id`),
CONSTRAINT `fk_user_skills_skill_id` FOREIGN KEY (`skill_id`) REFERENCES `skills` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
Loading