Skip to content

Commit

Permalink
realizando a implementação do flyway no projeto
Browse files Browse the repository at this point in the history
  • Loading branch information
GabryelBoeira committed Mar 3, 2025
1 parent 6c3f290 commit fbc9dbd
Show file tree
Hide file tree
Showing 6 changed files with 66 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ public class WebConfig implements WebMvcConfigurer {

@Override
public void addCorsMappings(CorsRegistry registry) {
registry.addMapping("/**");
registry.addMapping("/**")
.allowedOrigins("*")
.allowedMethods("GET", "POST", "PUT", "DELETE", "OPTIONS")
.allowedHeaders("*");
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ public CustomerController(CustomerService customerService) {
}

@GetMapping
@Operation(summary = "Listar todos os clientes")
public String index() {
return "Hello World";
}
Expand Down
30 changes: 10 additions & 20 deletions VideoLocadora/src/main/resources/application.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ spring:
basename: messages
encoding: UTF-8
fallback-to-system-locale: true
docker:
compose:
enabled: true
file: docker-compose.yml

server:
port: 8080
Expand All @@ -31,37 +35,23 @@ springdoc:
api-docs:
path: /api-docs

docker:
compose:
enabled: true
file: docker-compose.yml
profiles: development
---
spring:
config:
activate:
on-profile: development

sql.init.mode: always
datasource:
driver-class-name: com.mysql.cj.jdbc.Driver
url: ${SPRING_DATASOURCE_URL}
username: root
password: root
username: ${SPRING_DATASOURCE_USERNAME}
password: ${SPRING_DATASOURCE_PASSWORD}
jpa:
show-sql: false
database: mysql
generate-ddl: false
defer-datasource-initialization: true
database-platform: org.hibernate.dialect.MySQL8Dialect
hibernate:
ddl-auto: create
flyway:
enabled: true
locations: classpath:db.migration
encoding: UTF-8
jackson:
serialization:
FAIL_ON_EMPTY_BEANS: false

---
spring:
config:
activate:
on-profile: production
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
CREATE TABLE address
(
id BIGINT AUTO_INCREMENT NOT NULL,
street VARCHAR(255) NOT NULL COMMENT 'Rua',
number INT NULL COMMENT 'Número',
city VARCHAR(255) NOT NULL COMMENT 'Cidade',
state VARCHAR(255) NOT NULL COMMENT 'Estado',
country VARCHAR(255) NOt NULL COMMENT 'País',
zip_code VARCHAR(255) NOT NULL COMMENT 'CEP',
is_active BIT(1) NOT NULL COMMENT 'Endereço ativo',
is_primary_address BIT(1) NOT NULL COMMENT 'Endereço principal',
customer_id BIGINT NOT NULL COMMENT 'Id do cliente',
CONSTRAINT pk_address PRIMARY KEY (id)
);

CREATE TABLE customer
(
id BIGINT AUTO_INCREMENT NOT NULL,
name VARCHAR(255) NULL COMMENT 'Nome',
cpf VARCHAR(255) NULL COMMENT 'CPF',
email VARCHAR(255) NULL COMMENT 'Email',
delay_devolution BIT(1) NULL COMMENT 'Tem atraso alguma devolução',
CONSTRAINT pk_customer PRIMARY KEY (id)
);

ALTER TABLE address ADD CONSTRAINT FK_ADDRESS_ON_CUSTOMER FOREIGN KEY (customer_id) REFERENCES customer (id);
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
-- Inserções para a tabela customer
INSERT INTO customer (name, cpf, email, delay_devolution) VALUES
('Ana Silva', '12345678901', 'ana.silva@email.com', 0),
('Bruno Oliveira', '98765432109', 'bruno.oliveira@email.com', 1),
('Carla Souza', '45678901234', 'carla.souza@email.com', 0),
('Daniel Pereira', '65432109876', 'daniel.pereira@email.com', 1),
('Elisa Santos', '78901234567', 'elisa.santos@email.com', 0),
('Fernando Lima', '01234567890', 'fernando.lima@email.com', 1),
('Gabriela Rocha', '34567890123', 'gabriela.rocha@email.com', 0),
('Henrique Costa', '21098765432', 'henrique.costa@email.com', 1),
('Isabela Gomes', '56789012345', 'isabela.gomes@email.com', 0),
('João Rodrigues', '89012345678', 'joao.rodrigues@email.com', 1);
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
-- Inserções para a tabela address
INSERT INTO address (street, number, city, state, country, zip_code, is_active, is_primary_address, customer_id) VALUES
('Rua A', 123, 'São Paulo', 'SP', 'Brasil', '01000000', 1, 1, 1),
('Avenida B', 456, 'Rio de Janeiro', 'RJ', 'Brasil', '20000000', 1, 1, 2),
('Rua C', 789, 'Belo Horizonte', 'MG', 'Brasil', '30000000', 1, 1, 3),
('Avenida D', 101, 'Porto Alegre', 'RS', 'Brasil', '90000000', 1, 1, 4),
('Rua E', 202, 'Salvador', 'BA', 'Brasil', '40000000', 1, 1, 5),
('Avenida F', 303, 'Recife', 'PE', 'Brasil', '50000000', 1, 1, 6),
('Rua G', 404, 'Curitiba', 'PR', 'Brasil', '80000000', 1, 1, 7),
('Avenida H', 505, 'Brasília', 'DF', 'Brasil', '70000000', 1, 1, 8),
('Rua I', 606, 'Fortaleza', 'CE', 'Brasil', '60000000', 1, 1, 9),
('Avenida J', 707, 'Manaus', 'AM', 'Brasil', '69000000', 1, 1, 10);

0 comments on commit fbc9dbd

Please sign in to comment.