Skip to content

Commit faee9d9

Browse files
committed
initial commit
0 parents  commit faee9d9

11 files changed

Lines changed: 595 additions & 0 deletions

File tree

.gitignore

Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
# Created by .ignore support plugin (hsz.mobi)
2+
### Gradle template
3+
.gradle
4+
/build/
5+
6+
# Ignore Gradle GUI config
7+
gradle-app.setting
8+
9+
# Avoid ignoring Gradle wrapper jar file (.jar files are usually ignored)
10+
!gradle-wrapper.jar
11+
12+
# Cache of project
13+
.gradletasknamecache
14+
15+
# # Work around https://youtrack.jetbrains.com/issue/IDEA-116898
16+
# gradle/wrapper/gradle-wrapper.properties
17+
18+
### JetBrains template
19+
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and WebStorm
20+
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
21+
22+
# User-specific stuff
23+
.idea/**/workspace.xml
24+
.idea/**/tasks.xml
25+
.idea/**/usage.statistics.xml
26+
.idea/**/dictionaries
27+
.idea/**/shelf
28+
29+
# Generated files
30+
.idea/**/contentModel.xml
31+
32+
# Sensitive or high-churn files
33+
.idea/**/dataSources/
34+
.idea/**/dataSources.ids
35+
.idea/**/dataSources.local.xml
36+
.idea/**/sqlDataSources.xml
37+
.idea/**/dynamic.xml
38+
.idea/**/uiDesigner.xml
39+
.idea/**/dbnavigator.xml
40+
41+
# Gradle
42+
.idea/**/gradle.xml
43+
.idea/**/libraries
44+
45+
# Gradle and Maven with auto-import
46+
# When using Gradle or Maven with auto-import, you should exclude module files,
47+
# since they will be recreated, and may cause churn. Uncomment if using
48+
# auto-import.
49+
# .idea/modules.xml
50+
# .idea/*.iml
51+
# .idea/modules
52+
# *.iml
53+
# *.ipr
54+
55+
# CMake
56+
cmake-build-*/
57+
58+
# Mongo Explorer plugin
59+
.idea/**/mongoSettings.xml
60+
61+
# File-based project format
62+
*.iws
63+
64+
# IntelliJ
65+
out/
66+
67+
# mpeltonen/sbt-idea plugin
68+
.idea_modules/
69+
70+
# JIRA plugin
71+
atlassian-ide-plugin.xml
72+
73+
# Cursive Clojure plugin
74+
.idea/replstate.xml
75+
76+
# Crashlytics plugin (for Android Studio and IntelliJ)
77+
com_crashlytics_export_strings.xml
78+
crashlytics.properties
79+
crashlytics-build.properties
80+
fabric.properties
81+
82+
# Editor-based Rest Client
83+
.idea/httpRequests
84+
85+
# Android studio 3.1+ serialized cache file
86+
.idea/caches/build_file_checksums.ser
87+
88+
### Kotlin template
89+
# Compiled class file
90+
*.class
91+
92+
# Log file
93+
*.log
94+
95+
# BlueJ files
96+
*.ctxt
97+
98+
# Mobile Tools for Java (J2ME)
99+
.mtj.tmp/
100+
101+
# Package Files #
102+
*.jar
103+
*.war
104+
*.nar
105+
*.ear
106+
*.zip
107+
*.tar.gz
108+
*.rar
109+
110+
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
111+
hs_err_pid*
112+
113+
.idea

README.md

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
# Postgres Database Restorer
2+
3+
This library helps you to quickly restore a Postgres database to a previous state.
4+
5+
It was developed as means to speed up integration tests.
6+
7+
## Introduction
8+
9+
In many integration test scenarios the database needs to be setup before it can be used in a test. For example, often migrations need to be run.
10+
11+
When writing isolated tests one would like to have the database in a 'clean' state for each test. This 'clean' state almost never means an 'empty' database, but one that has been setup.
12+
13+
The combination of these factors can lead to increasingly long running integration tests, because the database needs to be setup for each t
14+
15+
This library may help you to speed up integration tests by providing a means to _quickly_ restoring a Postgres database to a previous 'clean' state before each test.
16+
17+
## How it Works
18+
19+
Postgres has a feature that allows to create a database from a template. Creating databases this way is relatively fast.
20+
21+
We can create a template of a 'previous' state that we then may 'restore' to, by recreating the database from it.
22+
23+
For this to work one needs to disconnect connections to the database which should be restored.
24+
25+
This library handles the connections, dropping, and recreation from template for you.
26+
27+
**Please be aware that his only works if tests accessing the same database run strictly one after the other.**
28+
29+
## Installation
30+
31+
Add [JitPack](https://jitpack.io/) to your repositories:
32+
```groovy
33+
repositories {
34+
maven { url 'https://jitpack.io' }
35+
}
36+
```
37+
38+
Add the dependency:
39+
40+
```groovy
41+
dependencies {
42+
testImplementation 'com.github.ayedo:PostgresDbRestore:v1.0.0'
43+
}
44+
```
45+
46+
## Usage
47+
48+
val databaseRestorer = DatabaseRestorer(
49+
databaseName = "postgres",
50+
host = "localhost",
51+
port = 5432,
52+
user = "postgres",
53+
password = "postgres"
54+
)
55+
56+
databaseRestorer.takeSnapshot()
57+
58+
// later call this to restore to the state when you called snapshot
59+
restorer.restore()
60+
61+
## jUnit 5 Extension
62+
63+
An example of how you could use this library with jUnit5 can be found [here]().

build.gradle

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
plugins {
2+
id 'org.jetbrains.kotlin.jvm' version '1.3.50'
3+
}
4+
5+
group 'ayedo'
6+
version '1.0-SNAPSHOT'
7+
8+
repositories {
9+
mavenCentral()
10+
}
11+
12+
dependencies {
13+
implementation 'org.jetbrains.kotlin:kotlin-stdlib-jdk8'
14+
implementation 'org.jooq:jooq:3.12.3'
15+
implementation 'org.junit.jupiter:junit-jupiter-api:5.5.2'
16+
}
17+
18+
compileKotlin {
19+
kotlinOptions.jvmTarget = "1.8"
20+
}
21+
compileTestKotlin {
22+
kotlinOptions.jvmTarget = "1.8"
23+
}

gradle.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
kotlin.code.style=official
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#Sat Nov 09 18:41:58 CET 2019
2+
distributionUrl=https\://services.gradle.org/distributions/gradle-5.2.1-all.zip
3+
distributionBase=GRADLE_USER_HOME
4+
distributionPath=wrapper/dists
5+
zipStorePath=wrapper/dists
6+
zipStoreBase=GRADLE_USER_HOME

gradlew

Lines changed: 172 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)