Spring task scheduling example from the Pro Spring 5 book ported to Kotlin and Postgres.
On Debian Linux, PostgreSQL can be installed with the following command:
# apt-get install postgresql postgresql-doc
Both the default database user and default database are called postgres
By default, Postgres uses a concept called “roles” to handle authentication and authorization. After installation Postgres is set up to use ident authentication, meaning that it associates Postgres roles with a matching Unix/Linux system account.
Use su to switch to the postgres acount and create a user with the same name as the system user:
$ su -
# su -s /bin/bash postgres
postgres@debian:/root$ createuser -s username
The -s option grants superuser privileges.
Next we need to create a database for the user:
postgres@debian:/root$ createdb -O username username
Now try to start psql as a normal user:
$ psql
username=# \q
After setting up a user for the local system user, we no longer need to switch to the postgres account to run postgres commands. Add an instagram postgres user:
$ createuser -P cars
This creates an cars user that is not allowed to create new databases or roles and is not superuser. The -P flag will display a password prompt to set a password for the user.
To create the cars database, run the follwing command:
$ createdb -O cars cars
The Spring Hibernate example will automatically create tables before running the test and drop them after running the tests. It will also add test data to the tables.
Before running tests, set the correct password in src/main/resources/db/jdbc.properties
. SingerDaoTest
will test CRUD operations.