Skip to content

Commit

Permalink
#630 launch postgres with the expected conf
Browse files Browse the repository at this point in the history
  • Loading branch information
syjer committed Apr 27, 2019
1 parent 8444513 commit 5e7d924
Showing 1 changed file with 26 additions and 10 deletions.
36 changes: 26 additions & 10 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import com.opentable.db.postgres.embedded.EmbeddedPostgres
import org.apache.tools.ant.filters.ReplaceTokens
import org.springframework.jdbc.core.JdbcTemplate

Expand Down Expand Up @@ -310,20 +311,35 @@ task clever(type: Copy) {
dependsOn build
}

/*import ru.yandex.qatools.embed.postgresql.EmbeddedPostgres
import ru.yandex.qatools.embed.postgresql.distribution.Version.Main*/
import org.postgresql.ds.PGSimpleDataSource

/*task startEmbeddedPgSQL {
task startEmbeddedPgSQL {
doLast {
final pgsqlPath = Paths.get(".", "alfio-itest")
Files.createDirectories(pgsqlPath)
final tmpDataDir = Files.createTempDirectory(pgsqlPath, "alfio-data")
final postgres = new EmbeddedPostgres(Main.PRODUCTION, tmpDataDir.normalize().toAbsolutePath().toString())
final postgres = EmbeddedPostgres.builder().setPort(5432).setDataDirectory(tmpDataDir).start()

// create a new admin, and then rename the user "postgres" as we don't want to have the superuser roles
def jdbc = new JdbcTemplate(postgres.getDatabase("postgres", "postgres"))
jdbc.execute("CREATE ROLE tmpadmin LOGIN PASSWORD 'password' SUPERUSER")

jdbc = new JdbcTemplate(postgres.getDatabase("tmpadmin", "postgres"))
jdbc.execute("ALTER USER postgres RENAME TO admin")
//
//todo: check if the following grants are necessary
jdbc.execute("CREATE ROLE postgres LOGIN PASSWORD 'password' NOSUPERUSER INHERIT CREATEDB CREATEROLE REPLICATION")
jdbc.execute("GRANT pg_monitor TO postgres")
jdbc.execute("GRANT pg_read_all_settings TO postgres")
jdbc.execute("GRANT pg_read_all_stats TO postgres")
jdbc.execute("GRANT pg_signal_backend TO postgres")
jdbc.execute("GRANT pg_stat_scan_tables TO postgres")
jdbc.execute("CREATE DATABASE alfio WITH OWNER postgres")
//

/*final postgres = new /*EmbeddedPostgres(Main.PRODUCTION, tmpDataDir.normalize().toAbsolutePath().toString())
postgres.start(EmbeddedPostgres.cachedRuntimeConfig(Paths.get(System.getProperty("java.io.tmpdir"), "pgembed")),
"localhost", 5432, "alfio", "admin", "password", Arrays.asList("-E", "SQL_ASCII", "--locale=C", "--lc-collate=C", "--lc-ctype=C"))
"localhost", 5432, "alfio", "admin", "password", Arrays.asList("-E", "SQL_ASCII", "--locale=C", "--lc-collate=C", "--lc-ctype=C"))*/

postgres.getProcess().ifPresent({
/*postgres.getProcess().ifPresent({
final pid = it.getProcessId()
Files.write(Paths.get(".", "alfio-itest", "pgsql-pid"), Arrays.asList(Long.toString(pid)))
System.out.println("Launched pgsql with pid " + pid)
Expand All @@ -340,7 +356,7 @@ import org.postgresql.ds.PGSimpleDataSource
jdbc.execute("GRANT pg_read_all_stats TO postgres")
jdbc.execute("GRANT pg_signal_backend TO postgres")
jdbc.execute("GRANT pg_stat_scan_tables TO postgres")
})
})*/
}
}

Expand All @@ -352,7 +368,7 @@ task stopEmbeddedPgSQL {
Runtime.runtime.exec("kill -9 " + pid)
System.out.println("Killed pgsql with pid " + pid)
}
}*/
}

release {
buildTasks = ['distribution']
Expand Down

0 comments on commit 5e7d924

Please sign in to comment.