Skip to content
Snippets Groups Projects
Commit a146a498 authored by Addin Munawwar's avatar Addin Munawwar
Browse files

feat: init flyway migration plugin

parent 9f6db720
No related merge requests found
DB_NAME = soap_db
DB_USER = root # Change this to your own username
DB_PASSWORD = root # Change this to your own password
\ No newline at end of file
# Visual Studio Code # Visual Studio Code
.vscode .vscode
.env
# Compiled class file # Compiled class file
target/ target/
......
include .env
# Default target # Default target
all: build run all: build run
...@@ -14,5 +16,17 @@ clean: ...@@ -14,5 +16,17 @@ clean:
mvn clean mvn clean
rm -f target/soap_service-1.0.jar rm -f target/soap_service-1.0.jar
setup: create-db migration
create-db:
mysql -u root -p -e "CREATE DATABASE IF NOT EXISTS $(DB_NAME)"
exit
migration:
mvn flyway:migrate -Dflyway.url=jdbc:mysql://localhost:3306/$(DB_NAME) -Dflyway.user=$(DB_USER) -Dflyway.password=$(DB_PASSWORD)
migration-repair:
mvn flyway:repair -Dflyway.url=jdbc:mysql://localhost:3306/$(DB_NAME) -Dflyway.user=$(DB_USER) -Dflyway.password=$(DB_PASSWORD)
# Phony targets to prevent conflicts with filenames # Phony targets to prevent conflicts with filenames
.PHONY: all build run clean .PHONY: all build run clean
\ No newline at end of file
...@@ -13,6 +13,18 @@ ...@@ -13,6 +13,18 @@
<maven.compiler.target>1.8</maven.compiler.target> <maven.compiler.target>1.8</maven.compiler.target>
</properties> </properties>
<dependencies> <dependencies>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>8.0.33</version>
</dependency>
<dependency>
<groupId>io.sunshower.zephyr</groupId>
<artifactId>flyway</artifactId>
<version>2.0.128.Final</version>
</dependency>
<dependency> <dependency>
<groupId>org.projectlombok</groupId> <groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId> <artifactId>lombok</artifactId>
...@@ -22,12 +34,17 @@ ...@@ -22,12 +34,17 @@
<dependency> <dependency>
<groupId>com.sun.xml.ws</groupId> <groupId>com.sun.xml.ws</groupId>
<artifactId>jaxws-rt</artifactId> <artifactId>jaxws-rt</artifactId>
<version>2.3.6</version> <!-- Use the latest version --> <version>2.3.6</version>
</dependency> </dependency>
</dependencies> </dependencies>
<build> <build>
<plugins> <plugins>
<!-- clean lifecycle, see https://maven.apache.org/ref/current/maven-core/lifecycles.html#clean_Lifecycle --> <!-- clean lifecycle, see https://maven.apache.org/ref/current/maven-core/lifecycles.html#clean_Lifecycle -->
<plugin>
<groupId>org.flywaydb</groupId>
<artifactId>flyway-maven-plugin</artifactId>
<version>8.0.0</version>
</plugin>
<plugin> <plugin>
<groupId>org.apache.maven.plugins</groupId> <groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId> <artifactId>maven-jar-plugin</artifactId>
......
BEGIN;
DROP TABLE IF EXISTS `book_collection`;
DROP TABLE IF EXISTS `in_collection`;
DROP TABLE IF EXISTS `collection_subscription`;
DROP TABLE IF EXISTS `author_subscription`;
DROP TABLE IF EXISTS `user_notification`;
CREATE TABLE `book_collection` (
`collection_id` int AUTO_INCREMENT PRIMARY KEY,
`created_by` varchar(25) NOT NULL,
`name` varchar(255) NOT NULL,
`desc` text NOT NULL,
`created_at` timestamp NOT NULL,
`updated_at` timestamp,
`is_deleted` BOOLEAN NOT NULL DEFAULT FALSE,
`deleted_at` timestamp
);
CREATE TABLE `in_collection` (
`collection_id` int,
`book_id` int,
PRIMARY KEY (`collection_id`, `book_id`)
);
CREATE TABLE `collection_subscription` (
`collection_id` int,
`username` varchar(25),
`subscribed_at` timestamp NOT NULL,
`is_unsubscribed` BOOLEAN NOT NULL DEFAULT FALSE,
`unsubscribed_at` timestamp,
PRIMARY KEY (`collection_id`, `username`)
);
CREATE TABLE `author_subscription` (
`author_id` int,
`username` varchar(25),
`subscribed_at` timestamp NOT NULL,
`is_unsubscribed` BOOLEAN NOT NULL DEFAULT FALSE,
`unsubscribed_at` timestamp,
PRIMARY KEY (`author_id`, `username`)
);
CREATE TABLE `user_notification` (
`notification_id` int AUTO_INCREMENT PRIMARY KEY,
`username` varchar(25),
`message` text NOT NULL,
`created_at` timestamp NOT NULL,
`status` ENUM('unread', 'read', 'archived') NOT NULL
);
ALTER TABLE `in_collection` ADD FOREIGN KEY (`collection_id`) REFERENCES `book_collection` (`collection_id`);
ALTER TABLE `collection_subscription` ADD FOREIGN KEY (`collection_id`) REFERENCES `book_collection` (`collection_id`);
COMMIT;
```
\ No newline at end of file
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment