diff --git a/src/main/kotlin/roomescape/admin/infrastructure/persistence/AdminEntity.kt b/src/main/kotlin/roomescape/admin/infrastructure/persistence/AdminEntity.kt index 3de6097f..9f356427 100644 --- a/src/main/kotlin/roomescape/admin/infrastructure/persistence/AdminEntity.kt +++ b/src/main/kotlin/roomescape/admin/infrastructure/persistence/AdminEntity.kt @@ -10,16 +10,29 @@ import roomescape.common.entity.AuditingBaseEntity class AdminEntity( id: Long, + @Column(unique = true) val account: String, var password: String, val name: String, + + @Column(unique = true) var phone: String, @Enumerated(value = EnumType.STRING) - var permissionLevel: AdminPermissionLevel + val type: AdminType, + @Column(nullable = true) + var storeId: Long? = null, + + @Enumerated(value = EnumType.STRING) + var permissionLevel: AdminPermissionLevel ) : AuditingBaseEntity(id) +enum class AdminType { + HQ, + STORE +} + enum class AdminPermissionLevel( val privileges: Set ) { diff --git a/src/main/resources/schema/schema-h2.sql b/src/main/resources/schema/schema-h2.sql index cbcb63fd..d4b6fe73 100644 --- a/src/main/resources/schema/schema-h2.sql +++ b/src/main/resources/schema/schema-h2.sql @@ -74,11 +74,22 @@ create table if not exists admin( password varchar(255) not null, name varchar(20) not null, phone varchar(20) not null, + type varchar(20) not null, + store_id bigint, permission_level varchar(20) not null, created_at timestamp not null, created_by bigint not null, updated_at timestamp not null, - updated_by bigint not null + updated_by bigint not null, + + constraint uk_admin__account unique (account), + constraint uk_admin__phone unique (phone), + constraint chk_admin__type check (type in ('HQ', 'STORE')), + constraint chk_admin__store_id check ( + (type = 'HQ' AND store_id IS NULL) OR + (type = 'STORE' AND store_id IS NOT NULL) + ), + constraint fk_admin__store_id foreign key (store_id) references store (id) ); create table if not exists login_history(