-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(core): add a setting model and repository
- Loading branch information
1 parent
3514b9e
commit 73168c4
Showing
36 changed files
with
520 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package io.kestra.core.models; | ||
|
||
import lombok.EqualsAndHashCode; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
import lombok.ToString; | ||
import lombok.experimental.SuperBuilder; | ||
|
||
import javax.validation.constraints.NotNull; | ||
|
||
@SuperBuilder | ||
@ToString | ||
@EqualsAndHashCode | ||
@Getter | ||
@NoArgsConstructor | ||
public class Setting { | ||
public static final String INSTANCE_UUID = "instance.uuid"; | ||
@NotNull | ||
private String key; | ||
|
||
@NotNull | ||
private Object value; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
core/src/main/java/io/kestra/core/repositories/SettingRepositoryInterface.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package io.kestra.core.repositories; | ||
|
||
import io.kestra.core.models.Setting; | ||
|
||
import java.util.List; | ||
import java.util.Optional; | ||
import javax.validation.ConstraintViolationException; | ||
|
||
public interface SettingRepositoryInterface { | ||
Optional<Setting> findByKey(String key); | ||
|
||
List<Setting> findAll(); | ||
|
||
Setting save(Setting setting) throws ConstraintViolationException; | ||
|
||
Setting delete(Setting setting); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
core/src/test/java/io/kestra/core/repositories/AbstracSettingRepositoryTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package io.kestra.core.repositories; | ||
|
||
import io.kestra.core.models.Setting; | ||
import io.kestra.core.utils.IdUtils; | ||
import io.micronaut.test.extensions.junit5.annotation.MicronautTest; | ||
import jakarta.inject.Inject; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import java.util.List; | ||
import java.util.Optional; | ||
|
||
import static org.hamcrest.MatcherAssert.assertThat; | ||
import static org.hamcrest.Matchers.is; | ||
|
||
@MicronautTest(transactional = false) | ||
public abstract class AbstracSettingRepositoryTest { | ||
@Inject | ||
protected SettingRepositoryInterface settingRepository; | ||
|
||
@Test | ||
void all() { | ||
Setting setting = Setting.builder() | ||
.key(Setting.INSTANCE_UUID) | ||
.value(IdUtils.create()) | ||
.build(); | ||
|
||
Optional<Setting> find = settingRepository.findByKey(setting.getKey()); | ||
assertThat(find.isPresent(), is(false)); | ||
|
||
Setting save = settingRepository.save(setting); | ||
|
||
find = settingRepository.findByKey(save.getKey()); | ||
|
||
assertThat(find.isPresent(), is(true)); | ||
assertThat(find.get().getValue(), is(save.getValue())); | ||
|
||
List<Setting> all = settingRepository.findAll(); | ||
assertThat(all.size(), is(1)); | ||
assertThat(all.get(0).getValue(), is(setting.getValue())); | ||
|
||
Setting delete = settingRepository.delete(setting); | ||
assertThat(delete.getValue(), is(setting.getValue())); | ||
|
||
all = settingRepository.findAll(); | ||
assertThat(all.size(), is(0)); | ||
|
||
find = settingRepository.findByKey(setting.getKey()); | ||
assertThat(find.isPresent(), is(false)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
jdbc-h2/src/main/java/io/kestra/repository/h2/H2SettingRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package io.kestra.repository.h2; | ||
|
||
import io.kestra.core.models.Setting; | ||
import io.kestra.core.models.triggers.Trigger; | ||
import io.kestra.jdbc.repository.AbstractJdbcSettingRepository; | ||
import io.kestra.jdbc.repository.AbstractJdbcTriggerRepository; | ||
import io.micronaut.context.ApplicationContext; | ||
import jakarta.inject.Inject; | ||
import jakarta.inject.Singleton; | ||
|
||
@Singleton | ||
@H2RepositoryEnabled | ||
public class H2SettingRepository extends AbstractJdbcSettingRepository { | ||
@Inject | ||
public H2SettingRepository(ApplicationContext applicationContext) { | ||
super(new H2Repository<>(Setting.class, applicationContext), applicationContext); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
CREATE TABLE settings ( | ||
"key" VARCHAR(250) NOT NULL PRIMARY KEY, | ||
"value" TEXT NOT NULL | ||
); | ||
|
7 changes: 7 additions & 0 deletions
7
jdbc-h2/src/test/java/io/kestra/repository/h2/H2SettingRepositoryTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package io.kestra.repository.h2; | ||
|
||
import io.kestra.jdbc.repository.AbstractJdbcSettingRepositoryTest; | ||
|
||
public class H2SettingRepositoryTest extends AbstractJdbcSettingRepositoryTest { | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
jdbc-mysql/src/main/java/io/kestra/repository/mysql/MysqlSettingRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package io.kestra.repository.mysql; | ||
|
||
import io.kestra.core.models.Setting; | ||
import io.kestra.core.models.triggers.Trigger; | ||
import io.kestra.jdbc.repository.AbstractJdbcSettingRepository; | ||
import io.kestra.jdbc.repository.AbstractJdbcTriggerRepository; | ||
import io.micronaut.context.ApplicationContext; | ||
import jakarta.inject.Inject; | ||
import jakarta.inject.Singleton; | ||
|
||
@Singleton | ||
@MysqlRepositoryEnabled | ||
public class MysqlSettingRepository extends AbstractJdbcSettingRepository { | ||
@Inject | ||
public MysqlSettingRepository(ApplicationContext applicationContext) { | ||
super(new MysqlRepository<>(Setting.class, applicationContext), applicationContext); | ||
}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 4 additions & 0 deletions
4
jdbc-mysql/src/main/resources/migrations/mysql/V2__setting.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
CREATE TABLE settings ( | ||
`key` VARCHAR(250) NOT NULL PRIMARY KEY, | ||
`value` JSON NOT NULL | ||
) ENGINE INNODB CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; |
7 changes: 7 additions & 0 deletions
7
jdbc-mysql/src/test/java/io/kestra/repository/mysql/MysqlSettingRepositoryTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package io.kestra.repository.mysql; | ||
|
||
import io.kestra.jdbc.repository.AbstractJdbcSettingRepositoryTest; | ||
|
||
public class MysqlSettingRepositoryTest extends AbstractJdbcSettingRepositoryTest { | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.