Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ target/
!**/src/main/**/target/
!**/src/test/**/target/

.env-docker

### STS ###
.apt_generated
.classpath
Expand Down
10 changes: 5 additions & 5 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
FROM maven:3.9.6-eclipse-temurin-21 AS build

WORKDIR /app

COPY src /app/src
COPY pom.xml /app

WORKDIR /app

RUN mvn -e clean install -DskipTests

FROM eclipse-temurin:21-jre-alpine

COPY --from=build /app/target/CFinance-0.0.1-SNAPSHOT.jar /app/app.jar

WORKDIR /app

COPY --from=build /app/target/*.jar /app/app.jar

EXPOSE 1234

CMD ["java","-jar","app.jar"]
ENTRYPOINT ["java","-jar","app.jar"]
19 changes: 14 additions & 5 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,15 +1,24 @@
services:
postgresql:
image: postgres:latest
image: postgres:18
container_name: cfinance-db
ports:
- '5432:5432'
environment:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
POSTGRES_DB: cfinance
volumes:
- cfinance:/var/lib/postgresql
restart: always

app:
build: .
depends_on:
- postgresql
cfinance:
image: cfinance:1.0
env_file:
- .env-docker
ports:
- "1234:1234"

volumes:
cfinance:
external: true
13 changes: 4 additions & 9 deletions src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,7 @@ server:

spring:
profiles:
active: production
datasource:
url: jdbc:postgresql://localhost:5432/cfinance
username: ${DB_USER:null}
password: ${DB_PASSWORD:null}
driver-class-name: org.postgresql.Driver
active: ${PROFILE:development}

jpa:
hibernate:
Expand Down Expand Up @@ -43,10 +38,10 @@ spring:
baseline-on-migrate: true
baseline-version: 0
datasource:
url: jdbc:postgresql://localhost:5432/cfinance
url: ${DB_URL}
driverClassName: org.postgresql.Driver
username: ${DB_USER:postgres}
password: ${DB_PASSWORD:postgres}
username: ${DB_USER}
password: ${DB_PASSWORD}
jpa:
show-sql: true
database-platform: org.hibernate.dialect.PostgreSQLDialect
Expand Down
35 changes: 28 additions & 7 deletions src/main/resources/db/migration/V1753201048__create_tables.sql
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
DROP TYPE IF EXISTS transactions_type;

create type transactions_type as enum('EXPENSE','INCOME');
DO $$
BEGIN
IF NOT EXISTS (
SELECT 1
FROM pg_type
WHERE typname = 'transactions_type'
) THEN
CREATE TYPE transactions_type AS ENUM ('EXPENSE', 'INCOME');
END IF;
END
$$;

create table if not exists users(
id BIGSERIAL primary key,
Expand All @@ -10,7 +18,20 @@ create table if not exists users(
created_at timestamp default current_timestamp
);

CREATE SEQUENCE category_seq START WITH 17 INCREMENT BY 1;
DO $$
BEGIN
IF NOT EXISTS (
SELECT 1
FROM pg_class
WHERE relkind = 'S'
AND relname = 'category_seq'
) THEN
CREATE SEQUENCE category_seq
START WITH 17
INCREMENT BY 1;
END IF;
END
$$;

CREATE TABLE if not exists category (
id INT PRIMARY KEY DEFAULT nextval('category_seq'),
Expand Down Expand Up @@ -80,7 +101,7 @@ insert into payment_method(id, name, description) values
(1,'Debit card', 'Debit card'),
(2,'Pix', 'Pix is an instant payment method launched by the Brazilian Central Bank to facilitate the transfer of funds between individuals and legal entities.'),
(3,'Cash', 'Cash'),
(4,'Credit card', 'Credit card');
(4,'Credit card', 'Credit card') on conflict do nothing;

-- Inserting default categories for expenses
INSERT INTO category (id, name, description) VALUES
Expand All @@ -93,7 +114,7 @@ INSERT INTO category (id, name, description) VALUES
(7,'Education', 'Courses, books, school supplies'),
(8,'Clothing', 'Clothes, shoes, accessories'),
(9,'Services', 'Internet, phone, streaming, etc.'),
(10,'Other Expenses', 'Miscellaneous uncategorized expenses');
(10,'Other Expenses', 'Miscellaneous uncategorized expenses') on conflict do nothing;

-- Inserting default categories for income
INSERT INTO category (id, name, description) VALUES
Expand All @@ -102,4 +123,4 @@ INSERT INTO category (id, name, description) VALUES
(13,'Investments', 'Investment income'),
(14,'Sales', 'Sale of products or services'),
(15,'Gifts', 'Money received as a gift'),
(16,'Other Income', 'Miscellaneous uncategorized income');
(16,'Other Income', 'Miscellaneous uncategorized income') on conflict do nothing;
Loading