Skip to content
Merged
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
4 changes: 4 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,10 @@
<artifactId>spring-security-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-validation</artifactId>
</dependency>
</dependencies>

<build>
Expand Down
44 changes: 44 additions & 0 deletions src/main/java/backendlab/team4you/registry/Registry.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package backendlab.team4you.registry;

import jakarta.persistence.*;
import jakarta.validation.constraints.Pattern;

import java.time.LocalDateTime;

@Entity
@Table(name= "registry")
public class Registry {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;

@Column(nullable = false, unique = true, length = 100)
private String name;

@Column(nullable = false, unique = true, length = 2)
@Pattern(regexp = "[A-Z]{2}")
private String code;

@Column(name = "created_at", nullable = false, updatable = false, insertable = false)
private LocalDateTime createdAt;

protected Registry() {}

public Registry(String name, String code) {
this.name = name;
this.code = code;
}

public Long getId() {
return id;
}

public String getName() {
return name;
}

public String getCode() {
return code;
}
}
6 changes: 0 additions & 6 deletions src/main/resources/db/migration/V1__init_schema.sql

This file was deleted.

18 changes: 18 additions & 0 deletions src/main/resources/db/migration/V2__registry.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
CREATE TABLE registry
(
id BIGINT GENERATED BY DEFAULT AS IDENTITY NOT NULL,
name VARCHAR(100) NOT NULL,
code VARCHAR(2) NOT NULL,
created_at TIMESTAMP NOT NULL DEFAULT current_timestamp,
CONSTRAINT pk_registry PRIMARY KEY (id)
);

ALTER TABLE registry
ADD CONSTRAINT uc_registry_code UNIQUE (code);

ALTER TABLE registry
ADD CONSTRAINT uc_registry_name UNIQUE (name);

ALTER TABLE registry
ADD CONSTRAINT chk_registry_code_format
CHECK (code ~ '^[A-Z]{2}$');