diff --git a/.gitignore b/.gitignore index fc77b90..31e443f 100644 --- a/.gitignore +++ b/.gitignore @@ -4,6 +4,8 @@ target/ !**/src/main/**/target/ !**/src/test/**/target/ +.env-docker + ### STS ### .apt_generated .classpath diff --git a/Dockerfile b/Dockerfile index bae3e91..2dfd706 100644 --- a/Dockerfile +++ b/Dockerfile @@ -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"] \ No newline at end of file +ENTRYPOINT ["java","-jar","app.jar"] \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml index 45be813..d68d945 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -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 \ No newline at end of file + cfinance: + image: cfinance:1.0 + env_file: + - .env-docker + ports: + - "1234:1234" + +volumes: + cfinance: + external: true \ No newline at end of file diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index 40ed6df..3430c62 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -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: @@ -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 diff --git a/src/main/resources/db/migration/V1753201048__create_tables.sql b/src/main/resources/db/migration/V1753201048__create_tables.sql index 6061876..66ec387 100644 --- a/src/main/resources/db/migration/V1753201048__create_tables.sql +++ b/src/main/resources/db/migration/V1753201048__create_tables.sql @@ -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, @@ -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'), @@ -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 @@ -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 @@ -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;