diff --git a/doc/README b/doc/README index c04e884..83330b0 100644 --- a/doc/README +++ b/doc/README @@ -10,4 +10,21 @@ 3. Overview 4. Architectural overview 5. Account types - 6. Booking rules \ No newline at end of file + 6. Booking rules + 7. Setup + + + 7. Setup + ======== + This chapter explains how to setup a financer instance. It requires PostgreSQL as a database backend and a Java + Servlet Container (e.g. Apache Tomcat) as a runtime environment. + + 7.1 Database setup + ------------------ + First install PostgreSQL. Then create a user for financer: + sudo -iu postgres + createuser --interactive + Enter 'financer' as role name and make it superuser. Then create the actual database: + createdb financer + Naming both, the user and the database, 'financer' is the expected default. If you want any other names you need + to adjust the database connection settings of the financer application. \ No newline at end of file diff --git a/src/main/resources/config/application-hsqldb.properties b/src/main/resources/config/application-hsqldb.properties index e2f0f22..3976d92 100644 --- a/src/main/resources/config/application-hsqldb.properties +++ b/src/main/resources/config/application-hsqldb.properties @@ -1,4 +1,4 @@ -spring.flyway.locations=classpath:/database/hsqldb +spring.flyway.locations=classpath:/database/hsqldb,classpath:/database/common # DataSource #spring.datasource.url=jdbc:hsqldb:file:/tmp/financer diff --git a/src/main/resources/config/application-postgres.properties b/src/main/resources/config/application-postgres.properties index 944068b..7082fd1 100644 --- a/src/main/resources/config/application-postgres.properties +++ b/src/main/resources/config/application-postgres.properties @@ -1 +1,7 @@ -spring.flyway.locations=classpath:/database/postgres \ No newline at end of file +spring.flyway.locations=classpath:/database/postgres,classpath:/database/common + +spring.datasource.url=jdbc:postgresql://localhost/financer +spring.datasource.username=financer + +# See https://github.com/spring-projects/spring-boot/issues/12007 +spring.jpa.properties.hibernate.jdbc.lob.non_contextual_creation=true \ No newline at end of file diff --git a/src/main/resources/database/common/V1_0_1__initData.sql b/src/main/resources/database/common/V1_0_1__initData.sql new file mode 100644 index 0000000..084e8fc --- /dev/null +++ b/src/main/resources/database/common/V1_0_1__initData.sql @@ -0,0 +1,15 @@ +-- Accounts +INSERT INTO account ("key", type, status, current_balance) +VALUES ('accounts.checkaccount', 'BANK', 'OPEN', 0); + +INSERT INTO account ("key", type, status, current_balance) +VALUES ('accounts.income', 'INCOME', 'OPEN', 0); + +INSERT INTO account ("key", type, status, current_balance) +VALUES ('accounts.cash', 'CASH', 'OPEN', 0); + +INSERT INTO account ("key", type, status, current_balance) +VALUES ('accounts.start', 'START', 'OPEN', 0); + +INSERT INTO account ("key", type, status, current_balance) +VALUES ('accounts.rent', 'EXPENSE', 'OPEN', 0); \ No newline at end of file diff --git a/src/main/resources/database/hsqldb/V1_0_0__init.sql b/src/main/resources/database/hsqldb/V1_0_0__init.sql index a8cca05..0737352 100644 --- a/src/main/resources/database/hsqldb/V1_0_0__init.sql +++ b/src/main/resources/database/hsqldb/V1_0_0__init.sql @@ -42,20 +42,4 @@ CREATE TABLE "transaction" ( --escape keyword "transaction" CONSTRAINT fk_transaction_from_account FOREIGN KEY (from_account_id) REFERENCES account (id), CONSTRAINT fk_transaction_to_account FOREIGN KEY (to_account_id) REFERENCES account (id), CONSTRAINT fk_transaction_recurring_transaction FOREIGN KEY (recurring_transaction_id) REFERENCES recurring_transaction (id) -); - --- Accounts -INSERT INTO account (id, "key", type, status, current_balance) -VALUES (1, 'accounts.checkaccount', 'BANK', 'OPEN', 0); -- insert first with ID 1 so we get predictable numbering - -INSERT INTO account ("key", type, status, current_balance) -VALUES ('accounts.income', 'INCOME', 'OPEN', 0); - -INSERT INTO account ("key", type, status, current_balance) -VALUES ('accounts.cash', 'CASH', 'OPEN', 0); - -INSERT INTO account ("key", type, status, current_balance) -VALUES ('accounts.start', 'START', 'OPEN', 0); - -INSERT INTO account ("key", type, status, current_balance) -VALUES ('accounts.rent', 'EXPENSE', 'OPEN', 0); \ No newline at end of file +); \ No newline at end of file diff --git a/src/main/resources/database/postgres/V1_0_0__init.sql b/src/main/resources/database/postgres/V1_0_0__init.sql new file mode 100644 index 0000000..52158af --- /dev/null +++ b/src/main/resources/database/postgres/V1_0_0__init.sql @@ -0,0 +1,45 @@ +-- +-- This file contains the basic initialization of the financer schema and basic init data +-- + +-- Account table +CREATE TABLE account ( + id BIGINT NOT NULL PRIMARY KEY GENERATED ALWAYS AS IDENTITY, + "key" VARCHAR(1000) NOT NULL, --escape keyword "key" + type VARCHAR(255) NOT NULL, + status VARCHAR(255) NOT NULL, + current_balance BIGINT NOT NULL, + + CONSTRAINT un_account_name_key UNIQUE ("key") +); + +-- Recurring transaction table +CREATE TABLE recurring_transaction ( + id BIGINT NOT NULL PRIMARY KEY GENERATED ALWAYS AS IDENTITY, + from_account_id BIGINT NOT NULL, + to_account_id BIGINT NOT NULL, + description VARCHAR(1000), + amount BIGINT NOT NULL, + interval_type VARCHAR(255) NOT NULL, + first_occurrence DATE NOT NULL, + last_occurrence DATE, + holiday_weekend_type VARCHAR(255) NOT NULL, + + CONSTRAINT fk_recurring_transaction_from_account FOREIGN KEY (from_account_id) REFERENCES account (id), + CONSTRAINT fk_recurring_transaction_to_account FOREIGN KEY (to_account_id) REFERENCES account (id) +); + +-- Transaction table +CREATE TABLE "transaction" ( --escape keyword "transaction" + id BIGINT NOT NULL PRIMARY KEY GENERATED ALWAYS AS IDENTITY, + from_account_id BIGINT NOT NULL, + to_account_id BIGINT NOT NULL, + "date" DATE NOT NULL, --escape keyword "date" + description VARCHAR(1000), + amount BIGINT NOT NULL, + recurring_transaction_id BIGINT, + + CONSTRAINT fk_transaction_from_account FOREIGN KEY (from_account_id) REFERENCES account (id), + CONSTRAINT fk_transaction_to_account FOREIGN KEY (to_account_id) REFERENCES account (id), + CONSTRAINT fk_transaction_recurring_transaction FOREIGN KEY (recurring_transaction_id) REFERENCES recurring_transaction (id) +); \ No newline at end of file diff --git a/src/test/resources/application-integrationtest.properties b/src/test/resources/application-integrationtest.properties index b75a1d2..d6974b3 100644 --- a/src/test/resources/application-integrationtest.properties +++ b/src/test/resources/application-integrationtest.properties @@ -1,3 +1,5 @@ +spring.profiles.active=hsqldb,dev + spring.datasource.url=jdbc:hsqldb:mem:. spring.datasource.username=sa -spring.flyway.locations=classpath:/database/hsqldb,classpath:/database/hsqldb/integration +spring.flyway.locations=classpath:/database/hsqldb,classpath:/database/hsqldb/integration,classpath:/database/common